wichert / lingua

Translation toolkit for Python
Other
46 stars 32 forks source link

improper .pot file generated? #46

Closed tisdall closed 10 years ago

tisdall commented 10 years ago

pot-create generates the following from _('Logout ${login}', mapping={'login':request.user.login})

#: ./mainserver/templates/menu.mako:70
#, python-format
msgid "Logout ${login}"
msgid_plural "login"
msgstr ""

msginit then chokes on that with the message: "mainserver.pot:172:10: syntax error" (172 is the "msgstr" line above)

I'm not sure if this is a lingua or Babel issue, but it seems like it's incorrectly detecting the translation string as plural and then generating some .pot content that's not proper syntax. If I change line 172 to msgstr[0] "" the syntax error goes away, but obviously it's still not what I wanted.

wichert commented 10 years ago

Which extractor are you using? I can't replicate that output with lingua's python extractor:

$ mkdir tst
$ cat <<EOF > tst/x.py
_('Logout ${login}', mapping={'login':request.user.login})
EOF
$ pot-create tst
$ sed -ne '/^$/,$p' messages.pot 

#: ./tst/x.py:1
#, python-format
msgid "Logout ${login}"

Could it be that you are trying to use Babel's Python extractor? That does not know how to handle the translationstring or zope.i18nmessageid format and is likely to incorrectly detect plural strings.

tisdall commented 10 years ago

Sorry, I thought I should edit the post, but I was hoping you'd see the .mako in the comments. It's using the babel-mako parser. The tag in mako is simply ${_('Logout ${login}', mapping={'login':request.user.login})}.

tisdall commented 10 years ago

I just tried a .mako file with only ${_('Logout ${login}', mapping={'login':'login'})} in it and it had the same result.

wichert commented 10 years ago

Ah, I'm afraid there is little I can do about that: that is the Babel mako plugin using the Babel python plugin to handle any Python code it finds in mako files. The available options I see are:

If @zzzeek is willing to accept a change for Mako to add a lingua extractor I'm willing to create that.

tisdall commented 10 years ago

ah.. I thought Babel didn't do plural, though... It seems odd that it's improperly seeing string replacement as a plural thing.

Is there another way I can do string replacement without triggering it into thinking it's a "plural" translation? In that example I just want it to say "Logout [USERNAME]" where the username isn't translated.

wichert commented 10 years ago

I suspect Babel has a pretty simple concept of plural: any extra parameter for _(...) is treated as a plural msgid. I can't think of a good way to handle this sanely through the Babel plugin. However: I just asked zzzeek and he is willing to accept a patch for Mako to add native lingua support. I'll try to get that in this week.