C 的寫法在網路上比較找得到資料,可參考一下底下的連結:
http://www.study-area.net/tips/chinese_programming.html

我就不多做說明,直接舉簡單的例子:

原始檔
代碼:

/* hello_c.c */
#include
#define _(STRING) STRING
int main(int argc, char *argv[])
{
printf(_("hello!\n"));
return 0;
}

改成:
代碼:

/* hello_c.c */
#include
#include
#include
#define _(STRING) gettext(STRING)
#define PROGRAM_NAME "hello_c"
#define TEXTDOMAIN_DIR "/usr/local/locale"
int main(int argc, char *argv[])
{
setlocale(LC_MESSAGES,"");
bindtextdomain(PROGRAM_NAME,TEXTDOMAIN_DIR);
textdomain(PROGRAM_NAME);
printf(_("hello!\n"));
return 0;
}


編執行檔
代碼:
gcc -o hello_c hello_c.c


編po檔
代碼:
xgettext -k_ hello_c.c -o hello_c.po

再翻譯po檔
代碼:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR , YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2004-06-10 15:26+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=Big5\n"
"Content-Transfer-Encoding: 8bit\n"

#: hello_c.c:12
#, c-format
msgid "hello!\n"
msgstr "您好!\n"


再來產生.mo檔,並copy到相關目錄
代碼:

msgfmt -o hello_c.mo hello.po
cp hello_c.mo /usr/local/locale/zh_TW/LC_MESSAGES/


原址:http://phorum.study-area.org/printview.php?t=24020&start=0&sid=811534c1712860f4cf1c9dbcf153ac27

台南小新 發表在 痞客邦 PIXNET 留言(0) 人氣()