Internationalization

These are the coding conventions for NethServer i18n. Each package repository should respect them.

  • The developer prepares the translation source strings when the code has been written.

  • 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
    
  • Once translators complete their work a new release of nethserver-lang can occur.

Currently both gettext and Server Manager specific formats are supported for language catalogs.

Server Manager (Cockpit)

Packages providing an application for the Cockpit Server Manager must adhere to the guidelines documented here:

https://nethserver.github.io/nethserver-cockpit/i18n/#translations

Server Manager (Nethgui)

To configure the Transifex client and find the string catalog files execute the txinit.sh script on the repository root. The script can run multiple times, when new catalogs are added to the repository.

PHP files

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?';
  1. Omit ending sequence ?>.
  2. 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>.

gettext files

The gettext format is used by the TODO scripts in the old Server Manager.

The xgettext command can be used to extract strings from the source code. The resulting .pot file must be named locale/<rpmname>.pot.

For example we will translate a new TODO message for the web interface.

Steps to setup translation for a new todo:

  1. Be sure gettext is installed in your system

  2. Add the todo script to the git repository

  3. Create locale directory inside the git repository root:

    mkdir locale/
    
  4. Extract the strings (from a Python source code):

    PACKAGE=$(basename `pwd`)
    xgettext --msgid-bugs-address "translations@nethserver.org" --package-version "1.0.0"  \
    --package-name "$PACKAGE" --foreign-user -d "$PACKAGE" -o "locale/${PACKAGE}.pot" \
    -L Python root/etc/nethserver/todos.d/*
    
  5. Run the txinit.sh script and commit newly created files into git.

  6. Upload the new .pot resource to Transifex (special permissions are needed):

    tx push -s