Linux software information of Chinese language contains a number of steps as follows.
* Preparation:
Check your Linux platform whether to support the Chinese Locale/X Locale, if we do not support, they can be downloaded from the Internet.
* Setup locale:
Our program should import the string header file and define the macro translation:
# include "locale.h"
# include "libintl.h"
# define _ (String) gettext (String)
# define N_ (String) gettext (String)
# define __ (String) (String) to initialize locale,
Setlocale (LC_ALL, ""); or
Setlocale (LC_ALL, "zh_CN.EUC"); or
Setlocale (LC_ALL, "zh_TW.Big5");
The first line is setting an environment variable, LC_ALL, or special options LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES initialization. The other two directly set GB / GBK or Big5 as locale. For design flexibility, it is best to use the first approach.
* Specify location information:
extracts information specified by the directories and files
#Define PACKAGE "test" //this package name
#Define LOCALEDIR "/usr/share/locale"
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
* Designated information translation:
Specified in the software to translate the string, for example,
Printf ( "% s", _ ( "Chinese"));
Here the string "Chinese" has been designated from the locale file to extract information.
* Information Extraction:
Assumptions test.c procedures has been prepared, you can use the command
xgettext-a-o test.po test.c
The information extracted.
* Translation information:
Test.po information document contains the information to be translated:
Msgid "Chinese"
Msgstr ""
It can be translated into Chinese. If at the same time support GB/Big5, also translated into the two documents.
msgid "Chinese"
msgstr "中文"
* Formatting information:
The above-mentioned documents into test.po formatted documents can be used to extract test.mo:
Msgfmt-o test.mo test.po
* Installation information:
copy test.mo the above-mentioned documents to the definition of the locale directory
* Preparation:
Check your Linux platform whether to support the Chinese Locale/X Locale, if we do not support, they can be downloaded from the Internet.
* Setup locale:
Our program should import the string header file and define the macro translation:
# include "locale.h"
# include "libintl.h"
# define _ (String) gettext (String)
# define N_ (String) gettext (String)
# define __ (String) (String) to initialize locale,
Setlocale (LC_ALL, ""); or
Setlocale (LC_ALL, "zh_CN.EUC"); or
Setlocale (LC_ALL, "zh_TW.Big5");
The first line is setting an environment variable, LC_ALL, or special options LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES initialization. The other two directly set GB / GBK or Big5 as locale. For design flexibility, it is best to use the first approach.
* Specify location information:
extracts information specified by the directories and files
#Define PACKAGE "test" //this package name
#Define LOCALEDIR "/usr/share/locale"
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
* Designated information translation:
Specified in the software to translate the string, for example,
Printf ( "% s", _ ( "Chinese"));
Here the string "Chinese" has been designated from the locale file to extract information.
* Information Extraction:
Assumptions test.c procedures has been prepared, you can use the command
xgettext-a-o test.po test.c
The information extracted.
* Translation information:
Test.po information document contains the information to be translated:
Msgid "Chinese"
Msgstr ""
It can be translated into Chinese. If at the same time support GB/Big5, also translated into the two documents.
msgid "Chinese"
msgstr "中文"
* Formatting information:
The above-mentioned documents into test.po formatted documents can be used to extract test.mo:
Msgfmt-o test.mo test.po
* Installation information:
copy test.mo the above-mentioned documents to the definition of the locale directory