使用Babel CLI提取器提取Javascript gettext消息 [英] Extracting Javascript gettext messages using Babel CLI extractor

查看:75
本文介绍了使用Babel CLI提取器提取Javascript gettext消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处表明Babel可以提取Python和Javascript的gettext消息文件。

It is stated here that Babel can extract gettext messages for Python and Javascript files.


Babel附带一些内置提取器:python(从Python源文件中提取
消息),javascript和忽略(
不提取任何东西)。

Babel comes with a few builtin extractors: python (which extracts messages from Python source files), javascript, and ignore (which extracts nothing).

命令行提取器记录在案这里 - 但没有使用示例。

The command line extractor is documented here - but with no examples on usage.

同样在上面的同一指针,提到了一个用于提取的配置文件但是没有太多扩展。

Also in the same pointer above, there is some mention of a config file to be used with extraction, but not much expanded on.

当我使用js文件在dir上运行提取器的基本命令时,我只获得了生成的.PO头但没有消息。

When I run the basic command for the extractor on a dir with js files, I get only the .PO header generated but no messages.

$ 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文件的示例段我正在尝试为以下内容提取消息:

Here is a sample segment from a js file I'm trying to extract messages for:

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]));
    }
}

如果有人能提供精确的CLI选项,我将不胜感激和配置设置以使提取工作,或指向这样的指针。

I would appreciate it if someone can provide exact CLI options and config settings to make the extraction work, or a pointer to such.

推荐答案

创建一个文件( babel.cfg )包含以下内容:

Create a file (babel.cfg) with the following content:

[javascript:*.js]
encoding = utf-8

然后,执行:

pybabel extract -F babel.cfg /path/to/js-dir

这应该足以让你有一些消息字符串。

That should be enough for you to have some message strings.

BTW,你可以参考提取的帮助执行命令:

BTW, you can consult the help for the extract command by doing:

pybabel extract --help

这篇关于使用Babel CLI提取器提取Javascript gettext消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆