GTK 中多国语言

 

1. In source code
#include<gtk/gtk.h>
#include<libintl.h>
#define _(STRING) gettext(STRING)
#define PACKAGE "record_zh"   //will build record_zh.mo
#define LOCALEDIR "./mo"     

int main(int argc, char *argv[])
{
    ...
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);
    bind_textdomain_codeset(PACKAGE, "UTF-8");
   
    gtk_init(&argc, &argv);
    ...
}

2. Build po file
#xgettext -k_ -o ui_pref.pot *.c *.h
#cp ui_pref.pot zh_CN.po
#vim zh_CN.po
change the zh_CN.po file head "charset=CHARSET" to "charset=UTF-8"
Change capital string part in head if you need.
translate msgid and write then in msgstr
eg, in zh_CN.po:
...
#callback.c:67
msgid "Delete record failure/n"
msgstr "删除纪录失败/n"
...

3. Make .mo file
#msgfmt -o record_zh.mo zh_CN.po

4. Copy .mo to right directly
#mkdir -p mo/zh_CN/LC_MESSAGES
#cp record_zh.mo mo/zh_CN/LC_MESSAGES

You also can copy .mo to /usr/share/locale/zh_CN/LC_MESSAGES/
then your main file need remove lines

#define LOCALEDIR "./mo"

bindtextdomain(PACKAGE, LOCALEDIR);

5. Do test
#export LANG=zh_CN.UTF-8
run your program


When you run your program, if show below information

Gtk-WARNING **: Locale not supported by c library
        Using the fallback 'C' locale

You can use "locale -a" check the language
#vim /var/lib/locales/supported.d/local
Add "zh_CN.UTF-8 UTF-8"
The other support language you can see /usr/share/i18n/SUPPORTED

#sudo locale-gen
Then you can see a zh_CN.utf8 in /usr/lib/locale/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值