在CakePHP中本地化timeAgoInWords [英] Localizing timeAgoInWords in CakePHP

查看:244
本文介绍了在CakePHP中本地化timeAgoInWords的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my CakePHP application, By using cake.bat i created POT files and by using PoEdit I created PO files. So by writing __('myword') i can see localized word in my application successfully.

但现在我需要本地化timeAgoInWords。
当我运行 cake i18n extract 时,脚本没有在 CakeTime 中获取 _dn() href =http://api20.cakephp.org/view_source/cake-time#line-522> http://api20.cakephp.org/view_source/cake-time#line-522

But now I need to localize "timeAgoInWords". When i run cake i18n extract, script didn't get the _dn() words in CakeTime http://api20.cakephp.org/view_source/cake-time#line-522

所以我创建了一个 dummy.ctp 文件,并将从蛋糕时文件复制粘贴的内容复制到虚拟文件。
我再次运行蛋糕脚本和POEdit。并将以下实例创建到文件 app / Locale / tur / LC_MESSAGES / default.po 中。

So i created a dummy.ctp file and copy-pasted contents from cake-time file to dummy file. I run cake script and POEdit again. And it created instances like below, into the file 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中,语言到土耳其语:

In core.php i already set default language to Turkish:

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

但是当我检查我的应用程序时, timeAgoInWords 的结果是英语。

But when i check my application, results of timeAgoInWords came in English.

如何解决这个问题

推荐答案

Cake的讯息一个不同的域,在这种情况下, cake 域。这意味着蛋糕消息不会被提取到你的 default.pot 文件,但会进入 cake.pot 文件。

Cake's messages are extracted into a different domain, in this case, the cake domain. This means that cake messages will not be extracted into your default.pot file, but will go into cake.pot file.

奇怪的是,cake.pot似乎没有包含在下载中,i18n shell也不允许你通过一个参数来包含提取的蛋糕核心。但是,它仍然很容易完成(我的意见从开始):

Curiously, cake.pot doesn't seem to be included in the download, nor does the i18n shell allow you to pass a param to include the cake core during extraction. However, it is still easily done (my comments start with a #):

$:/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] > 

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

Now wait for the extraction to finish and enjoy the pain of translating ;)

这篇关于在CakePHP中本地化timeAgoInWords的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆