如何获取以 UTF-8 编码的 cakePHP i18n .pot 文件?
我正在使用 cake i18n 命令来提取我的 __( )
在我的应用程序中运行。 但是,default.pot 输出文件未采用 UTF-8 编码,因此无法正确显示重音字符,这是一个问题,因为主要语言是法语(大量 'é' 、 'à' ...)。
我在 Windows 7 上使用 wamp 服务器。
我尝试使用 chcp 更改 Windows 控制台的编码,使用 notepad++ 或 PSpad 编辑器将 default.pot 文件转换为 UTF-8,但没有成功。
您知道以 UTF-8 格式获取此 default.pot 文件的方法吗?
所有 .php 或 .ctp 文件均在 Windows 上使用 Komodo 或 Geany 进行编辑,并配置为使用 UTF-8 。 我也在使用 subversion,如果有帮助的话。
感谢您的阅读。
I'm using the cake i18n command to extract the content of my __()
functions in my application.
However, the default.pot output file is not encoded in UTF-8, and thus does not correctly display accentuated characters which is a problem since the main language is french (lot of 'é' , 'à' ...).
I'm using wamp server on Windows 7.
I've tried to change Windows console's encoding with chcp, to convert default.pot file in UTF-8 with notepad++ or PSpad editor, without success.
Do you know any way to get this default.pot file in UTF-8 ?
All the .php or .ctp files are edited with either Komodo or Geany, both on Windows and configured to use UTF-8.
Also i'm using subversion, if it helps.
Thank you for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cakephp 1.3 也有同样的问题(不确定是否在 2.x 中修复):所有不符合 ANSI 标准的“特殊”字符(例如 ä、ü、ö、ß),在 .pot 文件中提取并由 ANSI 解释(例如,“μ”而不是“ü”)。
卡米尔提到的解决方案(手动更改字符)不太可行,因为它有很多字符,这部分破坏了 .pot 格式,更糟糕的是,.po 文件的自动更新将无法工作。
我找到的解决方法是借助 php 文档中 write() 的注释(在控制台任务中使用): http://www.php.net/manual/en/function.fwrite.php#73764。
根据那里的描述,我用两行扩展了文件 /cake/console/libs/tasks/extract.php:
第一行进入函数 __buildFiles():
我在第 351 行编写了它,但它只需要在第二个 foreach 循环,当然是在函数使用变量之前。
第二行进入函数 __writeHeader():
替换行 $File->write($output);这
对我来说是这样,请注意更新你的 cakephp 将覆盖此更改。
Had the same problem with cakephp 1.3 (not sure if it is fixed in 2.x): all "special" character which are not ANSI compliant (such as ä, ü, ö, ß), where extracted in the .pot file and there interpreted by ANSI (e.g. "ü" instead of "ü").
The solution mentioned by Camille (manually changing the characters) was not very feasable, since it was a lot of characters, this partly destroyed the .pot format and even worse an automated update of your .po file won't work.
The workaround I found was with the help of a comment in the php documentation for write() (which is used in the console task): http://www.php.net/manual/en/function.fwrite.php#73764.
According to the description there, I extended the file /cake/console/libs/tasks/extract.php with two lines:
First line went into the function __buildFiles():
I wrote it in line 351, but it just needs to be in the second foreach loop and of couse before the variable is used by the function.
the second line went into the function __writeHeader():
replace the line $File->write($output); with
That did it for me, take care the updating your cakephp will overwrite this changes.
感谢@Msalters,我找到了解决这个问题的方法。我更改了编辑器的默认编码并覆盖了错误的字符。
I found a way to deal with this thanks to @Msalters. I changed the default encoding of my editor and overwrote wrong characters.