def test_translate(self): app = Flask(__name__) app.config['DEFAULT_LOCALE'] = 'zh_CN' Locale(app) with app.test_request_context(): assert translate('I love you') == to_unicode('我爱你')
def test_custom_locale_selector(self): app = Flask(__name__) l = Locale(app) the_locale = 'zh_CN' @l.localeselector def select_locale(): return the_locale with app.test_request_context(): assert translate('I love you') == to_unicode('我爱你') the_locale = 'en' with app.test_request_context(): assert translate('I love you') == 'I love you' the_locale = 'es_LA' with app.test_request_context(): assert translate('I love you') == to_unicode('Te amo')