Gettext
In computing, gettext is an internationalization and localization (i18n and l10n) system commonly used for writing multilingual programs on Unix-like computer operating systems. One of the main benefits of gettext is that it separates programming from translating.[4] The most commonly used implementation of gettext is GNU gettext,[5] released by the GNU Project in 1995. The runtime library is libintl. gettext provides an option to use different strings for any number of plural forms of nouns, but this feature has no support for grammatical gender. The main filename extensions used by this system are .POT (Portable Object Template), .PO (Portable Object) and .MO (Machine Object).[6] HistoryInitially, POSIX provided no means of localizing messages. Two proposals were raised in the late 1980s, the 1988 Uniforum gettext and the 1989 X/Open catgets (XPG-3 § 5). Sun Microsystems implemented the first gettext in 1993.[1] The Unix and POSIX developers never really agreed on what kind of interface to use (the other option is the X/Open catgets), so many C libraries, including glibc, implemented both.[7] As of August 2019[update], whether gettext should be part of POSIX was still a point of debate in the Austin Group, despite the fact that its old foe has already fallen out of use. Concerns cited included its dependence on the system-set locale (a global variable subject to multithreading problems) and its support for newer C-language extensions involving wide strings.[8] The GNU Project decided that the message-as-key approach of gettext is simpler and more friendly. (Most other systems, including catgets, requires the developer to come up with "key" names for every string.)[9] They released GNU gettext, a free software implementation of the system in 1995.[2] Gettext, GNU or not, has since been ported to many programming languages.[10] The simplicity of po and widespread editor support even lead to its adoption in non-program contexts for text documents or as an intermediate between other localization formats, with converters like po4a (po for anything) and Translate Toolkit emerging to provide such a bridge.[11][12] OperationProgrammingThe basic interface of gettext is the printf(gettext("My name is %s.\n"), my_name);
printf(_("My name is %s.\n"), my_name); // same, but shorter
For example, an input file with a comment might look like: /// TRANSLATORS: %s contains the user's name as specified in Preferences
printf(_("My name is %s.\n"), my_name);
xgettext -c / The resultant .pot file looks like this with the comment (note that xgettext recognizes the string as a C-language printf format string): #. TRANSLATORS: %s contains the user's name as specified in Preferences
#, c-format
#: src/name.c:36
msgid "My name is %s.\n"
msgstr ""
In POSIX shell script, gettext provides a TranslatingThe translator derives a msginit—locale=fr—input=name.pot This will create #: src/name.c:36
msgid "My name is %s.\n"
msgstr "Je m'appelle %s.\n"
Finally, the .po files are compiled with GNU In later phases of the developmental workflow, RunningThe user, on Unix-type systems, sets the environment variable Users on GNU variants can also use the environment variable Plural formThe // parameters: english singular, english plural, integer count
printf(ngettext("%d translated message", "%d translated messages", n), n);
A header in the msgid ""
msgstr ""
"..."
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);\n"
Since now there are four plural forms, the final po would look like: #: src/msgfmt.c:876
#, c-format
msgid "%d translated message"
msgid_plural "%d translated messages"
msgstr[0] "%d prevedenih sporočil"
msgstr[1] "%d prevedeno sporočilo"
msgstr[2] "%d prevedeni sporočili"
msgstr[3] "%d prevedena sporočila"
Reference plural rules for languages are provided by the Unicode consortium.[22] msginit also prefills the appropriate rule when creating a file for one specific language.[18] ImplementationsIn addition to C, gettext has the following implementations: C# for both ASP.NET[23][24] and for WPF,[25] Perl,[26] PHP,[27] Python,[28] R,[29] Scala,[30] and Node.js.[31] GNU gettext has native support for Objective-C, but there is no support for the Swift programming language yet. A commonly used gettext implementation on these Cocoa platforms is POLocalizedString.[32] The Microsoft Outlook for iOS team also provides a LocalizedStringsKit library with a gettext-like API.[33] See alsoWikimedia Commons has media related to GNU gettext. References
External links |