当前位置: 首页>>代码示例>>Python>>正文


Python Translator.translate方法代码示例

本文整理汇总了Python中taal.Translator.translate方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.translate方法的具体用法?Python Translator.translate怎么用?Python Translator.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在taal.Translator的用法示例。


在下文中一共展示了Translator.translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invalid_override

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
 def test_invalid_override(self):
     translator = Translator(
         Translation,
         session=None,
         language=None,
     )
     with pytest.raises(ValueError) as exc:
         translator.translate(None, strategy='invalid ಠ_ಠ')
     assert 'Invalid strategy `invalid ಠ_ಠ`' in unicode(exc)
开发者ID:timbu,项目名称:taal,代码行数:11,代码来源:test_strategies.py

示例2: test_translate_structure

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_translate_structure(self, session):
        translation = Translation(
            context='context', message_id='message_id',
            language='language', value='translation')
        session.add(translation)
        session.commit()

        translator = Translator(Translation, session, 'language')
        translatable = TranslatableString(
            context='context', message_id='message_id')

        structure = {
            'int': 1,
            'str': 'str',
            'list': [1, 'str', translatable],
            'translatable': translatable,
        }

        translation = translator.translate(structure)
        assert translation == {
            'int': 1,
            'str': 'str',
            'list': [1, 'str', 'translation'],
            'translatable': 'translation',
        }
开发者ID:timbu,项目名称:taal,代码行数:27,代码来源:test_models.py

示例3: test_translate_missing

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_translate_missing(self, session):
        translator = Translator(Translation, session, 'language')
        translatable = TranslatableString(
            context='context', message_id='message_id')

        translation = translator.translate(translatable)
        translation is None
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:9,代码来源:test_models.py

示例4: test_none_value

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_none_value(self, session):
        translator = Translator(Translation, session, SAMPLE_LANGUAGE)
        translatable = TranslatableString(
            context=SAMPLE_CONTEXT, message_id=SAMPLE_MESSAGE_ID)

        translation = translator.translate(translatable)
        translation is None
开发者ID:onefinestay,项目名称:taal,代码行数:9,代码来源:test_strategies.py

示例5: test_translate_missing_debug

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_translate_missing_debug(self, session):
        translator = Translator(
            Translation, session, 'language', debug_output=True)
        translatable = TranslatableString(
            context='context', message_id='message_id')

        translation = translator.translate(translatable)
        assert "[Translation missing" in translation
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:10,代码来源:test_models.py

示例6: test_case_sensitivity

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_case_sensitivity(self, session):
        translation_lower = Translation(
            context='context', message_id='message_id',
            language='language', value='translation')
        translation_upper = Translation(
            context='CONTEXT', message_id='message_id',
            language='language', value='translation')
        session.add(translation_upper)
        session.add(translation_lower)
        session.commit()

        translator = Translator(Translation, session, 'language')
        translatable = TranslatableString(
            context='context', message_id='message_id')

        # this shuold just not raise
        translator.translate(translatable)
开发者ID:timbu,项目名称:taal,代码行数:19,代码来源:test_models.py

示例7: test_debug_value

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_debug_value(self, session):
        translator = Translator(
            Translation,
            session,
            SAMPLE_LANGUAGE,
            strategy=Translator.strategies.DEBUG_VALUE
        )
        translatable = TranslatableString(
            context=SAMPLE_CONTEXT, message_id=SAMPLE_MESSAGE_ID)

        translation = translator.translate(translatable)
        assert "[Translation missing" in translation
开发者ID:onefinestay,项目名称:taal,代码行数:14,代码来源:test_strategies.py

示例8: test_sentinel_value

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_sentinel_value(self, session):
        translator = Translator(
            Translation,
            session,
            SAMPLE_LANGUAGE,
            strategy=Translator.strategies.SENTINEL_VALUE
        )
        translatable = TranslatableString(
            context=SAMPLE_CONTEXT, message_id=SAMPLE_MESSAGE_ID)

        translation = translator.translate(translatable)
        assert translation is TRANSLATION_MISSING
开发者ID:onefinestay,项目名称:taal,代码行数:14,代码来源:test_strategies.py

示例9: test_translate

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_translate(self, session):
        translation = Translation(
            context='context', message_id='message_id',
            language='language', value='translation')
        session.add(translation)
        session.commit()

        translator = Translator(Translation, session, 'language')
        translatable = TranslatableString(
            context='context', message_id='message_id')

        translation = translator.translate(translatable)
        assert translation == 'translation'
开发者ID:timbu,项目名称:taal,代码行数:15,代码来源:test_models.py

示例10: test_save_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_save_translation(self, session, session_cls):
        translator = Translator(Translation, session, 'language')
        params = {
            'context': 'context',
            'message_id': 'message_id',
        }
        translatable = TranslatableString(
            pending_value='translation', **params)
        translator.save_translation(translatable)

        read_translatable = TranslatableString(**params)
        translation = translator.translate(read_translatable)
        assert translation == 'translation'
开发者ID:timbu,项目名称:taal,代码行数:15,代码来源:test_models.py

示例11: test_update_removed_values

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
def test_update_removed_values(
        session, bound_manager, change_instance_hierarchy):
    manager = bound_manager
    obj = change_instance_hierarchy

    retrieved = manager.deserialize(manager.serialize(obj))
    new = manager.change_instance_type(retrieved, 'New', {'old': 'new'})

    data = manager.serialize(new)
    translator = Translator(Translation, session, 'language')
    translated = translator.translate(data)

    assert translated['common'] == 'common'
    assert session.query(Translation).count() == 1
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:16,代码来源:test_change_instance.py

示例12: test_translating_class_labels

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
def test_translating_class_labels(session, translating_type_heirarchy,
                                  bound_manager):
    manager = bound_manager

    translator = Translator(Translation, session, 'en')
    translatable = TranslatableString(
        context=TYPE_CONTEXT,
        message_id='Entity', pending_value='English Entity')

    translator.save_translation(translatable)
    translator.bind(manager)

    hierarchy = manager.get_labeled_type_hierarchy()
    entity = next(hierarchy)

    translated = translator.translate(entity[1])
    assert translated == 'English Entity'
开发者ID:timbu,项目名称:taal,代码行数:19,代码来源:test_manager.py

示例13: test_get_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
def test_get_translation(session, manager):
    manager.save(CustomFieldsEntity)
    item = CustomFieldsEntity()
    manager.save(item)

    create_translation_for_entity(
        session, manager, 'english', item, 'name', 'English name')

    context = get_context(manager, item, 'name')
    message_id = get_message_id(manager, item)
    translatable = TranslatableString(
        context=context, message_id=message_id)

    translator = Translator(Translation, session, 'english')
    translated_data = translator.translate(translatable)

    assert translated_data == 'English name'
开发者ID:onefinestay,项目名称:taal,代码行数:19,代码来源:test_types.py

示例14: test_change_instance_type

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
def test_change_instance_type(
        bound_manager, session, change_instance_hierarchy):
    manager = bound_manager
    obj = change_instance_hierarchy

    assert session.query(Translation).count() == 2

    retrieved = manager.deserialize(manager.serialize(obj))
    new = manager.change_instance_type(retrieved, 'New')

    # make sure we reset our session
    session.rollback()

    data = manager.serialize(new)
    translator = Translator(Translation, session, 'language')
    translated = translator.translate(data)

    assert translated['common'] == 'common'
    assert session.query(Translation).count() == 1
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:21,代码来源:test_change_instance.py

示例15: test_update_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import translate [as 别名]
    def test_update_translation(self, session, session_cls):
        translator = Translator(Translation, session, 'language')
        params = {
            'context': 'context',
            'message_id': 'message_id',
        }
        translatable = TranslatableString(
            pending_value='translation', **params)
        translator.save_translation(translatable)

        new_translator = Translator(
            Translation, session_cls(), 'language')
        new_translatable = TranslatableString(
            pending_value='new translation', **params)
        new_translator.save_translation(new_translatable)

        read_translatable = TranslatableString(**params)
        translation = translator.translate(read_translatable)
        assert translation == 'new translation'
        assert session.query(Translation).count() == 1
开发者ID:timbu,项目名称:taal,代码行数:22,代码来源:test_models.py


注:本文中的taal.Translator.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。