Use the Poedit tool to translate Chinese WordPress themes

how to useTool translation into ChineseTheme, how to translate these fields that need to be localized!

If you are a WordPress theme production enthusiast, of course you will hope that the theme you create will be more popular. A very important way is to make the theme you create support more languages besides Chinese. This article talks about how to localize WordPress themes.

(In the following examples I use the themeO4was an example)

First you need to add localization support statements to your theme file, and 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 field in the above code is optional. It is used to tell WordPress how to select codes that can localize languages. Generally speaking, just fill in the name of the theme. The green field tells WordPress the calling path of the localized language file. It is usually written that way and does not need to be changed.

After setting up the above code, everyone starts to define which fields in the theme file need to support language localization. I will use a title code in the sidebar as an example. Before language localization was supported, the code looked like this:

Most Popular

I hope to modify the Most Popular above to support localization. I only need to modify the code to be as follows:

php _e('Most Popular', 'js-o4w');

You can see the modified content. Let’s take another example, such as a piece of code I put in the footer information:

Copyright 2009

I want to modify the copyright to support localization. The modified code is as follows:

[cc lang=”php”]php _e('Copyright', 'js-o4w');

I believe that by now everyone has a good understanding of how to modify the code that displays the character field in the theme. Note that the above two sentences of code 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 must correspond to each other. Then after everyone has modified everything that needs to be modified, how to translate these fields that need to be localized?

download:PoeditV2.3 translation editing tool

First download onePoeditthis editing tool. Then we need to create a new folder in the theme directory, because we need to place translated files in this folder for the system to read. According to the green field in the code at the beginning of this article, the name of our folder is:languages.

Next step to usePoeditCreate a new "Message Catalog Document", as shown below:

使用Poedit工具翻译汉化WordPress主题-1

Then it requires us to initialize the document.

使用Poedit工具翻译汉化WordPress主题-2

In this example, I need to translate the above English fields into Chinese, so I filled in the "Project Information" column in the settings like this. These fillings are not very important, they are just some record information and the like, and do not affect the translation operation. .

使用Poedit工具翻译汉化WordPress主题-3

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.

使用Poedit工具翻译汉化WordPress主题-4

The third tab is used to determine the keywords that need to be translated automatically. This is to tell the software that when a word appears in the code, make sure it is selected as the field to be translated. Just fill it out according to the picture above. Did you find that the "_e" above exists in the example code I mentioned earlier? Everyone understands.

After everyone has set up according to the above,Remember to store the file in the directory languages created earlier. Because this is a translation of Simplified Chinese, the file name is zh_CN and the suffix is .po.

Next, click on the third icon in the software (marked in red in the picture below). The software of Hua La Hua La lists all the fields in our theme file that meet the requirements and need to be translated. It is very efficient.

使用Poedit工具翻译汉化WordPress主题-5

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 a field that has not been translated is left blank, as shown in the figure "Read more".

使用Poedit工具翻译汉化WordPress主题-6

We click on the field that needs to be translated, and then fill in the translated content in the bottom column. Just translate the fields that need to be translated one by one, please be patient.

When all fields that need to be translated are complete, clickAs shown belowred button.The software will save the current compiled file zh_CN.po and at the same time generate a file with the same file name but the suffix .mo in the directory of the file.

使用Poedit工具翻译汉化WordPress主题-7

Because we can compile files with the suffix .po, but we cannot compile files with the suffix .mo, but it is a file that the system needs to read.Therefore, please be sure to repeat the above steps every time you change the .po file in the future and update the corresponding .mo file.

使用Poedit工具翻译汉化WordPress主题-8

The basic operation is like this. Once you have translated it into Simplified Chinese, you can translate it into other languages. All the steps are the same as mentioned above, just the translated content is different. I believe everyone will draw inferences from one example.

So one more thing, how does WordPress know which language file to read? In fact, in its wp-config.php file, isn't there the following sentence?

[cc lang=”php”]define ('WPLANG', 'zh_CN');

Pay attention to the 'zh_CN' part, this is the language file read by the theme.

Next let us do the translation work. If your English is not good, you can useGoogle TranslateorYoudao translationAssist with translation

score

Leave a Reply

Your email address will not be published. Required fields are marked *