babel icon indicating copy to clipboard operation
babel copied to clipboard

Allow multiple arguments for same keyword

Open st4lk opened this issue 10 years ago • 3 comments
trafficstars

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.

st4lk avatar Jan 26 '15 07:01 st4lk

hey @st4lk can you rebase this? Should fix the tests.

sils avatar Aug 05 '15 15:08 sils

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 1f632c0

Powered by Codecov. Updated on successful CI builds.

codecov-io avatar Dec 04 '15 22:12 codecov-io

I've done the rebase now.

st4lk avatar Dec 04 '15 23:12 st4lk