First of all i18n is shorthand for internationalisation,The same reasoning is behind l10n.The standard translation support on linux is "gettext".It consists of a translations database stored inthe filesystem, utilities to manage the databaseand an API (which comes with glibc) to access it.Database:
The translations database is stored in seperate files like:
$dirname/$locale/$category/$domain.mo
an example of the variables being:
#language_COUNTRY
category=LC_MESSAGES
#strings in your app
bindtextdomain("fslint","/usr/share/locale");
setlocale(LC_ALL,""); /* set all locale categories to value in LC_ALL or LANG environment variables */
/* note gettext uses LC_MESSAGES category */
textdomain("fslint");
Python:
gettext.bindtextdomain("fslint", "/usr/share/locale") #sys default used if localedir=None
locale.setlocale(locale.LC_ALL,'')
gettext.textdomain("fslint")
#Note if you initially do the following, it is much
#faster as lookup for mo file not done for each translation
#Note also before python 2.3 you need the following if
#you need translations from non python code (glibc,libglade etc.)
print item, ":",
gettext._translations['/usr/share/locale/es/LC_MESSAGES/libc.mo']._catalog[item]
To actually call the gettext translation functions
just replace your strings "string" with gettext("string")
The following shortcuts are usually used:
Python:
_ = gettext.gettext #Don't do if used gettext.install above (more inefficient)
print _("translated string")
C:
#define _(x) gettext(x)
printf(_("translated string"));Utilities:
The next thing to do is extract the marked strings from your
source files for translation and insertion into the database. Python used to
have its own utility (pygettext.py) to do this, but the best way
now is to use the standard xgettext utility which now supports python.
The output from this stage is a pot file.
The last thing left to is actually do the translations.
Translators create a "po" file from the pot file above,
by just entering the text for the source strings in the pot file.
Then the developer compiles these to binary mo files for
use by the application. msgfmt and msgmerge are the main
utilities for manipulating po, pot and mo files.
The quickest way to learn about the external utilities
(xgettext, msgmerge, msgfmt) is to look at existing examples,
which are usually in po/Makefile in various projects, including: FSlintCharsets:
Translators can represent your strings in various ways.
扫码下方或搜索关注公众号“卫星参数网”,独家内幕新闻!