Theme’s original text strings customization
Let’s say we are working on the WordPress theme customization for a writer’s website. It doesn’t matter if we are adding an additional language, or staying with a single original language. What is important, that the original English naming doesn’t quite work for our purpose.
For example, we’d like any mentioning of the theme’s custom post type “Portfolio” to appear as “Publication” at the front end of our writer’s website. Another example is a plugin Buddydrive, where we’d like the name “Drive” to appear as “Files“.
Do we have to search for the strings in the php and js code, make changes to them, and to repeat it over and over after each theme update? No, we can utilize the translation system in order to change the text strings. It may look strange, as there is no translation here. We only substitute one English words with others.
Usually the localization of the English language is not defined in the en.po file. That’s why, to make text strings customization working, we need to add an important definition to the WordPress configuration file, and the original translation file.
If we’re customizing the theme for the American English (en_US), then the entire procedure will look as following.
- Define the original language localization for WordPress
Add the string to wp-config.php
define ('WPLANG', 'en_US');
- Rename the original translation files if needed
Check your theme or plugin language folders and rename the original language file according to the localization template (en_US in our case), if it has a simplified name en.po.
As it was mentioned in the previous articles of this series, text_domain is defined for each plugin, or theme. Most of the time it is the name of the theme or plugin folder.
- Define the original language localization in translation files
There are two ways to make the definition:
a) Open the renamed en_US.po file in text editor and change, or add (if it’s absent) the language string in the header
b) Open the en_US.po in poEdit, go to the Catalog -> Properties menu and select “English (United States)” in language field, as shown below. Save your .po file.
Now to change the original theme/plugin text strings you need to add translations (substitution English strings) for those strings in your en_US.po file. Use the poEdit Find tool (Edit -> Find) to make the process faster.
All articles from this series
- Introduction to the structure of the WordPress translation.
- How to translate Wodpress themes and plugins.
- Theme’s original text strings customization.
- How to translate child themes.
- How to handle translations with plugins and theme updates.
- Adding a second language to a WordPress website.
- Adding translation support to WordPress themes and plugins.
As usually, I’ll be glad to answer your questions, or provide more clarification on the topic of this article: