Translation and Pluralization on SocialEngine

Marco Enrico
2 min readFeb 7, 2020

--

Translation is done in view scripts with the translate view helper. Invoking it with a single string parameter will make it return string translated to the auto-detected locale. You may also indicate a locale short code as a last parameter and it will return the string translated the locale indicated by the last parameter.

Translations are done using the language files. The are the CSV files under applications/languages/<localeShort Code>/<moduleName>.csv. It may be the case that the string’s translation is not available in the indicated local (or the auto-detected locale). If that’s the case the view helper will return the string untranslated and log the fact in firebug if you have the plugin active on the browser and the site is in development mode.

This information is also logged in the log file translate.log.

Pluralization is done with the same view helper with the following code snippet:

The first parameter is an array whose first element is a format string for the singular form of the word or phrase, the second element is the plural form of of the word or phrase and the third element is the number from which the view helper will determine which format string to use (singular or plural). The second parameter is the number to be substituted in the format string. It is wrapped with the locale view helper which will return the number formatted in the auto-detected locale.

Originally published in https://social-engine-tutorials.blogsplot.com.

--

--

No responses yet