In the latest builds of Known, I’ve added support for Gettext translations. This can operate in tandem with the string array mechanism used previously, but it is my hope that using gettext will make translations easier, as there is a more complete tool chain available.

Creating .POT file

The first step, after you’ve used \Idno\Core\Idno::site()->language()->_() to write your strings, is to generate a POT template translation file. To do this, in /languages/ there’s a helpful script, go into this directory and run the script

./ /path/to/your/plugin > /path/to/your/plugin/languages/

This will parse all your plugin’s PHP files and extract translatable strings.

Creating your translation

Open up your .POT file with a suitable tool, e.g. poedit, and save your .mo and .po files as /path/to/your/plugin/languages/LOCALE/LC_MESSAGES/|po, where:

  • LOCALE is the locale you’re writing for, e.g. pt_BR
  • DOMAIN is the domain, e.g. your plugin name ‘myplugin’

Registering your translation

In your plugin, register your language by registering a new GetTextTranslation class, passing the path of your languages directory, and the domain you used.

So, for the above example this might look like: