Excellent software and practical tutorials
How to usePoeditTool translation Chinese WordPress theme, how to translate those fields that need to be localized!
If you are a WordPress theme maker, you will certainly hope that your themes will be more popular. One important way is to make your themes support more languages besides Chinese. This article will talk about how to localize WordPress themes.
(In the following examples, I will use the themeJ4was an example)
First you need to add localization support statements in your theme file. Add the following code to the function.php file in your theme:
function theme_init(){ load_theme_textdomain('js-o4w', get_template_directory() . '/languages'); }
The red fields in the above code are arbitrary, they are used to tell WordPress how to select the code that can be localized. Generally speaking, you can just fill in the name of the theme. The green fields tell WordPress the calling path of the localized language file, which is usually written like that and can be left unchanged.
With the above code settings, we can start to define which fields in the theme file need to support language localization. Here I take the title code in the sidebar as an example. When language localization is not supported, the code is as follows:
Most Popular
I want to modify the Most Popular above to support localization. I just need to modify the code as follows:
php _e('Most Popular', 'js-o4w');
You can see the modified content, right? Here is another example, such as a piece of code in my footer information:
Copyright 2009
I want to modify the copyright to support localization, and modify the code as follows:
[cc lang="php"]php _e('Copyright', 'js-o4w');
I believe that everyone now understands how to modify the code for displaying character segments in the theme. Note that the above two codes both contain identification fields:
js-o4w
It is used to correspond to the random part I mentioned in the code at the beginning of the article. They should correspond to each other. Then, after you modify what needs to be modified, how do you translate these fields that need to be localized?
download:PoeditV2.3 translation editing tool
First download aPoeditThis editing tool. Then we need to create a new folder in the theme directory, because we need to put the translated files for the system to read in this folder. According to the green field part in the code at the beginning of this article, the name of our folder is:languages.
Next stepPoeditCreate a new "Message Catalog Document", as shown below:
Then it requires us to initially set up this document.
In this example, I need to translate the English fields above into Chinese, so I filled in the "Project Information" column in the settings like this. These fields are not very important, just some record information, which does not affect the translation operation.
The next thing to fill in is the second tab "Path". This step is very important, please fill it in as shown in the picture. Because it will tell the software where to get the fields that need to be translated.
The third tab is used to determine the keywords for automatically obtaining the fields that need to be translated. This tells the software to select the words that appear in the code as the fields to be translated. Just fill in the fields as shown above. Do you find that the "_e" above exists in the example code I mentioned earlier? Do you understand?
After you have completed the above settings,Remember to save the file in the languages directory created earlier. Since this is a translation of simplified Chinese, the file name is zh_CN and the suffix is .po.
Next, click the third icon in the software (as shown in red in the figure below). The software will list all the fields in our theme file that meet the requirements and need to be translated. It is very efficient.
As shown in the figure below, the tool displays two columns, the left side is the field that needs to be translated, and the right side is the translation. When the right side of the field has not been translated, it is left blank, such as "Read more" in the figure.
We click on the field that needs to be translated, and then fill in the translation content in the bottom column. Just translate the fields that need to be translated one by one, and be patient.
When all fields that require translation are complete, clickAs shown belowred button.The software will save the current compiled file zh_CN.po and generate a file with the same file name but the suffix .mo in the directory of the file.
Because we can compile files with the suffix .po, but we cannot compile files with the suffix .mo, but they are files that the system needs to read.So please be sure to repeat the above steps and update the corresponding .mo file every time you change the .po file in the future.
The basic operation is like this. After you have finished translating the simplified Chinese version, you can translate other languages. All the steps are the same as mentioned above, but the content of the translation is different. I believe you will be able to apply what you have learned to other situations.
So let me say one more thing, how does WordPress know which language file to read? In fact, in its wp-config.php file, isn’t there a sentence like this?
[cc lang="php"]define ('WPLANG', 'zh_CN');
Note the 'zh_CN' part, this is the language file that the theme reads.
Next, let's do the translation work. If you are not good at English, you can useGoogle TranslateorYoudao TranslationAssist in translation