CakePHP缺少复数形式的语言环境翻译

时间:2014-04-17 18:02:26

标签: php cakephp localization gettext cakephp-2.4

我使用CakePHP 2.4.6。

我从github repository获取语言环境文件(cake.po) 我的视图文件中有这样的代码:

$myStr = $this->Time->timeAgoInWords($mTimestamp, array('end' => '+10 year'));

我在下面粘贴了错误。您可以从this link找到所有错误。

Warning: Warning (512): Missing plural form translation for "%d year" in "cake"
     domain, "fra" locale.
Check your po file for correct plurals and valid Plural-Forms header.
     in [/var/www/vhosts/example.com/httpdocs/lib/Cake/I18n/I18n.php, line 210]
Trace:
I18n::translate() - CORE/Cake/I18n/I18n.php, line 210
__dn - CORE/Cake/basics.php, line 644
CakeTime::timeAgoInWords() - CORE/Cake/Utility/CakeTime.php, line 884
TimeHelper::timeAgoInWords() - CORE/Cake/View/Helper/TimeHelper.php, line 417
include - APP/View/Mytool/index.ctp, line 42
View::_evaluate() - CORE/Cake/View/View.php, line 935
View::_render() - CORE/Cake/View/View.php, line 897
View::render() - CORE/Cake/View/View.php, line 466
Controller::render() - CORE/Cake/Controller/Controller.php, line 952
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 192
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 160
[main] - APP/webroot/index.php, line 111

对于cake.po文件的第194-197行,存在%d year like this的翻译。

我还从cake.po目录中删除了法语/app/tmp/cache/persistent缓存文件。

虽然我在法语cake.po文件中有翻译但为什么会出现此错误?
请注意,我还添加了other languages' cake.po文件 并且他们不会给出任何错误。

1 个答案:

答案 0 :(得分:2)

fra cake.po文件中的Plural-Forms有问题。

变化:

"Plural-Forms: nplurals=2; plural=(n==1? 0 : 1);\n"

为:

"Plural-Forms: nplurals=2; plural=(n > 1);\n"

它应该有用。

我已经测试过了:

echo sprintf(__dn('cake', '%d year', '%d years',2),2);