问题标签 [php-gettext]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1155 浏览

php - PHP gettext 不起作用

阿帕奇 2.4 + PHP 5.5

我绝对确定,比mydomain.pomydomain.mo/absolute/path/to/messages/ru_RU/LC_MESSAGES/.
我还把这些文件给了我在 OS X Maverics 上的同事 - 工作得很好。
我不能让 php gettext 工作。

我已经在 Google/stackoverflow 上搜索了大约几个小时,尝试了各种解决方案 - 仍然无法正常工作。我做错了什么?

每次更改某些内容以确保重新加载 gettext 文件时,我都会重新启动 apache。

这是我的locale -a输出:

另一个 cmd 输出:

好吧,我想通了:

sudo locale-gen ru_RU(添加了新的语言环境,但不同的字符集)然后setlocale(LC_ALL, 'ru_RU.UTF-8');完成了所有工作。

感谢帮助。

0 投票
4 回答
752 浏览

php - Yii: GetText _() vs Yii::t()

在 Yii 中使用 GetText 翻译字符串时,我们必须使用Yii::t($category,'message')gettext 的_('message')语法吗?

然后我们如何将字符串拉入 PO 文件?

0 投票
0 回答
83 浏览

php - Strange functioning of gettext

I have a very strange situation with gettext.

I configured an Apache server on a Windows Server 2008. I installed the default XAMPP distribution and tweaked a few settings. The site is running fine all in all but the situation is the following:

  • I have the php_gettext.dll enabled in php.ini
  • I checked if the locale files are correctly located and they are, the site reads them correctly. I used these functions and got the following outputs:

input: var_dump(file_exists('./locale/language_code/LC_MESSAGES/file.mo'));

output: bool(true)

input: var_dump(fileperms('./locale/language_code/LC_MESSAGES/file.mo'));

output: int(33204)

  • The default language is Spanish, but for some reason the site loads the English locale by default ignoring either the Spanish or the Portuguese locales. The parameters are correctly passed through .htaccess. That tells me that the gettext is working but just with English. It has 3 languages and 2 locales. Default Spanish, and English and Portuguese locale files.

I tested the same configuration on HostGator hosting and the site worked fine. The difference is the HostGator hosting is Linux and the client's server has Windows. An OS change is not an option. The problems with the language started when we uploaded the site to the client server.

I tried exec("locale -a",$output); but for some reason $output is an empty array. I am thinking the encoding might be the issue, I'll try changing it but in the meantime this is the code I use for the locale:

Any idea what might the reason be?

0 投票
1 回答
209 浏览

php - PHP:本地化包含变量的字符串

到目前为止,我用 本地化字符串没有问题gettext,除非字符串包含变量。我按照这个优秀教程中的步骤进行操作,但是每当我尝试将此功能应用于此功能时,我都会遇到麻烦。

我的字符串messages.po看起来像这样:

不幸的是,这些字符串没有被翻译,而所有其他字符串(没有变量)都可以正常工作。我在这里做错了什么?

0 投票
1 回答
1140 浏览

php - php gettext 翻译在 Debian 上不起作用

(我看过其他问题,但他们的回答 我没有帮助)

我有一个使用 php gettext 进行翻译的应用程序,并且多年来一直在 OSX 和 FreeBSD 上工作。当我尝试将它移植到 Debian 7.6 32bit ( Linux debian32bit 3.2.0-4-686-pae #1 SMP Debian 3.2.60-1+deb7u3 i686 GNU/Linux) 时,一切正常,除了翻译。我将问题归结为 CLI 单行代码:

locale/nl/LC_MESSAGES/foo.mo包含 的荷兰语翻译low,即。laag

在 OSX Maverick 上:

在 FreeBSD 10 64 位上:

但是,在 Debian 7 上:

php-gettext 已安装:

locale -a给出:

所以我尝试了 nl_NL.utf8 而不是 nl_NL.UTF-8:同样的结果。

我尝试将foo.mo文件放在 下locale/nl_NL/LC_MESSAGES,结果相同。

我尝试使用绝对路径locale代替当前工作目录的相对路径,结果相同。

我在这里不知所措。关于如何进行的任何建议?

0 投票
0 回答
184 浏览

php - 内置网络服务器的 php 是否支持 gettext?

我正在 Ubuntu 14.04 上运行的 Apache 上尝试这个,它工作正常:

但是当我在内置网络服务器的 PHP 上尝试它时,我只得到英文版本,这是这两者之间的唯一区别。内置网络服务器的 php 是否支持 gettext?有什么办法绕过它?

感谢帮助!

0 投票
2 回答
433 浏览

php - 如何翻译包含多个复数的字符串?

我想翻译一个列出文件夹内容的脚本。包含文件、文件夹和显示的总大小的摘要。到目前为止,我使用 翻译了所有字符串gettext,但我被困在这里并寻找一种优雅的方法来解决翻译可能包含多个复数的字符串。可能不用说,但由于每种语言都不同,我想避免连接字符串。

可能的状态(0-cases 被有意遗漏):

  • 1 个文件夹和 1 个文件,共 100 KB
  • 1 个文件夹和 2 个文件,共 200 KB
  • 2 个文件夹和 1 个文件,共 100 KB
  • 2 个文件夹和 2 个文件,共 200 KB

我认为ngettext()这将是 的适当替代品_(),但将其与我的示例结合起来让我无法理解。

0 投票
2 回答
1207 浏览

php - 无法使用 gettext php 函数翻译成任何其他语言

我在 Windows 上使用 WAMP 服务器并制作了一个测试项目。我在网站文件夹中有这些文件:

C:\wamp\www\project\locale\ar_EG\LC_MESSAGES\messages.po C:\wamp\www\project\locale\en_US\LC_MESSAGES\messages.po

下面是PHP代码:

上面的代码工作正常。当我尝试en_USar_EG它替换时,也会显示翻译en_US,当我尝试删除en_US文件夹并重试时,它会显示msgidnot msgstr

我搜索了一下,发现是setlocale在windows平台上有问题,但是我需要一个解决方案让它在windows上运行。

0 投票
1 回答
918 浏览

php - php ngettext 多个变量

手册中复制示例,ngettext 的工作方式如下:

但是,例如,如果我想使用 2 个变量%d windows %d doors怎么办?是否有标准的方法来实现这一点,以便根据 2 个变量出现正确的字符串(4 种组合)?

0 投票
0 回答
321 浏览

php - PHP 版本令人困惑 - Gettext 不适用于 PHPStorm

我有一个繁琐的设置,最终在 Mac OSX Yosemite 上使用了多个版本的 PHP,现在它变得令人困惑。因此,我设法让 gettext 使用 PHP 进行本地化,并且它适用于 Apache。但是现在当我安装 PHPStorm 时,我得到:

调用未定义的函数 bindtextdomain()

表示不支持 gettext。我知道 php.ini 也告诉这没有启用,事实上,当我使用 apache 运行同一个文件然后使用 PHPStorm 的内置服务器时,会有不同的 phpinfo() 输出。

有没有办法能够知道 apache 当前正在使用哪个 PHP 并使用 PHPStorm 复制确切的功能?我希望它能让调试更快,但设置却让我卡住了。