Quantcast
Channel: Dahnielson » Language
Viewing all articles
Browse latest Browse all 6

Playing With Gettext in the Sandbox

$
0
0

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.

  1. $> xgettext --foreign-user -k__ -k_e -d sandbox -n *.php
  2. $> mv sandbox.po sandbox.pot
  3. 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.

  1. $> msginit -l sv_SE -i sandbox.pot -o sv_SE.po
  2. 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.

  1. $> msgmerge -U sv_SE.po sandbox.pot
  2. 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.

  1. $> msgfmt -o sv_SE.mo sv_SE.po
  2. 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!


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images