Internationnalisation (i18n)

Galette source code is entirely internationnalised thanks to GNU Gettext. All translatable strings in the source code must be in english.

The lang directory contains:

  • Makefile,, utilities to manage translations,
  • *.pot: transaltions template files, one per domain,
  • *.po: translation files, one per lang and per domain.

Galette core, all oficial plugins as well as documentations are translated using Weblate platform.


Two different types of syntax are used:

  • PHP syntax,
  • Smarty syntax.


For PHP syntax, this is the _T function that is used. There is a second optionnal argument for translation domain, which defaults to galette.

echo _T("Hello world!");
echo _T("Hello world!", "galette"); //galette is the default domain


Another method, __() is very similar to _T(). This one will not mark strings which miss a translation.

This was used to translate routes mainly; but this is no longer possible.

Often, you will have to use variables in translated strings. To do that, use a placeholder in the string to translate, and use something like str_replace or preg_replace to do the effective replacement:

echo str_replace('%name', $adh->name, _T("Hello %name!"));
$search = array(
$replace = array(
echo preg_replace(
   _T("Hello %name %surname from %town")


You can use any word you want as pattern, just try to keep simple for others :) There are several other ways to handle string replacements, check PHP documentation.


Smarty translation is done with a custom plugin:

<p>{_T string="Hello world!"}</p>
<p>{_T string="Hello world!" domain="galette"}</p>

Smarty comes with modifiers that may be used to do remplacements among others. But it is done before the text is sent to the plugin, so translation cannot be found (it already contains a replacement value for our pattern). Our Smarty plugin can take two optionnal arguments to handle properly replacements:

<p>{_T string="Hello %name!" pattern="/%name/" replace=$adh->name}</p>

Translation domains

New in version 0.9.

Galette uses translation domains to prevent string replacements from external sources. Default domain name (implicit if not specified) is galette

Each plugin will come with at least one domain of its own.

You must then tell the functions which domain you want to use:

echo _T('Hello, you'); //uses default domain, french will be 'Bonjour, vous'
echo _T('Hello, you', 'another'); //use another doamin ; french will be 'Salut, toi'

Same example, with Smarty:

{_T string="Hello, you!"}
{_T string="Hello, you!" domain="another"}

Generate lang files

There are several steps to update Galette translations:

  • extract strings from source code and update translation templats (POT files) (run make extract from lang directory and commit updated POT file),
  • (let translators do their job)
  • retrieve translated files (PO) from translation platform
  • compile translation files (MO)


It is possible to generate local PO files with make po, but all mecanisms assume the translation platform is used.

Once the updated POT file has been pushed to the Github mirror, an update is triggered on the Weblate platform. Weblate translations are commited in a forked Git repository, and must be merged back to Galette:

$ git remote add weblate
$ git fetch weblate
$ git merge weblate/develop

Finally, you must compile translations (compiled files are the ones used):

$ make mo

In order to refresh known languages, you will have to logout/login from your Galette instance. You may have to restart PHP as well.