【问题标题】:Localizing timeAgoInWords in CakePHP在 CakePHP 中本地化 timeAgoInWords
【发布时间】:2026-01-28 18:45:02
【问题描述】:

在我的 CakePHP 应用程序中, 通过使用 cake.bat 我创建了 POT 文件并通过使用 PoEdit 我创建了 PO 文件。 因此,通过编写 __('myword') 我可以成功地在我的应用程序中看到本地化的单词。

但现在我需要本地化“timeAgoInWords”。 当我运行 cake i18n extract 时,脚本在 CakeTime 中没有得到 _dn() 字样 http://api20.cakephp.org/view_source/cake-time#line-522

所以我创建了一个 dummy.ctp 文件并将内容从 cake-time 文件复制粘贴到虚拟文件。 我再次运行蛋糕脚本和 POEdit。它在 app/Locale/tur/LC_MESSAGES/default.po

文件中创建了如下所示的实例
#: View\App\dummy.ctp:30;33
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] "%d dakika"
msgstr[1] "%d dakika"

在 core.php 中,我已经将默认语言设置为土耳其语:

Configure::write('Config.language', 'tur');

但是当我检查我的申请时,timeAgoInWords 的结果是英文的。

我该如何解决这个问题

【问题讨论】:

标签: cakephp localization internationalization cakephp-2.0 timeago


【解决方案1】:

Cake 的消息被提取到不同的域中,在本例中为cake 域。这意味着蛋糕消息不会被提取到您的default.pot 文件中,而是会进入cake.pot 文件中。

奇怪的是,cake.pot 似乎没有包含在下载中,i18n shell 也不允许您在提取过程中传递参数来包含蛋糕核心。但是,它仍然很容易完成(我的 cmets 以 # 开头):

$:/var/www/path/app$ cake i18n extract

# if will ask you here if you want to extract from your app folder
# simply press enter to confirm
What is the path you would like to extract?
[Q]uit [D]one  
[/var/www/path/app/]

# now it will ask you again, in this case enter the cake path
What is the path you would like to extract?
[Q]uit [D]one  
[D] > /var/www/path/lib/Cake

# third time, just press enter
What is the path you would like to extract?
[Q]uit [D]one  
[D] > 

# press enter to accept the app/Locale
What is the path you would like to output?
[Q]uit  
[/var/www/path/app//Locale] > 

# press enter to keep translation domains deparate
Would you like to merge all domains strings into the default.pot file? (y/n) 
[n] > 

现在等待提取完成,享受翻译的痛苦;)

【讨论】: