如何使gettext始终使用翻译而不是默认语言文本
When you call the gettext php function for translating text to another language, it uses the text you have on the page to act as the KEY/ID to lookup the value to replace it with
echo gettext('hello how are you today');
that would be the text used to lookup the translation, however I would like to use something like this
echo gettext('welcome_message');
and have that translated into English and any other language I offer. So how could I make this happen? How can I make gettext function ALWAYS use a language file? So if my default language is English for the site then instead of gettext showing welcome_message to an English user it would show hello how are you today
Is it as simple as just creating an English language file in addition to the other language files?
当你调用gettext php函数将文本翻译成另一种语言时,它会使用你在页面上的文字来 充当KEY / ID来查找值以替换它 p>
echo gettext('你好今天好吗');
code> pre>
这将是用于查找翻译的文本,但是我想使用类似这样的东西 p>
echo gettext('welcome_message'); \ n code> pre>
并将其翻译成英语和我提供的任何其他语言。 那怎么能让这件事发生呢? 如何使gettext函数始终使用语言文件? 因此,如果我的默认语言是网站的英语,那么它将显示你好,今天你好吗 strong> p>
除了创建其他语言文件之外,还是简单地创建英语语言文件吗? p>
div>
You're on the right track. The string argument to gettext() is just an identifier, not a "default language". If there is no translation in the active locale, then gettext will return that identifier.
Your solution is just what you suspect: just create an English translation file.