What is bindtextdomain, textdomain in gettext?

[亡魂溺海] 提交于 2019-12-05 07:30:51

You can readily swap between textdomains whenever you like. e.g:

Given

./locale/en/LC_MESSAGES/template.po 

with the contents

msgid "foo"
msgstr "foobar"

and

./locale/en/LC_MESSAGES/messages.po

with the contents

msgid "Basic test"
msgstr "A basic test"

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";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!