How to enable i18n from within setup_app in websetup.py ?
Posted
by daniel
on Stack Overflow
See other posts from Stack Overflow
or by daniel
Published on 2010-05-09T17:04:49Z
Indexed on
2010/05/09
17:08 UTC
Read the original article
Hit count: 330
From within the setup_app function (websetup.py) of a pylons i18n application, which is making use of a db, I was trying to initiate multilingual content to be inserted into the db.
To do so the idea was something like:
necessary imports here
def setup_app(command, conf, vars):
....
for lang in langs:
set_lang(lang)
content=model.Content()
content.content=_('content')
Session.add(content)
Session.commit()
Unfortunately it seems that it doesn't work. the set_lang code line is firing an exception as follows:
File ".. i18n/translation.py", line 179, in set_lang translator = _get_translator(lang, **kwargs) File ".. i18n/translation.py", line 160, in _get_translator localedir = os.path.join(rootdir, 'i18n') File ".. /posixpath.py", line 67, in join elif path == '' or path.endswith('/'): AttributeError: 'NoneType' object has no attribute 'endswith'
Actually I'm even not sure it could be possible launching i18n mechanisms from within this setup_app function without an active request object.
Anyone has tried some trick on a similar story ?
© Stack Overflow or respective owner