wichert / lingua

Translation toolkit for Python
Other
45 stars 32 forks source link

pgettext does not work from babel plugins #71

Closed ztane closed 8 years ago

ztane commented 8 years ago

I am using babel-javascript which readily scans pgettext, and correctly if I use it with pybabel/setup.py extract_messages. However if used via pot-create, the pgettext contents are interpreted as if they were ngettext.

pgettext('Task', 'Type') in a .js file and processed with babel-javascript should result in

msgctxt "Task"
msgid "Type"
msgstr ""

But currently results in

msgid "Task"
msgid_plural "Type"
msgstr[0] ""
msgstr[1] ""
wichert commented 8 years ago

Can you provide a small example that shows this problem, so I have something to test with?

ztane commented 8 years ago

You just need pgettext('Context', 'The real msgid') in a javascript file, then use babel-javascript to extract messages from that file. Babel 2.0.

ztane commented 8 years ago
% cat lingua.cfg
[extensions]
.js = babel-javascript
% cat foo.js
pgettext('Context', 'The real msgid')
% pot-create -c lingua.cfg .
ztane commented 8 years ago

You can also verify this by python source, by trying pybabel vs babel-python on the pgettext (could not make pybabel extract javascript correctly on command-line, but setup.py extract_messages works).

wichert commented 8 years ago

I've pushed a set of changes that should fix this. Can you check if babel plugins work correctly for you now?

ztane commented 8 years ago

Thanks, both python and javascript seem to be working (npgettext does not work but it seems it is not supported by Babel)

wichert commented 8 years ago

npgettext is not in the default keyword list for either, but you can just register that as an extra keyword to look for.

I have released lingua 4.4 with the fix for this issue.