这里说明Babel 可以为 Python 和 Javascript 文件提取 gettext 消息。
Babel 带有一些内置的提取器:python(从 Python 源文件中提取消息)、javascript 和 ignore(不提取任何内容)。
此处记录了命令行提取器- 但没有使用示例。
同样在上面的同一个指针中,提到了一个用于提取的配置文件,但没有太多扩展。
当我在带有 js 文件的目录上运行提取器的基本命令时,我只生成了 .PO 标头,但没有消息。
$ pybabel extract /path/to/js-dir
# Translations template for PROJECT.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-04-22 19:39+1000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
$
这是我试图提取消息的 js 文件中的示例片段:
else if(data.status == "1"){
var follow_html = gettext('Follow');
object.attr("class", 'button follow');
object.html(follow_html);
var fav = getFavoriteNumber();
fav.removeClass("my-favorite-number");
if(data.count === 0){
data.count = '';
fav.text('');
}else{
var fmts = ngettext('%s follower', '%s followers', data.count);
fav.text(interpolate(fmts, [data.count]));
}
}
I would appreciate it if someone can provide exact CLI options and config settings to make the extraction work, or a pointer to such.