Po2c is a software tool for translation of language files, making use of Perl scripts. It accepts gettext files in the argument of its command line for translation purposes. The software tool is designed to simplify translation between languages.
The C source code file generated includes the original and translated messages as a group of static, NULL terminated pointer-to-string arrays alongside the following two C functions – po2c_setlang(char * lang) and po2c_gettext(char * msgid). The po2c_setlang() function is used to set the user's desired language by reading it either from the user or from any of the LANG, LC_ALL and LC_MESSAGES environment variables. The processed .po files' names must match those language strings.
On the other hand, the po2c_gettext() function is a convenient tool that works orthogonally to the original gettext() function. The msgid is the character string to translate and it returns the translated string if found, or the same msgid otherwise.
Suppose a user has a directory named po that includes two files – po/es.po and po/fr.po. The former includes translations in Spanish while the latter includes translations in French. Thus, running the following command: po2c po/*.po > lang.c, results in creating the lang.c C source file.
The generated lang.c C source file is entirely static, and the binary only needs to link against the C library. It includes the original and translated messages as a group of static, NULL terminated pointer-to-string arrays alongside the necessary functions.
To use the generated C source code file, a user only needs to compile and link it against their code. There, they'll add the function prototypes and use them seamlessly.
The only requirement to use po2c is the use of Perl. It is a small yet useful script that is flexible and can be quickly integrated into various software projects.
Version 1.0.2: N/A