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

javascript - how to generate po file from js file using poedit - Stack Overflow

programmeradmin1浏览0评论

i am using Gettext.js library to localize my contents generated from a JS file. Now the situation is, i have to create and write each and every po files manually. I know we can scan php files for gettext strings using PoEdit. So, is it possible to scan JS files for gettext strings using PoEdit?

i am using Gettext.js library to localize my contents generated from a JS file. Now the situation is, i have to create and write each and every po files manually. I know we can scan php files for gettext strings using PoEdit. So, is it possible to scan JS files for gettext strings using PoEdit?

Share Improve this question asked May 15, 2013 at 5:11 Prasanth K CPrasanth K C 7,3326 gold badges42 silver badges63 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 9

Achieved this by creating a new parser of python language in PoEdit.

File > Preferences > Parsers > New

Language:

JS

List of extension:

*.js

Parser command:

xgettext --language=Python --force-po -o %o %C %K %F

Item in Keyword List:

-k%k

Item in input files list:

%f

Source code charset:

--from-code=%c

i found this tutorial while searching on this, which helped me to attain the situation Tutorial Here>>

Actually the tutorial is in French and the link is a google translated(to English) one.

Since version xgettext 0.18.3, you can use JavaScript as the language parameter.

This version of xgettext is used in Poedit since at least version 1.6.2.

xgettext now supports JavaScript natively, so the command is simply:

xgettext --output=output.pot --language=JavaScript *.js

The xgettext commandline program is used to scan source code and can parse the following languages:

C, C++, ObjectiveC, Shell, Python, Lisp, EmacsLisp, librep, Scheme, Java, C#, awk, Tcl, Perl, PHP, GCC-source, Glade

Although JavaScript is not listed as a language, I just tried it with a few and Perl actually worked. Try this:

echo " testFunc('foo');" > test.js;
xgettext --keyword=testFunc --output=- test.js --language="perl";

To do this from POEdit, open Preferences > Parsers > Perl add ;*.js to the file extensions list and add --language=Perl after xgettext in the Parser command field. This worked for me and I was able to get new strings from a JS file this way.

Although I don't know how gettext.js works a better approach may be to convert PO files to a native JavaScript file format.

发布评论

评论列表(0)

  1. 暂无评论