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

Allow multiple arguments for same keyword #140

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@st4lk
Copy link

st4lk commented Jan 26, 2015

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.

@sils

This comment has been minimized.

Copy link
Member

sils commented Aug 5, 2015

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

@st4lk st4lk force-pushed the st4lk:multi_keywords branch from d87d53f to 97a1677 Dec 4, 2015

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Dec 4, 2015

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.

@st4lk

This comment has been minimized.

Copy link
Author

st4lk commented Dec 4, 2015

I've done the rebase now.

@@ -29,15 +29,15 @@
GROUP_NAME = 'babel.extractors'

DEFAULT_KEYWORDS = {

This comment has been minimized.

@akx

akx Dec 20, 2015

Member

Changing the format of the keywords dict should be documented.

In addition, it's a backward-incompatible change for client apps that pass keywords as code, so it should probably support the old format as well as the new one.

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