我的问题是我无法将日期从英语翻译成俄语。 我遵循了这些指南:
我在 AppController.php 中写了这段代码:
function beforeFilter() {
parent::beforeFilter();
setlocale(LC_ALL, "ru_RU.utf8");
Configure::write('Config.language', 'rus');
CakeSession::write('Config.language', 'rus');
}
我添加了一个文件夹“Locale\rus\LC_MESSAGES”并将其放入文件 default.po 中。 顺便说一句,我将所有消息提取到单个文件中。
但实际上:
<?php echo $this->Time->timeAgoInWords($feedback['Feedback']['created']); ?>
什么也没做。
<?php echo __d('default', $this->Time->timeAgoInWords($feedback['Feedback']['created']), true); ?>
仅将字符串 'just now' 翻译成俄语,但其他时间格式仍为英语。 default.po 的翻译示例如下:
成功
#: Lib\Cake\Utility\CakeTime.php:842
#: Utility\CakeTime.php:842
msgid "just now"
msgstr "translate"
失败
#: Lib\Cake\Utility\CakeTime.php:829
#: Utility\CakeTime.php:829
msgid "%d week"
msgid_plural "%d weeks"
msgstr[0] "%d translate"
msgstr[1] "%d translate"
我不明白我做错了什么。
最佳答案
要翻译 Lib\Cake\Utility 文件夹中的 CakePHP 核心字符串,您需要使用不同的翻译域。您的 View 的默认域是“default”,但对于 CakePHP 核心字符串,它是“cake”。
您需要提供“cake.po”而不是“default.po”。否则您的翻译将无效。
关于CakePHP 2 : Localization&Internalization for function timeAgoInWords(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13662495/