库文件的国际化

动态库的国际化要使用
 
 
  1. #define _(String) dgettext(GETTEXT_PACKAGE, String)

代替
  1. #define _(String) gettext(String)




Special requirement for libraries

If you are writing a library, almost everything written previously applies as with a standalone application. The only problem that arises is that a library will never really know what message domain is currently active when it is processing a string and you usually want to have the library's own domain active at that point. The simplest solution to this problem is to change one of the defintions in the i18n header file mentioned in the Section 2.1, “The i18n header file” section. Find the line that says

#define _(String) gettext(String)

and change it to read

#define _(String) dgettext(GETTEXT_PACKAGE, String)

In this way, all strings that pass through the _() function will be translated in the domain of the library all the time.

One other situation that arises very rarely may be worth knowing about. In libgnomeui, for example, there are functions that operate on arbitrary arrays of strings (menu items, in this case). Some of those strings are standard and have been translated in the library itself. Others will have been supplied by the client application and translated in that domain. So libgnomeui defines the following function and convenience macro.

Example 2. Code from libgnomeui/gnome-app-helper.c

#define L_(x) gnome_app_helper_gettext (x)

const gchar *
gnome_app_helper_gettext (const gchar *str)
{
char *s;

s = gettext (str);
if ( s == str )
s = dgettext (GETTEXT_PACKAGE, str);

return s;
}

Strings marked with L_() are thereby translated in the currently active domain if possible and the library's domain otherwise. You may wish to duplicate this code if you have similar circumstances.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值