I’m using the xili language plugin to handle the multi-lingual aspects of this blog. While the plugin is hardly user-friendly I managed to make it work, and built a child theme that patches the Sixteen theme so it works properly with multilingual data.
The next step was localise post categories. In theory, I could have used the xili dictionary plugin, but that one is even more confusing, so in the end, I decided to just write the localization files (so-called
gettext files) by hand. While this sounds hardcore, it really isn’t.
Do do this, you really only need a text editor and a tool to generate
.mo (machine readable) out of
.po (portable) files. Here I’ll use
msgfmt which is available on most Unix installations.
.po file is a list of translation from a source language (typically english) to some other language. The file that explains how to translate my categories looks like this:
msgid "" msgstr "" "Project-Id-Version: Sixteen-child\n" "Report-Msgid-Bugs-To: root@localhost\n" "Last-Translator: Matthias Wiesmann <root@localhost>\n" "Language-Team: Matthias Wiesmann <root@localhost>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "Language: fr_FR\n" "POT-Creation-Date: \n" "PO-Revision-Date: \n" # msgid "Stories" msgstr "Histoires"
The only interesting line in header is the one that specifies that the language for this file is
fr_FR, the last two lines explain how to translate Stories into French: Histoires.
This file should be named
local-fr_FR.po and placed into the
languages directory of your theme. WordPress does not understand
.po files directly, they need to be compiled to
.mo format, this is done with the following command:
msgfmt local-fr_FR.po -o local-fr_FR.mo