Translating internal strings: gettext


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin » Skin

Translating internal strings: gettextLast Modified: May 29, 2020, 8:05 pm
As of DirectAdmin 1.61.1, the binaries will support gettext, for better internationalized string translations.

The path for your language will be at:

/usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.po


DirectAdmin automatically convert the .po to the binary internal.mo version (and update when needed) upon the first load of the internal.po.
The auto-conversion requires the presence of

/usr/bin/msgfmt

so if you do not have it, install it with:

yum install gettext


Translate

  1. To create your internal.po, first take the default which should be found in:

    /usr/local/directadmin/data/lang/internal.pot

    and copy it to a temporary location for translation.
  2. The translation involves going through each msgid string, and swapping

    with the correct string for the new given language.

  3. Some msgids will have flag charcters such as %s and %d, which are used to place dynamic string/number into.  The number and order of these flags must remain intact, else the translation will not work.
  4. Some phrases can be singular or plural. These cases have "msgid_plural" below the msgid. The singular translation goes into msgstr[0] and the plural set beside msgstr[1].
  5. Once you have your translated internal.po file, save it to the path listed at the top of this guide.

Example

internal.pot:

#, c-format
msgid " and %d User"
msgid_plural " and %d Users"
msgstr[0] ""
msgstr[1] ""

Say you were to translate this into a french lang/fr/LC_MESSAGES/internal.po, the given result may look like:

#, c-format
msgid " and %d User"
msgid_plural " and %d Users"
msgstr[0] "et %d Utilisateur"
msgstr[1] "et %d Utilisateurs"

where DirectAdmin would internally swap the %d flag with a dynamic number that can change depending on the output.

Updates

With each new release of DirectAdmin, there are likely going to be new or changed translations.  To add the new translations to your .po file without losing your existing translations, use the command:

msgmerge --update /usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.po /usr/local/directadmin/data/lang/internal.pot



Debugging


  1. Check the language of the User fred:

    grep fr /usr/local/directadmin/data/users/fred/user.conf

  2. Ensure the internal.mo was created, as DA itself needs the .mo from the .po file:

    ls -la /usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.mo

    If it does not exist, convert it from the .po to see what's going on:

    /usr/bin/msgfmt /usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.mo -o /usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.po
    chown diradmin:diradmin /usr/local/directadmin/data/lang/fr/LC_MESSAGES/internal.mo

  3. Debugging the binaries

    Ensure that gettext is compiled in:

    cd /usr/local/directadmin
    ./directadmin o

    we want to see this in the output:

    gettext support: yes
    gettext path: /usr/local/directadmin/data/lang


    Beyond that, running DirectAdmin in debug mode exactly level 735 will yield information which can be sent to DirectAdmin support for investigation.
 
Related Helpfiles
Translating the Evolution skin

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST