在Cakephp 2中,我使用这个repo进行cake.po翻译。但似乎没有为Cakephp 3更新它。所以我按照here运行了i18n shell并创建了cake.pot
文件。然后我做了一些翻译并将cake.po
个文件添加到文件夹src\Locale\
中。
当msgstr部分为空时,timeAgoInWords
显示英文单词,如果找到翻译,则cakephp显示翻译版本。
但这对阿拉伯语言不起作用。其他语言效果很好。
在cakephp 3中制作timeAgoInWords
时这样:
$string = $this->Time->timeAgoInWords(1338659672, array('end' => '+10 year'));
我收到此错误:Error: [Aura\Intl\Exception\CannotInstantiateFormatter] msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR
错误堆栈:
Error: [Aura\Intl\Exception\CannotInstantiateFormatter] msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR
Request URL: /ar/tools/
Stack Trace:
#0 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/I18n/Formatter/IcuFormatter.php(71): Cake\I18n\Formatter\IcuFormatter->_formatMessage('ar', NULL, Array)
#1 /var/www/vhosts/example.com/httpdocs/app/vendor/aura/intl/src/Aura/Intl/Translator.php(142): Cake\I18n\Formatter\IcuFormatter->format('ar', Array, Array)
#2 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/I18n/functions.php(110): Aura\Intl\Translator->translate('{0} years', Array)
#3 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/I18n/Time.php(384): __dn('cake', '{0} year', '{0} years', 3, 3)
#4 /var/www/vhosts/example.com/httpdocs/app/src/Template/Tools/index.ctp(62): Cake\I18n\Time->timeAgoInWords(Array)
#5 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/View/View.php(833): include('/var/www/vhosts...')
#6 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/View/View.php(793): Cake\View\View->_evaluate('/var/www/vhosts...', Array)
#7 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/View/View.php(464): Cake\View\View->_render('/var/www/vhosts...')
#8 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/Controller/Controller.php(582): Cake\View\View->render(NULL, NULL)
#9 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(120): Cake\Controller\Controller->render()
#10 /var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(87): Cake\Routing\Dispatcher->_invoke(Object(App\Controller\ToolsController))
#11 /var/www/vhosts/example.com/httpdocs/app/webroot/index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#12 {main}
Notice: Notice (8): Undefined offset: 3 in [/var/www/vhosts/example.com/httpdocs/app/vendor/cakephp/cakephp/src/I18n/Formatter/IcuFormatter.php, line 68]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 138
Cake\I18n\Formatter\IcuFormatter::format() - CORE/src/I18n/Formatter/IcuFormatter.php, line 68
Aura\Intl\Translator::translate() - ROOT/vendor/aura/intl/src/Aura/Intl/Translator.php, line 142
__dn - CORE/src/I18n/functions.php, line 110
Cake\I18n\Time::timeAgoInWords() - CORE/src/I18n/Time.php, line 384
include - APP/Template/Tools/index.ctp, line 62
Cake\View\View::_evaluate() - CORE/src/View/View.php, line 833
Cake\View\View::_render() - CORE/src/View/View.php, line 793
Cake\View\View::render() - CORE/src/View/View.php, line 464
Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 582
Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 120
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87
[main] - ROOT/webroot/index.php, line 37
编辑:俄语的错误非常类似。当我删除src\Locale\ru\cake.po
文件时,我再次获得U_ILLEGAL_ARGUMENT_ERROR
。请注意,俄语有3种复数形式,而英语和其他语言有2种复数形式。
答案 0 :(得分:0)
我和俄罗斯cake.po有同样的错误。由我翻译。当我从https://github.com/cakephp/localized/blob/master/src/Locale/ru/cake.po得到它时它工作正常。