python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 433 forks source link

No Template Literals support for .js files. #997

Closed wolkodlack closed 9 months ago

wolkodlack commented 1 year ago

Overview Description

No Template Literals support for .js files.

Steps to Reproduce

  1. Update babel.cfg

    [javascript: **/static/**.js]
    encoding = utf-8
    extract_messages=_,gettext,ngettext
  2. Create test.js with Template Literal e.g.

    let hmtl = `<h3>${gettext("Some string to translate")}</h3>`;
  3. Execute extractor pybabel extract -F config/babel.cfg -o messages.pot .

Actual Results

No translate entries added to the messages.pot

Expected Results

It would be good to find expected entries.

msgid "Some string to translate"
msgstr ""

Reproducibility

Additional Information

Could be workarounded by adding same call outside of Template Literal _("Some string to translate");

Is it possible to fix this case? Thank you.

oomsveta commented 1 year ago

Hello, I just ran into the same problem! I solved it by calling the extract function with the parse_template_string option set to True. I also had to update the version of the library as it doesn't seem to be supported until version 2.12.0.

akx commented 9 months ago

Yep – this was added pretty recently and needs opt-in; see above :)