babel
babel copied to clipboard
Allow multiple arguments for same keyword
xgettext allows to have different arguments for same keyword, whereas babel doesn't. This pull request fix it.
Example
some_file.py contents:
print _("Hello")
print _("Event", "Events", 5)
- output of
xgettext some_file.py --language=Python --output-dir=locale --keyword=_ --keyword=_:1,2:
#: some_file.py:1
msgid "Hello"
msgstr ""
#: some_file.py:2
msgid "Event"
msgid_plural "Events"
msgstr[0] ""
msgstr[1] ""
- output of
pybabel extract ./ --output=locale/messages.pot --keyword=_ --keyword=_:1,2
#: some_file.py:1
msgid "Hello"
msgstr ""
#: some_file.py:2
msgid "Event"
msgstr ""
As we can see, xgettext correctly found plural argument list for _("Event", "Events", 5). But babel treats function _ to have only one argument, ignoring option --keyword=_:1,2 and therefore assumes, that "Event" has no plural forms.
P.S.
In tornado web framework, function _ can take both the single string and a string with plural form and with count. I found it useful, as we don't need to have another translate function name for such case.
hey @st4lk can you rebase this? Should fix the tests.
Current coverage is 83.47%
Merging #140 into master will increase coverage by +0.09% as of
1f632c0
@@ master #140 diff @@
======================================
Files 22 22
Stmts 3756 3775 +19
Branches 0 0
Methods 0 0
======================================
+ Hit 3132 3151 +19
Partial 0 0
Missed 624 624
Review entire Coverage Diff as of
1f632c0Powered by Codecov. Updated on successful CI builds.
I've done the rebase now.