本地化django项目的实用程序
django-i18n-utils的Python项目详细描述
数据处理
清除Unicode
utils.clean\u unicode接受输入字符串并返回 标准化Unicode
单异丙嗪混入< EH3>
模型混合类,确保每个文本字段已被处理 清除Unicode在模型验证的清除字段中步骤
测试
翻译安全测试客户端
djangotestclient子类,它在每次请求后重置活动翻译以避免泄漏 跨测试的转换状态,导致难以调试的副作用,如加载错误的fixture 使用django-modeltranslation的语言。
用法:
from django_i18n_utils.testclients import TranslationSafeTestClient class MyTestCase(TestCase): client_class = TranslationSafeTestClient def test_foo(self): # default language active self.client.get('/pt/myview') # Portuguese active when the view executes # default language active again
翻译安全案例
djangotestcase子类,它使用translationsafetestclient来避免以前的测试失败 使意外的区域设置处于活动状态的测试。
用法:
from django_i18n_utils.testcases import TranslationSafeTestCase class MyTestCase(TranslationSafeTestCase): …
局部测试用例
djangotestcase子类,使创建每种语言的测试变得容易 无重复或循环:
class MyLocalizedTests(LocalizedTestCase): def test_homepage(self): …
将执行并显示为您真正创建的:
class MyLocalizedTests(LocalizedTestCase): def test_homepage_en(self): … # test English def test_homepage_es(self): … # test Spanish