Variable arguments in translation functions

12 views
Skip to first unread message

Alex Grönholm

unread,
Apr 24, 2011, 12:32:09 PM4/24/11
to Python Babel
When attempting to define a "better" gettext function that would call
either ugettext or ungettext based on the number of arguments, I ran
into several problems. First of all, the syntax for specifying keyword
argument list lengths is undocumented. Browsing the Babel source, I
figured out that the syntax was _:x,y where x and y are indices that
tell which arguments contain the extractable strings. My second
problem, however, was the fact that extract() checks the number of
arguments and if it does not exactly match the specification, it would
drop the string from the first argument. This can be easily fixed by
removing line 293 from babel/messages/extract.py (v0.9.6), preventing
it from marking the entry as invalid. After this modification the
variable argument gettext function worked beautifully. Any chance that
this modification could be added to the main codebase?

Philip Jenvey

unread,
Apr 25, 2011, 12:46:13 AM4/25/11
to python...@googlegroups.com

I wonder if we should add a separate syntax for this kind of thing, like better_gettext:1,2? where 2 would be optional.

--
Philip Jenvey

Reply all
Reply to author
Forward
0 new messages