To localize Flus, I use the “old-but-still-good” gettext() function which is aliased by _() (you might have seen it from time to time).
In templates, this method is aliased behind the t() function.
English is the default language of Flus.
For the other languages (only French at the moment), the locale files are placed under the locales/ folder.
Each language defines at least three files.
For French:
locales/fr_FR/metadata.jsondeclares (only) the language in a human-readable way (“Français”);locales/fr_FR/LC_MESSAGES/main.pois where the strings are translatedlocales/fr_FR/LC_MESSAGES/main.mois the compiled version of this file, used by PHP.
I don’t manipulate the two last files directly, but I use Poedit, a translation editor which is able to manipulate po and mo files.
Note that to be able to parse Twig files, you'll need the "pro" version.
Sometimes, I need to localize strings within the JavaScript code.
In this case, the _() function is a bit different since it's not provided by PHP.
It must be imported:
import _ from 'js/l10n.js';
console.log(_('Hello World!'));The function will look into the window.jsConfiguration.l10n object to search for the string.
To add a new translation to this object, you’ll have to add the string to the $translations array from the src/utils/javascript_configuration.php file.