Internationalization¶
These are the coding conventions for NethServer i18n. Each package repository should respect them.
The developer prepares the translation source strings when he writes the code.
Each translation catalog must be mapped to a resource on Transifex.
Whenever new strings are added or existing ones are changed, source catalogs must be pushed into Transifex with Transifex client:
tx push -s
To configure the Transifex client execute the txinit.sh script on the repository root. The script can be executed multiple times, if new catalogs are added to the repository.
Currently both gettext and Server Manager specific format is supported for language catalogs.
gettext¶
The xgettext
command can be used to extract strings from the
source code. The resulting .pot
file must be named
locale/<rpmname>.pot
.
gettext example¶
In this example we will translate a new TODO message for the web interface.
Steps to setup translation for a new todo:
- Be sure gettext is installed in your system
- Add the todo script to the git repository
- Create locale directory inside the git repository root:
mkdir locale/
- Extract the strings (from a Python source code):
PACKAGE=$(basename `pwd`)
xgettext --msgid-bugs-address "[email protected]" --package-version "1.0.0" \
--package-name "$PACKAGE" --foreign-user -d "$PACKAGE" -o "locale/${PACKAGE}.pot" \
-L Python root/etc/nethserver/todos.d/*
- Run the txinit.sh script and commit newly created files into git.
- Upload the new
.pot
resource to Transifex (special permissions are needed):
tx push -s
Server Manager¶
All source language catalog files are placed in
root/usr/share/nethesis/NethServer/Language/en
. We assume
en
is en-US
.
The catalog format is a common PHP file where the array variable
$L
is assigned some keys:
<?php
$L['string_id_1'] = 'This is an example';
$L['string_id_2'] = 'What is a PHP array catalog?';
- Omit ending sequence
?>
. - Use UTF-8 encoding.
Given a module with name “Test”, the source language file will be
root/usr/share/nethesis/NethServer/Language/en/NethServer_Module_Test.php
.
When the Server Manager is running in debug mode, missing translation
labels can be found in /var/log/messages
. To enable the
debug,
Unlock
index_dev.php
controller:touch /usr/share/nethesis/nethserver-manager/debug
Prepend
index_dev.php
on URLs path, eg:https://<ipaddress>/index_dev.php/en/<module>
.