[英]how to generate po file from js file using poedit
i am using Gettext.js library to localize my contents generated from a JS file. 我正在使用Gettext.js库本地化我从JS文件生成的内容。 Now the situation is, i have to create and write each and every po files manually.
现在的情况是,我必须手动创建和编写每个po文件。 I know we can scan php files for gettext strings using PoEdit.
我知道我们可以使用PoEdit扫描php文件中的gettext字符串。 So, is it possible to scan JS files for gettext strings using PoEdit ?
那么,是否可以使用PoEdit扫描JS文件中的gettext字符串?
Achieved this by creating a new parser of python language in PoEdit. 通过在PoEdit中创建一个新的python语言解析器来实现这一目标。
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 . 从版本xgettext 0.18.3开始 ,您可以使用JavaScript作为语言参数 。
This version of xgettext is used in Poedit since at least version 1.6.2. 此版本的xgettext至少在版本1.6.2中用于Poedit。
The xgettext commandline program is used to scan source code and can parse the following languages: xgettext命令行程序用于扫描源代码,可以解析以下语言:
C, C++, ObjectiveC, Shell, Python, Lisp, EmacsLisp, librep, Scheme, Java, C#, awk, Tcl, Perl, PHP, GCC-source, Glade 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. 虽然JavaScript没有被列为语言,但我只是尝试了一些并且Perl实际上工作了。 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. 要从POEdit执行此操作,请打开
Preferences > Parsers > Perl
add ;*.js
.js到文件扩展名列表,并在Parser命令字段中的xgettext
之后添加--language=Perl
。 This worked for me and I was able to get new strings from a JS file this way. 这对我有用,我能够以这种方式从JS文件中获取新的字符串。
Although I don't know how gettext.js works a better approach may be to convert PO files to a native JavaScript file format . 虽然我不知道gettext.js如何工作,但更好的方法可能是将PO文件转换为本机JavaScript文件格式 。
xgettext
现在支持本机JavaScript,所以命令很简单:
xgettext --output=output.pot --language=JavaScript *.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.