Collecting all the theme strings
Once all the texts in your theme are wrapped with GetText calls, it’s time to collect them into a single file, which we will translate later.
Allow us to introduce Poedit. It is a program that can create and translate .po (Portable Object) files and turn them into .mo (Machine Object) files. These are the files that WordPress uses to translate your theme.
Poedit is able to scan many different types of files, including C, CPP, PHP, and others. But, instead of using this tool, we will do something a bit different – and a lot easier.
In order to localize our own theme, we have used our own PHP to .po file converter. It is an online tool that allows you to upload a ZIP file containing your theme. The converter will instantly create a .po file for you to download.
And that’s it, we have the needed .po file to start translating our own theme.
Translating your theme strings
Now that you have a .po (or .pot – Portable Object Template) file, it’s time to translate it. Each .po file includes strings and their translation to a single language. This means that you need as many .po files as the languages you are translating the theme to.
If you are working with translators, just send them the .po files. Each translator would translate it and return it to you. Otherwise, you have to translate them.
In our case, we have done the translations for all languages at once using our own translation service.
Here is how it works:
- Create an account at ICanLocalize (that’s free).
- Create a new text resource project (still free).
- Upload the .po file and select which languages to translate to.
- The system counts the words in the file and asks for payment. Payment is calculated as 0.09 USD * words * languages. For instance, translating our own theme to both Spanish and German cost us $30 (together).
- Translators do the translation.
- You download all the translated .po files (one .po file per language), ready to be used by WordPress.
Adding translations to WordPress
Now that you have the translated .po files, you need to create the corresponding .mo file. For this, open each of your .po files with Poedit and click on Save. Poedit will create the .mo file for every .po project that you have.
Keep in mind that your .mo files names are important. All of them go into your theme’s folder (/wp-content/languages/themes/) and their names indicate which language they correspond to. You can choose any name you like, but we strongly suggest you to follow the standard locale naming convention of language_COUNTRY, where every term should have two letters.
For example, to provide the German (Germany) translation, you would name it de_DE.mo. For French from France, it would be fr_FR.mo.
For reference, you can see the locale names used by WordPress in the WordPress i18n project.
Remember that some of the translations need to be provided directly by WordPress, so keeping to the same naming is crucial.
Where to place your WordPress Translations
To fully translate your WordPress admin and your theme, you need the following two sets of .mo files:
- Your theme’s .mo files.
- WordPress .mo files.
Until now, all we have discussed was related to your theme’s .mo files and how you should place them in your theme folder. But what about your WordPress Dashboard?
In previous versions of WPML, you needed to manually install your WordPress .mo files. Nowadays, this procedure is automatically done by WPML at the moment of your language configuration.
WPML String Translation allows us to translate texts that are not in posts, pages, and taxonomy. This includes the site’s tagline, general texts in Admin screens, widget titles, and many other texts.
Activating the module
WPML’s String Translation module is part of the Multilingual CMS account type. To enable it, you first need to download and install it from your WPML.org account, under the Downloads section.
Then, go to the WPML → String Translation page in your site.String Translation admin screen
Choosing Which Strings to Display
A complex site may contain many strings to translate. Use the display filter, at the top of the String Translation page, to determine which strings to display.
- Which strings to display – choose the translation status (everything, translation complete, translation needed or waiting for translator)
- Strings domain – WPML organizes strings into different domains, making it easier to find a specific string. If, for example, you are looking for a widget string, select the Widgets domain
- Search – you can enter a search value to narrow down specific strings
Click on the translations link to open the translation editor.Translating a string
Be sure to click on translation is complete after you translate. Incomplete translations will not appear on the site.
If you are using WPML’s Translation Management module, you can also send strings to the translation by your translators.
Click on the checkboxes next to strings, select the language from the list (in the Translation options box), and choose to send to translation. Please note that you cannot choose a specific translator. All translators within a language pair would be able to translate the strings you’ve chosen.Sending strings to translation
When you no longer use a certain theme or a plugin you might wish to remove the strings associated with it. Simply select the strings you want to remove and click Delete selected strings.Deleting selected string
Original Language of Strings
You can set the source language of specific strings or all strings that belong to a domain (context).
To change the language of specific strings, select them and click on the new Change language of selected strings button. Then, select a new language.Change the language of selected strings
You can also change the language of entire contexts. This is useful when you get a theme or a plugin, that’s coded in a language other than English. Click on the new link, at the top of the String Translation page, Language of domains.Click on the link to ‘Languages of domains’
Then, choose the new language.Dialog for setting the language of entire domains
The dialog will show you a table of the strings in that domain. You can choose the new language and also make it the default language for new strings that will be added to that domain.
Advanced String Translation Features
Besides the basic filter and translation features, WPML offers advanced options, which can make your site administration simpler.
Track when strings appear on the site
This option helps you identify where strings are used on public pages in the site. When enabled, WPML will keep records of the PHP source and pages that display each string. This feature can help understand the correct context of strings and how they should be translated.
How to use:
- Enable the Track where strings appear on the site option.
- Visit the site’s front-end pages.
- Switch to a language other than the site’s default language.
- WPML will register any string that appears on the page you are viewing. Move from page to page to cover all the strings you need.
Please note that this is a database-intense operation. You should only enable it when building the site. When you are done registering strings, don’t forget to return to the String Translation admin page and disable ‘Track where strings appear on the site’. Your site’s speed will be significantly lower if you keep this option running in production mode.
Auto register strings for translation
WPML uses static code analysis to locate strings that require translation in the theme and plugins. In some cases, the static code-scan cannot reliably find all strings. This often happens when strings are generated dynamically using code (not really static/”hard-coded”).
By enabling auto-registration, WPML will register strings that need translation at display-time. The conservative option is to register strings when logged in as an administrator. This means that when a logged-in admin browses the site, WPML registers for translation any strings that are displayed.
This operation may increase a number of database queries while strings are registering for translation.
Import / export .po
You can import translations from other sources and export your current translations using .po files. If you choose to export strings without their translations, the file extension will be .pot (Portable Object Template). If you choose to include translations, the extension would be .po.
When you import translations, you must choose the language to import to.
Translating strings in the wp_options table
Many themes and plugins store texts in the wp_options table. This is also the case with Widgets. Widgets also store their setting fields in the wp-options table. You can tell WPML to register these strings to translation.
To do this, click on Translate texts in admin screens. This will open a dialog showing the strings that WPML finds in your site.Translate texts in admin screens setting
The list will often be a tree, which you can expand and collapse.Selecting strings in the wp_options table for translation
Developers note: Theme and plugin authors are encouraged to include a language configuration file in their code, which tells WPML which strings from the wp_options table to register for translation. This can save a lot of time for end-users configuring multilingual sites. You can easily export the strings you want by using the “Export selected strings as a WPML config file that can be added to the themes or plugins ” button (see image above).
If your option includes a lot of sub-options, you can use the asterisk (*) as a wildcard character in your configuration file. You can find more information and examples on our page about creating language configuration files.
Cannot find a text using String Translation?
If you can’t find the string you are searching for in String Translation, it may be under the page that lists admin texts. Check out our page about translating options coming from themes and plugins to see how to translate such texts.
If Not able to Translate the Theme
You are invited to register and get help directly from the WPML team. Please follow the invitation link below. This will allow you to create your own free end-user accounts. In this way you will receive direct support from the WPML team and access personalized instructions on how to translate Houzez.