I got a little bit of time recently, so I’ve updated the Known vagrant build.

The latest vagrant package now uses the latest Ubuntu LTS – Xenial – as it’s build. It also makes some changes to the environment, including, we now use mariadb instead of the now rather defunct (and in some cases broken) Oracle mysql server. The build also now runs PHP 7.0.

If you’re like me, you might need to update your version of vagrant and VirtualBox in order to successfully boot the newer Ubuntu images, so be sure you do that.

» Visit the project on Github...

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

./makepot.sh /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/DOMAIN.mo|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: