Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybabel extract behaviour #439

Open
dmitriid opened this issue Aug 15, 2016 · 1 comment
Open

pybabel extract behaviour #439

dmitriid opened this issue Aug 15, 2016 · 1 comment

Comments

@dmitriid
Copy link

On the heels of #71 and #296 I decdied to document some of the oddities I ecnountered when using pybabel CLI.

This is the test dist/gettext.js file I'm using

var x = __("sing")
var z = __n("sing1", "plu1")
var y = __n("sing2", "plu2", 10)
var zzz = _("aaa")

1. pybabel extract ignores babel.cfg (docs are incorrect?)

According to docs, babel.cfg should look like this:

[javascript: **.js]
extract_messages = __

Run:

$ pybabel extract -F ./babel.cfg -o dist/lang/en.pot ./dist/gettext.js
extracting messages from ./dist/gettext.js (extract_messages="__")
writing PO template file to dist/lang/en.pot

It will only extract messages surrounded by _() (single underscore)

2. Ignores keywords in babel.cfg

Google + friends suggest that this is the correct babel.cfg:

[javascript: **.js]
keywords = __

Run:

$ pybabel extract -F ./babel.cfg -o dist/lang/en.pot ./dist/gettext.js
extracting messages from ./dist/gettext.js (keywords="__")
writing PO template file to dist/lang/en.pot

Result: only messages surrounded by _() are extracted (single underscore)

3. pybabel extract ignores -keywords parameter

Run $ pybabel extract --keywords=__ -o dist/lang/en.pot ./dist/gettext.js writing PO template file to dist/lang/en.pot

Result: no strings are extracted

4. pybabel extract requires babel.cfg even though it ignores its settings

Given the babel.cfg from above, run:

$ pybabel extract -F ./babel.cfg --keywords=__ -o dist/lang/en.pot ./dist/gettext.js
extracting messages from ./dist/gettext.js (keywords="__")
writing PO template file to dist/lang/en.pot

Result: strings are extracted for both _() and __()

5. pybabel extract requires babel.cfg even though it ignores its settings and complains about keywords not being set

Basically an extension of the above. Remove --keywords and add --no-default-keywords:

$ pybabel extract -F ./babel.cfg --no-default-keywords -o dist/lang/en.pot ./dist/gettext.js
Usage: pybabel extract [options] <input-paths>

pybabel: error: you must specify new keywords if you disable the default ones

Summary:

Please make one of the following:

  • make sure Babel CLI respects settings in babel.cfg, or
  • add a command-line parameter to babel extract to let it extract from .js files without the need for babel.cfg
@dimaqq
Copy link

dimaqq commented May 8, 2019

Also, pybabel attempts to extract from non-source files and crashes, e.g.:

extracting messages from project/subdir/._source_name.html.swp (extract_messages="gettext, ngettext, _", input_encoding="utf-8")
Traceback (most recent call last):
  ...
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 17-18: invalid continuation byte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants