Localization

For localization to work, all phrases that are displayed to the user must be output using language functions:

<?php echo __('Customer'); ?>

// Or 

<?php echo __l('Customer'); ?>

Plural Forms

To describe plural forms in a PO file, you need to specify Plural-Forms in the metadata and describe different plural forms:

msgid ""
msgstr ""
"Plural-Forms: nplurals=3; plural=((n%10==1 && n%100!=11) ? 0 : ((n%10>=2 && n%10<=4 && (n%100<12 || n%100>14)) ? 1 : 2));\n"

msgid "lesson"
msgid_plural "lessons"
msgstr[0] "урок"
msgstr[1] "урока"
msgstr[2] "уроков"

To get the translation, specify the string identifier in singular and plural forms along with the number of items:

<?php

echo __p('lesson', 'lessons', 3); // урока

Value Substitution in Translation Strings

All translation functions can accept additional parameters that will then be substituted into the translated string in place of conversion specifiers, similar to how the sprintf function works:

<?php

echo __('You get %s points on the subject of %s', 5, 'mathematics');
// You received 5 points in the subject mathematics

// Here the third parameter indicates the number of hours, and the fourth is the parameter for substitution
echo __p('%s hour ago', '%s hours ago', 5, 5); // 5 hours ago

Translation Editor

For translation files, we recommend using http://www.poedit.net/download.php

Generating PO File

Festi CLI has a command to generate PO files:

./vendor/bin/festi-locale