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


Python Translator.save_translation方法代码示例

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


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

示例1: test_basic

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [as 别名]
def test_basic(session_cls):
    session_en = session_cls()
    translator_en = Translator(Translation, session_cls(), 'en')
    translator_en.bind(session_en)

    session_fr = session_cls()
    translator_fr = Translator(Translation, session_cls(), 'fr')
    translator_fr.bind(session_fr)

    model = Model(name='name')
    session_en.add(model)
    session_en.commit()

    # translate into fr
    translatable = model.name
    translatable.pending_value = 'namë_fr'
    translator_fr.save_translation(translatable)

    new_model = Model(name='name')
    session_en.add(new_model)
    session_en.commit()

    suggestion = translator_fr.suggest_translation(
        new_model.name, from_language='en', to_language='fr')

    assert suggestion == 'namë_fr'
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:28,代码来源:test_suggestions.py

示例2: test_dont_save_debug_translation

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

        translatable = TranslatableString(
            context='context', message_id='message_id')
        debug_value = translator._get_debug_translation(translatable)
        translatable.pending_value = debug_value

        translator.save_translation(translatable)

        assert session.query(Translation).count() == 0
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:14,代码来源:test_models.py

示例3: test_save_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [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

示例4: test_dont_save_debug_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [as 别名]
    def test_dont_save_debug_translation(self, session):
        translator = Translator(
            Translation,
            session,
            SAMPLE_LANGUAGE,
            strategy=Translator.strategies.DEBUG_VALUE
        )

        translatable = TranslatableString(
            context=SAMPLE_CONTEXT, message_id=SAMPLE_MESSAGE_ID)
        debug_value = translator._get_debug_translation(translatable)
        translatable.pending_value = debug_value

        translator.save_translation(translatable)

        assert session.query(Translation).count() == 0
开发者ID:onefinestay,项目名称:taal,代码行数:18,代码来源:test_strategies.py

示例5: test_translating_class_labels

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [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

示例6: test_update_translation

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [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

示例7: test_save_empty

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import save_translation [as 别名]
def test_save_empty(session):
    translatable = TranslatableString()
    translator = Translator(Translation, session, 'language')
    with pytest.raises(RuntimeError):
        translator.save_translation(translatable)
开发者ID:timbu,项目名称:taal,代码行数:7,代码来源:test_sqlalchemy.py


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