xgettext只能用于提取特定的域字符串吗? [英] Can xgettext be used to extract specific domain strings only?

查看:84
本文介绍了xgettext只能用于提取特定的域字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(真的很惊讶,网上的任何地方都没有回答这个问题;在过去的几年中,有几次类似问题的帖子,但从未回答过.我们希望Stackoverflow的工作人员能够进行救援)

情况:

使用gettext支持应用程序本地化时,有时希望使用dgettext('domain','some text string')指定一个域".但是,在运行 xgettext 时,所有用dgettext(...)包装的字符串都吐到一个文件中(默认值:messages.po).

给出以下示例:

dgettext('menus', 'login link');
dgettext('menus', 'account link');
dgettext('footer', 'copyright notice');
dgettext('footer', 'contact form');

有什么方法可以结束

menus.po
footer.po

使用诸如xgettext之类的提取器?

需要PHP响应,尽管我认为这应该适用于所有语言

解决方案

我发现做到这一点的唯一方法是重新定义gettext函数...

示例:

function _menus ($str) {
    return dgettext('menus', $str);
}

function _footer ($_str) {
    return dgettext('footer', $str);
}

_menus('login link');
_menus('account link');
_footer('copyright notice');
_footer('contact form');

否则,您只需要运行以下命令:

xgettext [usual options] -k --keyword=_menus:1 -d menus
xgettext [usual options] -k --keyword=_footer:1 -d footer

再见!

(Really surprised this isn't answered anywhere online; couple posts over the past few years with a similar question, but never answered. Let's hope the Stackoverflow crew can come to the rescue)

Situation:

When using gettext to support application localization, one sometimes wishes to specify a 'domain' with dgettext('domain', 'some text string'). However, when running xgettext, all strings wrapped with dgettext(...) are spit out into one file (default: messages.po).

Given the following example:

dgettext('menus', 'login link');
dgettext('menus', 'account link');
dgettext('footer', 'copyright notice');
dgettext('footer', 'contact form');

is there any way to end up with

menus.po
footer.po

using an extractor such as xgettext?

PHP response desired, although I believe this should be applicable across all languages

解决方案

The only way I've found to do this is to redefine gettext functions...

example:

function _menus ($str) {
    return dgettext('menus', $str);
}

function _footer ($_str) {
    return dgettext('footer', $str);
}

_menus('login link');
_menus('account link');
_footer('copyright notice');
_footer('contact form');

else, you only have to run following commands:

xgettext [usual options] -k --keyword=_menus:1 -d menus
xgettext [usual options] -k --keyword=_footer:1 -d footer

Bye!

这篇关于xgettext只能用于提取特定的域字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆