How to translate a WordPress theme into any language
Over the years we have seen rapid growth in WordPress and its relevance in the web design community. Right now WordPress is the most popular CMS around the globe according to statistics. It is the perfect content management system regardless of nationality or language and its default installation is available in almost any language you can imagine.
Lately, more and more people are asking us how to translate a WordPress theme (front-end) into a language other than the default English, which is already packed in our themes. This article explains how to take the language file that is included with a Gavick WordPress theme and translate it into your native language.
Steps for a successful translation process
Translating WordPress Theme is easy, but labor-intensive. All of our themes include a language file (.pot) to make translating to a different language possible. Once you’ve got your theme, open up the zip file and find the language folder (if you are using a quickstart package you will find the language folder in the following location: /wp-content/themes/gavickthemename/languages) and look for a language file named themename.pot, for example ShopAndBuy.pot.
Unfortunately, to display text in a foreign language, you have to create .po and .mo language files.
That’s why we suggest you use Poedit (www.poedit.net), an easy to use open source program available for Mac OS X, Windows and UNIX/Linux. It is possible to use any text editor but it is much easier to use Poedit rather than a regular text edit so I strongly recommend you download it.
- Open Poedit and go to File -> New catalog from POT file and select the POT in your theme’s languages folder.
- A properties box will pop up asking you about general information. In the Language field enter the language name you want to translate.
- When you click “OK” button you’ll be asked what you want to name your translation file. The name is important and there’s a particular format you will need to follow. Each language and country has a specific code you will need to use when saving translation files. For instance if you have translated a Gavick WordPress theme to Spanish you should use “es_ES.po” as the file name, or if you have translated it to German, then “de_DE.po” would be the correct naming structure. This will make sure that WordPress understands what language you are referring to.
- Save your language file.
- Now you can start translating the Gavick theme. Go through every line of text and translate it to the required language. The String translation mechanism allow for the replacing of texts in the original language with texts in other languages. Using this tool you or a hired translator cannot change anything else. They only translate the texts that you give them.
If you think that there is text that won’t require translation you may leave them as they are in the original language and you may translate them later if required. Below is example from the Polish translation process.
- When you’ve finished translating, you have to save your file again. Poedit will automatically create/save both .po and .mo files.
Translation Tips: Character Encodings
All localizations should be a UTF-8 version. All translations should be written literally, rather than escaping accented and special characters with HTML character entities. Some characters must be escaped to avoid conflict with XHTML markup: angle brackets (< and >), and ampersands (&). In addition, there are a few other characters that function better when escaped, such as non-breaking spaces ( ), angle quotes (« and »), curly apostrophes (’) and curly quotes. When we create multilingual sites, we need to remember that translation is not everything. Localization means adapting the site to a different language, country and conventions. So don’t translate literally; translate organically.
How to use translated language files in WordPress
Once translation has been done, the first thing to do is to get/check your language and country code so you can tell WordPress which language file to use. You’ll need to make sure your wp-config.php file settings match your language files. By the way, this configuration file is located in the main directory where all your core WordPress files are located. Then set your language in wp-config.php, like this:
/** * WordPress Localized Language, defaults to English. * * Change this to localize WordPress. A corresponding MO file for the chosen * language must be installed to wp-content/languages. For example, install * es_ES.mo to wp-content/languages and set WPLANG to 'es-ES' to enable Spanish * language support. */ define('WPLANG', 'es-ES');
The last step is to upload your created language files to the language folder of your theme using FTP / SFTP. If you’re using a Spanish translation, you’ll need to upload the es_ES.po and es_ES.mo files to your theme folder.
Your internationalization should be complete! Remember since you’ve translated only your theme and not your backend, your WP site will display in new language but your WordPress admin area will continue to display in English. You may read more about this topic in this article.
More resources regarding how to translate WordPress into your language is located here.
Share your Language files with others
If you have already translated a theme many of our users would be delighted if you shared your translation files with the community. Just send them to email@example.com and we will include the translation files within the next GK theme update if possible. Thank you very much for your contribution!