I’ve done a translation of the Sandbox theme for my swedish section of the site using the GNU gettext tools. It’s pretty simple.
The following command line examples assume you already are in the sandbox
theme directory.
Generate a PO Template
First we have to create a PO Template.
$> xgettext --foreign-user -k__ -k_e -d sandbox -n *.php
$> mv sandbox.po sandbox.pot
- Edit the charset to read
UTF-8
.
Creating a PO File
Start by creating a PO File from the PO Template, in this case using the locale sv_SE (swedish as language, Sweden as country) and output a file using the locale as name.
Now time has come to translating the theme. You can either use a simple text editor or something more fancy like KDE’s KBabel. Anyhow, the editor (in this example) need to spit out UTF-8 encoded output.
$> msginit -l sv_SE -i sandbox.pot -o sv_SE.po
- Translate the messages in the
sv_SE.po
file.
Updating a PO File
When code may have changed (for example a new version being released) we need to update the translation project.
Begin with regenerating the sandbox.pot
PO Template as described above. Continue by updating the translated PO File using the new template and edit the updated file for new or missing translations.
$> msgmerge -U sv_SE.po sandbox.pot
- Translate any new messages in the
sv_SE.po
file.
Generate a MO File
Unfortunately the plain text PO file isn’t very efficient to use by the gettext library. Instead we have to generate a binary MO file from it that can be read by the gettext library efficiently.
$> msgfmt -o sv_SE.mo sv_SE.po
- That’s it, really!
Install your translation
Just drop the MO file into the theme directory and don’t forget to set the locale in wp-config.php
, and your site will be both localized and internationalized!