This is an old revision of the document!


Sahana I18N/L10N

GNU Gettext

“The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications”

Usage

When using gettext we can use the gettext() or _() function. But we will be using the _() function for sahana. (Even if you use gettext() it will still work)

 
e.g:
non localized
<title><?php print "DVR Home"; ?></title>

localization enabled
<title><?php print _("DVR Home"); ?></title>

Database Localization

Gettext framework doesn't support localization of strings stored in the database directly. Because of that Sahana uses a separate table named 'lc_fields'. This table holds the name of the table and field where the data in that field should be translated along with the Sahana web-interface translation.

The Structure of 'lc_fields'

id table field
1 rms_req_category category
2 rms_req_category description

The database fields that need to be translated in to other languages should be added to this table (lc_fields).

Database Localization Usage

To display a value retrieved from the database in some other language, the developer has to use use the function _lc(). This function takes a single string as the paramiter and will return the translated value of that string. If a translation is not available this will return the same value.

_lc() function
[ string ] _lc ( $string )
example
    $sql = "SELECT * FROM rms_req_priority";
    $recordSet_prio = $global['db']->Execute($sql);

    $rs = $recordSet_prio->getArray();

    ....

    foreach($rs as $r)
    {
    ?>
    <tr>
        <td><?php print  $r['priority_id'] ?></td>
        <td><?php print  _lc($r['priority']) ?></td>
        <td><?php print  _lc($r['description']) ?></td>
    </tr>
    <?php
    }

This will display the translated values of Priority, Description.


More information on gettext:

Sahana Translation Web Interface

Sahana now has a web interface for the language translation using the GNU Gettext framework. Currently using this interface the user can [ extract ] the strings that needs to be translated and create the template file for the translation, add the translation to the PO file and compile the PO file to create the MO file. Using this interface the user can also add strings manually (Database values etc..) to be translated.

Configuration

For the web interface to work you have to give read write permission to the 'res/locale/' and all it's sub directories. You also have to have gettext installed and have 'xgettext', 'msgfmt and 'msgmerge' available with in an accessible PATH (/usr/bin/) to get the full functionality of the system. You have to have the gettext extension in php for the translation to work. Otherwise you will only see the strings in the base language, which is usually en_US (English).

Translating Sahana

You can access the translation interface by going to 'System Administration' → 'Language Translation'. Before doing the translation make sure you have selected the correct locale for your language. You can do that by going to 'System Administration' → 'Set Locale' and selecting the language from the select box.

The normal way of doing a translation would be,

  • Load the existing list

Should be loaded at the start. If not Click the 'Load Existing List' button.

  • Do the translation.

The translation is done by entering the translated string for the 'msgid' string in the 'msgstr'. e.g:

#: ../inc/lib_security/acl_action_form.inc:50
#: ../inc/lib_security/acl_action_form.inc:145
msgid "* Description:"
msgstr "* විස්තර:"
  • Save the translated list

After doing the translation save the translated list. Press the 'save' button to save the list (Make sure you have permission to res/locale/ directory and it's sub directories)

  • After saving the translated list you have to compile the translated PO file in to a MO file which is ultimately used in the localization of sahana. This can be done using the 'Compile Messages' button on the bottom right hand corner of the page.

Navigation
QR Code
QR Code dev:l10n (generated for current page)