【问题标题】:CakePHP missing locale translation for plural formCakePHP 缺少复数形式的语言环境翻译
【发布时间】:2014-04-17 18:02:26
【问题描述】:

我使用的是 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 的翻译。

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

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

【问题讨论】:

    标签: php cakephp localization gettext cakephp-2.4


    【解决方案1】:

    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);
    

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      相关资源
      最近更新 更多