dongsi0625
2009-09-12 19:05
浏览 38
已采纳

如何使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?

图片转代码服务由CSDN问答提供 功能建议

当你调用gettext php函数将文本翻译成另一种语言时,它会使用你在页面上的文字来 充当KEY / ID来查找值以替换它

  echo gettext('你好今天好吗'); 
    
 
 

这将是用于查找翻译的文本,但是我想使用类似这样的东西

  echo gettext('welcome_message'); \  n   
 
 

并将其翻译成英语和我提供的任何其他语言。 那怎么能让这件事发生呢? 如何使gettext函数始终使用语言文件? 因此,如果我的默认语言是网站的英语,那么它将显示你好,今天你好吗

除了创建其他语言文件之外,还是简单地创建英语语言文件吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumen5895 2009-09-12 20:44
    已采纳

    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.

    点赞 打赏 评论

相关推荐 更多相似问题