开发者

How to enable i18n from within setup_app in websetup.py ? (formatted resend)

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 ?


Apologies, I'm not familiar with i18n together with Pylons...

That said, you need to track down what 'path' is, and what its relative to. The error is because path is expected to be a string, but instead is set to None... causing the exception because the code is attempting a string operation 'path.endswith()' but path is None.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜