Translating WordPress into another language
Step 2: Translating
This is the most important step and the one where you use your multi-lingual abilities. While the process involved may differ depending if you are using poEdit or gettext, the principles remain the same. All translation must be done intelligently and not literally. In most cases the original text may not translate directly into another language and it is up to your judgment to decide upon an alternative that makes sense in the localized language.
You may experience instances of not knowing what the original text means. For example, the text %s %d means nothing to anyone other than the programmer. In these situations you will need to look at the context, and this requires you to go to the source. In poEdit you can use the Show reference option from the Edit menu, and in gettext you will need to open the specified source file (both file and line number are shown in the POT file). Hopefully when you see the text in its context you will be better able to decide what it means. If all else fails go to the theme or plugin author and see what they say!
poEdit
poEdit presents all the localizable text in its main window. Clicking on any line allows you to edit the localized version:
You should work your way through the list of text until everything has been translated.
If poEdit should find text that requires pluralization it will present you with a slightly different interface:
You can see that there are two items of text to translate (singular and plural). The tabs along the bottom will change depending how many forms of pluralization your chosen language contains (based upon the plural forms value in the catalog settings). You should enter a translation inside each tab that reflects the number shown in the tab title. For example, 'Form 0 (e.g. "1")' will, in the case of English, contain the singular form, while 'Form 1 (e.g. "2")' will contain the plural form.
As with any software you should make sure to save regularly.
gettext
At this stage of the localization process you will need to use a text editor. The choice of editor is left up to you, but it should be capable of handling character set encodings correctly (i.e. when you save the file it is saved in UTF-8, or whatever character set you require). On Windows you can use UltraEdit, on Linux you can use vi or Emacs, and on Mac OS X you can use TextEdit.
Open the POT file using your editor. Every localizable text is contained in its own section:
You should work your way through the file, entering translated text in the empty section. That is, for every line starting with msgid you should put the translation into the following line starting with msgstr. Pay attention to the surrounding quotes, and if you do need to enter a quote into the translated text you must escape it by prefixing it with a backslash:
msgstr "My \"escaped\" quote"
Pluralization will occur as follows:
msgid "%d window" msgid_plural "%d windows" msgstr[0] "Translation when 1" msgstr[1] "Translation when more than 1"
The msgid value defines the original singular text and msgid_plural the original plural text. You should enter a translated version in each of the msgstr[] lines as necessary for the pluralization rules of the target language.
Notes on translation
Programmers often need to insert run-time values into text. This is achieved using something known as printf-style format strings. A printf-style format string is a string of characters that is passed to the PHP function printf and which, when accompanied with run-time values, results in a final formatted string. For example:
<?php printf ('Hello %s', $username); ?>
Here the format string is 'Hello %s'. The printf function knows that %s means to insert a run-time string, and the value of this is passed in the $username variable. The result of this function may be:
Hello John
In terms of translation, you will be required to retain printf-style formatting in translated text. Sometimes it is important to also be able to change the position of the run-time values, and this is achieved through placeholders:
Hello %1$s, today is %2$s
As before you should retain these placeholder codes. However, you are free to move their position about in the translated text. In this example, %1$s will always be the name, and %2$s will always be the day.
Today is %2$s and your name is %1$s
Dates and times are also another part the localization process, and a programmer will typically include special date format strings to be translated:
F j, Y g:i a
Each character represents a particular attribute of a date or time (such as month or year). You should consult the PHP date page for full details of what choices are available, and use the most appropriate codes for the target language (including changing the order). The above example will result in a date in the style of: August 9, 2007 4:05 pm.
Please direct all support questions to the support forum.






Comments
Comments are shown on the first page.