最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - translate .js files using gettext - Stack Overflow

programmeradmin5浏览0评论

I found this cool js gettext library -> / 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 found this cool js gettext library -> http://code.google./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!

Share Improve this question asked Jan 28, 2010 at 5:13 KentorKentor 6571 gold badge11 silver badges27 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 9

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

  1. File|Preferences|Parsers
  2. Edit Python
  3. Edit "List of extensions..":
  4. *.py;*.js
  5. Edit "Parser mend:"
  6. xgettext --language=Python --force-po -o %o %C %K %F

Done.

Thanks for leading me there Kentor :)

I think xgettext --language=perl --force-po -o %o %C %K %F (using perl rather than python) shall be a better options, as python cause problem with javascript ment which contains a single quote (unterminated string error).

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.

I initially tried with both configurations, Python & Perl but with some plex 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./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 :)

发布评论

评论列表(0)

  1. 暂无评论