简体   繁体   English

php gettext()显示msgid而不是msgstr

[英]php gettext() showing up msgid instead of msgstr

Here is my messages.po file 这是我的messages.po文件

#

msgid "_greet1"
msgstr "Hello"

msgid "_greet2"
msgstr "Bye"

I get this po file compiled to mo file using PO Edit, and when I use the mo file inside translation code, I see msgid of the string instead of msgstr. 我使用PO Edit将这个po文件编译为mo文件,当我在翻译代码中使用mo文件时,看到的是字符串的msgid而不是msgstr。 I am using exactly same code written in PHP documentation for gettext. 我正在用完全相同的代码编写PHP文档中的gettext。

Any suggestions... 有什么建议么...

I had the same problem and my folder path was correct too. 我有同样的问题,我的文件夹路径也正确。 The reason of the issue was that I was using 'pl_PL' as locale instead of 'pl_PL.utf8' (in source code and as a folder name). 问题的原因是我使用'pl_PL'作为语言环境,而不是'pl_PL.utf8' (在源代码中和作为文件夹名称)。

Solution - remember about UTF-8: 解决方案-请记住有关UTF-8的信息:

  1. Check in console what locales you have and what are their real names: locale -a . 在控制台中检查您拥有哪些语言环境以及它们的真实名称: locale -a (In case there is no locale you are interested on you can type: sudo apt-get install locales-all ) (如果没有您感兴趣的语言环境,可以输入: sudo apt-get install locales-all

  2. Use correct locale name in your code, for instance: setlocale(LC_ALL, 'pl_PL.utf8'); 在代码中使用正确的语言环境名称,例如: setlocale(LC_ALL, 'pl_PL.utf8');

  3. Change your folder name. 更改您的文件夹名称。 Correct path to sample folder with *.mo and *.po file is: /var/www/project/locale/pl_PL.utf8/LC_MESSAGES 带有*.mo*.po文件的示例文件夹的正确路径是: /var/www/project/locale/pl_PL.utf8/LC_MESSAGES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM