Source

# -*- coding: utf-8 -*-"""ryshcate.locale===============Tools for localizing languages and dates/times.:copyright: 2010 Matthew "LeafStorm" Frazier:license: MIT/X11, see LICENSE for details"""fromflaskimportsessionfromflaskext.babelimport(Babel,format_date,format_time,format_datetime,gettext,_)frompytzimportcommon_timezonesfromspeaklaterimportmake_lazy_stringTRANSLATED_LANGUAGES=[('en',u'English')]deflazy_gettext(string,**variables):""" Like :func:`gettext` but the string returned is lazy which means it will be translated when it is used as an actual string. Example:: hello = lazy_gettext(u'Hello World') @app.route('/') def index(): return unicode(hello) """returnmake_lazy_string(gettext,string,**variables)__=lazy_gettextdefget_user_locale():returnsession.get('locale')defget_user_timezone():returnsession.get('timezone')defsetup_babel(app):babel_inst=Babel(app)babel_inst.localeselector(get_user_locale)babel_inst.timezoneselector(get_user_timezone)