translate .js files using gettext
Asked Answered
D

4

5

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!

Domicile answered 28/1, 2010 at 5:13 Comment(0)
A
9

"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 :)

Aide answered 18/2, 2010 at 5:30 Comment(0)
G
4

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 comment which contains a single quote (unterminated string error).

Greenockite answered 4/5, 2011 at 14:25 Comment(1)
I've tried your solution and warnings were not showed. But some translations were not found in js files (for Python version they were found)... So I prefer Python version, even with warnings... :(Falconet
H
0

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.

Handstand answered 28/1, 2010 at 5:18 Comment(1)
I was able to figure out the problem I was having. The thing is that when making changes to the language I had to rescan all the files with Poedit. So I had to first add the correct paths for that project and then I had to use Python's parser for *.js files. I also had to force python in the gettext command otherwise Poedit will complain that .js files are not understood and will try to use C/C++ to parse them.Domicile
R
0

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 :)

Raine answered 15/10, 2013 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.