Extraction with contextual markers in django

90 views
Skip to first unread message

luis.vi...@onefinestay.com

unread,
May 24, 2013, 10:00:32 AM5/24/13
to python...@googlegroups.com
Hi all,

I ran into a bit of a problem and if anyone could point me in the right direction, that would be great.

Recently I been working with pybable extract in one django project.
The project contains several apps, some of which already have been translated.
The literals where extracted using Babel 0.9.6 and BabelDjango 0.2.2.

Currently, two .pot in separate apps contain the same msgid, but they require different translations depending of the app/context

For this, django makes use of contextual markers in python files and templates.
You can find documentation for this feature here, but in templates it looks like this

{% trans "may" context "month name" %}
{% trans "may" context "to indicate possibility" %}

Babel should extract those string like this:

msgctxt "month name"
msgid "May"
msgstr ""

msgctxt "to indicate possibility" msgid "May" msgstr ""

This does not happen and the context marker is ignored, which is inconvenient.

Apparently, according to Philip Chimento, this is supported in changeset 623 in the SVN repo.
BabelDjango
After checking out both Babel and BabelDjango and updating to that revision, I installed them and tried again.
Everything seems to work ok up until the very end of the extraction, when I get the following error:

...
writing PO template file to myproject/onboarding/locale/django.pot
Traceback (most recent call last):
File "/home/lvisintini/.virtualenvs/devenv/bin/pybabel", line 9, in <module>
load_entry_point('Babel==1.0dev-r623', 'console_scripts', 'pybabel')()
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/frontend.py", line 1105, in main
return CommandLineInterface().run(sys.argv)
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/frontend.py", line 649, in run
return getattr(self, cmdname)(args[1:])
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/frontend.py", line 921, in extract
sort_by_file=options.sort_by_file)
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/pofile.py", line 429, in write_po
messages = list(catalog)
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/catalog.py", line 542, in __iter__
for name, value in self.mime_headers:
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/messages/catalog.py", line 325, in _get_mime_headers
locale='en')))
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/dates.py", line 502, in format_datetime
locale = Locale.parse(locale)
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/core.py", line 212, in parse
return cls(*parse_locale(identifier, sep=sep))
File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/core.py", line 137, in __init__
raise UnknownLocaleError(identifier)
babel.core.UnknownLocaleError: unknown locale 'en'

The .pot file is empty after this error occurs too.

Installation was successful, as far as I can tell (just a regular "python setup.py install" for both Babel and BabelDjango)

Did any of you get this problem before?

cheers,

Luis

Luc Saffre

unread,
May 24, 2013, 3:02:05 PM5/24/13
to python...@googlegroups.com, luis.vi...@onefinestay.com
On 24/05/13 17:00, luis.vi...@onefinestay.com wrote:
> File "/home/lvisintini/.virtualenvs/devenv/local/lib/python2.7/site-packages/Babel-1.0dev_r623-py2.7.egg/babel/core.py", line 137, in __init__
> raise UnknownLocaleError(identifier)
> babel.core.UnknownLocaleError: unknown locale 'en'

Just a quick shot feedback: did you import the locale data as explained
in http://babel.edgewall.org/wiki/SubversionCheckout

Luc


Reply all
Reply to author
Forward
0 new messages