Beispiel #1
0
def _set_context_locale():
    ctx = _request_ctx_stack.top
    if ctx is None:
        return None
    if not current_user.is_anonymous:
        locale = current_user.locale
    else:
        accepts = current_app.config.get('BABEL_ACCEPT_LANGUAGE')
        locale = request.accept_languages.best_match(accepts)
    if locale is None:
        locale = current_app.config.get('BABEL_DEFAULT_LOCALE')
    ctx.babel_locale = locale
    # load customized translations
    ctx.babel_translations = get_translations(locale)
Beispiel #2
0
 def _(string, **variables):
     t = get_translations(get_locale(), domain=domain)
     if t is None:
         return string % variables
     return t.ugettext(string) % variables