def slug(self): lang = get_locale() if lang == 'sv': return self.slug_sv if lang == 'en': return self.slug_en or self.slug_sv flask.abort(500)
def text(self): lang = get_locale() if lang == 'sv': return self.text_sv if lang == 'en': return self.text_en or self.text_sv flask.abort(500)
def title(self): lang = get_locale() if lang == 'sv': return self.title_sv if lang == 'en': return self.title_en or self.title_sv flask.abort(500)
def flash(self): lang = get_locale() if lang == 'sv': return self.flash_sv or self.flash_en if lang == 'en': return self.flash_en or self.flash_sv flask.abort(500)
def location(self): lang = get_locale() if lang == 'sv': return self.location_sv if lang == 'en': return self.location_en or self.location_sv flask.abort(500)
def setup_locale(app): from babel.dates import (format_date, format_datetime, format_time, get_timezone) from teknologkoren_se import locale app.jinja_env.globals['locale'] = locale app.jinja_env.globals['_'] = locale.get_string app.jinja_env.globals['url_for_lang'] = locale.url_for_lang cet = get_timezone('Europe/Stockholm') # locale.get_locale() requires an application context, we either # have to run get_locale() in the templates, or use lambdas here. app.jinja_env.globals['format_date'] = ( lambda d, f: format_date(d, f, locale=locale.get_locale())) app.jinja_env.globals['format_datetime'] = (lambda d, f: format_datetime( d, f, tzinfo=cet, locale=locale.get_locale())) app.jinja_env.globals['format_time'] = ( lambda d, f: format_time(d, f, tzinfo=cet, locale=locale.get_locale())) app.before_request(locale.fix_missing_lang_code)