简体   繁体   English

使用gettext翻译.js文件

[英]translate .js files using gettext

I found this cool js gettext library -> http://code.google.com/p/gettext-js/ but I don't understand how to implement it. 我找到了这个很酷的js gettext库 - > http://code.google.com/p/gettext-js/但我不明白如何实现它。 I am using poedit to edit the translations and I can see that it works when I checkout the project and run the demo file but when I make changes to the text, the .po files don't get updated and I can't see the new text. 我正在使用poedit来编辑翻译,我可以看到它在我签出项目并运行演示文件时有效,但是当我对文本进行更改时,.po文件不会更新,我看不到新文本。 Does anybody have any idea? 有人有什么想法吗? Thanks! 谢谢!

"I also had to force python in the gettext command": “我还必须在gettext命令中强制使用python”:

  1. File|Preferences|Parsers 文件|偏好|解析器
  2. Edit Python 编辑Python
  3. Edit "List of extensions..": 编辑“扩展名列表”:
  4. *.py;*.js
  5. Edit "Parser commend:" 编辑“Parser表示:”
  6. xgettext --language=Python --force-po -o %o %C %K %F

Done. 完成。

Thanks for leading me there Kentor :) 谢谢你带领我到肯特尔:)

我认为xgettext --language = perl --force-po -o%o%C%K%F(使用perl而不是python)应该是更好的选择,因为python导致javascript注释包含单引号的问题(未终结字符串错误)。

I initially tried with both configurations, Python & Perl but with some complex underscore templates, nested quotes and double quotes, escaped characters etc. both parsers reported loads of false obsolete strings so I cannot update the .pot or .po files properly from source code. 我最初尝试使用Python和Perl两种配置,但是使用了一些复杂的下划线模板,嵌套引号和双引号,转义字符等。两个解析器报告了大量错误的过时字符串,因此我无法从源代码中正确更新.pot或.po文件。

I also tested without success http://code.google.com/p/gettext-js/ 我也测试没有成功http://code.google.com/p/gettext-js/

After a lot of trial & error I discovered I can use chaining parsing and it worked fine on poedit 1.5.7. 经过大量的试验和错误,我发现我可以使用链接解析,它在poedit 1.5.7上运行良好。 These are the configuration parameters that should be enabled at the same time for the best matching 这些是应该同时启用的配置参数,以实现最佳匹配

Extracted from Library/Preferences/net.poedit.Poedit.cfg of the Mac version, you can simply copy and paste on your dialog otherwise 从Mac版本的Library / Preferences / net.poedit.Poedit.cfg中提取,您可以简单地复制并粘贴到您的对话框上

[Parsers/js] 
Extensions=*.js;*.html 
Command=xgettext --language=Python --force-po -o %o %C %K %F 
KeywordItem=-k%k 
FileItem=%f 
CharsetItem=--from-code=%c 

[Parsers/PHP] 
Extensions=*.php;*.js;*.html 
Command=xgettext --language=PHP --force-po -o %o %C %K %F 
KeywordItem=-k%k 
FileItem=%f 
CharsetItem=--from-code=%c 

Notice that you may don't need to include *.html on your extensions, I did it to parse my underscore templates. 请注意,您可能不需要在扩展名中包含* .html,我这样做是为了解析我的下划线模板。 Hope it helps cause it was really frustrating for me :) 希望它有助于使我真的很沮丧:)

You must invoke xgettext in order to extract the strings into a .pot file, and then run msgmerge to update the .po files. 您必须调用xgettext才能将字符串解压缩到.pot文件中,然后运行msgmerge来更新.po文件。 The gettext manual has all the gory details. gettext手册包含所有血腥细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM