简体   繁体   中英

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. 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. Does anybody have any idea? Thanks!

"I also had to force python in the gettext command":

  1. File|Preferences|Parsers
  2. Edit Python
  3. Edit "List of extensions..":
  4. *.py;*.js
  5. Edit "Parser commend:"
  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.

I also tested without success 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. 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

[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. 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. The gettext manual has all the gory details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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