def test_basic(self): app = Flask(__name__) Locale(app) with app.test_request_context(): assert translate('hello') == 'hello' assert translate('a', 'b', 1) == 'a' assert translate('a', 'b', 2) == 'b' assert translate('%s') % 'hi' == 'hi'
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')
def hello(): return translate('Hello')