问题描述
我已经学习了一些gettext,但是我无法掌握这两个功能.我一直想知道我是否可以在用PHP编写的APP中使用多种翻译.例如,我有1)系统翻译2)扩展翻译3)主题翻译,可以将它们分成不同的文件.我的问题是,如果我加载系统翻译,然后加载主题翻译,第一个会是未设置"吗?
I've been learning a bit of gettext but I can't grasp those two functions. I've been wondering if I could use multiple translations in a APP written in PHP. For an instance, I've 1) the system translation 2) extensions translations 3) theme translations to divide those in different files. My question is, if I load the system translation, then load the theme translation will the first one be "unset"?
我非常感谢与gettext和php相关的任何链接.
I'd appreciate any links related to gettext and php.
谢谢
推荐答案
您随时可以在文本域之间轻松切换.例如:
You can readily swap between textdomains whenever you like. e.g:
给出
./locale/en/LC_MESSAGES/template.po
带有内容
msgid "foo"
msgstr "foobar"
和
./locale/en/LC_MESSAGES/messages.po
带有内容
msgid "Basic test"
msgstr "A basic test"
您可以使用类似以下PHP代码的内容从一个文本域切换到另一个文本域,然后再返回:
You could use something like the following PHP code to switch from one textdomain to the other, and then back:
<?php
setlocale(LC_ALL, 'en_US.UTF-8');
bindtextdomain ("messages", "./locale");
bindtextdomain ("template", "./locale");
textdomain ("messages");
echo gettext("Basic test"), "\n";
textdomain ("template");
echo _("foo"), "\n";
textdomain ("messages");
echo gettext("Basic test"), "\n";
这篇关于什么是bindtextdomain,gettext中的textdomain?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!