This article will describe how to translate your WordPress theme into another language. WordPress supports only a single language in a single WordPress installation. We will be showing you how to translate theme into another language other than English.
- The files that are involved in translation are en_US.po and en_US.mo. The files are located in the root directory of your theme (ie. /wp-content/themes/Karma)
- The 2 files above are required to translate the theme into another language. We’ll be showing you how to create a new “.po” file and the “.mo” file will be auto-generated for you.
- In this tutorial, we will use the very popular Poedit for translating the english “.po”into your language. You can download Poedit here.
Naming Convention of the .po and .mo file
The naming convention is based on the language code (e.g. zh for Chinese) followed by the country code (e.g. _CN for China). So, the Chinese file would be called zh_CN.po and zh_CN.mo. See the complete list of language codes and country codes to find your exact locale. Please note that if you name the file wrongly, WordPress will not pick up the translated strings.
Defining your language in wp-config.php
You will also need to make a change to your WordPress wp-config.php file (located in your WP root directory) with the correct language codes like the example below. If you don’t have a WPLANG entry then create one. define (‘WPLANG’, ‘zh_CN’); This language define in wp-config.php will tell WordPress to load your language files. The above example, will tell WordPress that this is a Chinese WordPress site and should load the Chinese zh_CN.po from the theme files.
Steps to translate the en_US.po to your language .po
1) Download and install Poedit. There are versions for Windows and Mac 2) Launch Poedit 3) At the toolbar of Poedit, click on File > Open and Browse to your theme folder and select en_US.po to open it. 4) As you can see from the screen shot below, the top part of the file contains the entire list of text that needs to be translated. Each line represents a place within the theme that stores the text. If you click on different lines, you’ll notice the section below displays that exact line of text. In this case we clicked on “Your comments is awaiting moderation”. 5) The blank box below that is where you will type in your translations. So in the screen shot I translated “Your comment is awaiting moderation” into Chinese by typing in the translation “你的评论正在等待审核” in the box below. You will need to hit enter key for the translation to be updated on the “translation” section on the right, which is next to the “Original string”. 6) Do the translation for all the string and “save as” into the file name that you need. In this example, we will save as zh_CN.po. You will find zh_CN.mo being automatically created by Poedit. 7) You can upload the newly created language files to your theme folder on your server. In this case we will upload zh_CN.po and zh_CN.mo 8 ) Clear your browser cache and re visit your site and the theme strings should be in your language.
Why are certain text not translated?
Only text that are written in theme files that are wrap with __() and _e() functions are translatable. User publish content via post editor or widgets are not translatable, User should write in their own language. Text inputs in Site Options are not translatable, User should write in their own language.
Why can’t I translate this theme into multiple languages?
Multiple language translations on a single installation involves using third party premium translation plugins. These premium translation plugins have their own Application Interface, our theme does not work with these premium translation plugins out of the box. Certain degree of programming modification is needed to make our theme work with these plugins. Modifications such as converting all text input in Site Option into hard coded translatable strings. Therefore, clients are strongly advised to engage a competent WordPress Developer to assist in integrating third party translation plugin into our theme. We will not be providing custom coding, however we will assist in providing related information.