-
Notifications
You must be signed in to change notification settings - Fork 2
Localization
The Dignitas database is in Romanian. The interface, however, has full localization support. To achieve this, strings in PHP and in Smarty templates are written as English keywords and surrounded by calls to gettext()
, such as
{t}label-remember-me{/t}
or, with argument support,
{t 1=$upvotePriv|nf}info-minimum-reputation-upvote-%1{/t}
We use poedit to build the catalog of English and Romanian translations. So far these are the only languages we support.
- Install the
gettext
package for your OS or distribution. - Activate the
gettext
extension in PHP. - Choose the preferred locale in
Config.php
. Note that the names must match exactly. For instance, if your system has aro_RO
locale, but thelocale/
directory has aro_RO.utf8
subdirectory, localization won't work.
We'd like to keep up with localization. You don't need to do the translation yourself, but we'd appreciate it if you tagged the strings that need be localized.
- In PHP, write any literal strings in English and surround them with a call to
_()
(a nice alias forgettext()
). So instead of
return 'login failed'; // or
return 'autentificare eșuată';
please say
return _('info-login-failed');
- In Smarty templates, use the
{t}
block around string literals. We recommend doing this at paragraph level:
{t}some-descriptive-string-keywords{/t}
We use the smarty-gettext module. Please read its documentation, including the localization of plurals such as:
{t
count=count($results)
1=count($results)
2=$query
plural="number-results-plural-%1-%2"}
number-results-singular-%1-%2{/t}
This is optional, but we'll love you if you contribute your own translations! We use poedit for translating. It needs some light customization for the Smarty syntax (poedit doesn't know it by default).
- Install poedit.
- Run
poedit locale/<your_language>/LC_MESSAGES/messages.po
- Go to Edit > Preferences and enter your name and email address.
- Under Edit > Preferences > Extractors, hit + to add a new parser. Set these values:
- language = Smarty
- extensions = *.tpl
- parser command = php /path/to/dignitas/lib/smarty-plugins/tsmarty2c.php -o %o %F
- an item in input files list = %f
To do the actual translation:
- Run Translation > Update from Source Code.
- Translate any new strings.
Please note that Apache (and possibly other HTTP servers) tend to cache the translated catalog. If you notice your newly added translations aren't being picked up, please restart Apache.
Before committing your changes, please diff messages.po
and ensure you haven't deleted any existing translations. If something goes wrong, for example if the path to the Smarty extractor is incorrect, then poedit simply comments out messages it can no longer find in the source code.
In time, we collected enough Javascript strings that it was no longer scalable to translate them in the backend. We rolled our own rudimentary translation system for Javascript.
To use it, please copy en_US.js to your desired name and translate it. Please be sure to adapt the _plural()
function to your language's needs. We can help with that part if you need us to.