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


Python Translator.bind方法代码示例

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


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

示例1: test_basic

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

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
    def test_delete_on_delete(self, session, session_cls):
        session1 = session_cls()
        translator1 = Translator(Translation, session_cls(), 'language1')
        translator1.bind(session1)

        session2 = session_cls()
        translator2 = Translator(Translation, session_cls(), 'language2')
        translator2.bind(session2)

        instance = Model(id=1)
        session.add(instance)
        session.commit()

        instance = session1.query(Model).get(1)
        instance.name = 'name'
        session1.commit()

        instance = session2.query(Model).get(1)
        instance.name = 'name'
        session2.commit()

        assert translator1.session.query(Translation).count() == 2
        session2.delete(instance)
        assert translator1.session.query(Translation).count() == 2
        session2.commit()

        translator1.session.rollback()  # expire caches
        assert translator1.session.query(Translation).count() == 0
开发者ID:timbu,项目名称:taal,代码行数:30,代码来源:test_sqlalchemy.py

示例3: test_use_most_frequent

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

    def add_with_translation(en, fr):
        model = Model(name=en)
        session_en.add(model)
        session_en.commit()

        # translate into fr
        translatable = model.name
        translatable.pending_value = fr
        translator_fr.save_translation(translatable)

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

    add_with_translation('a', '1')
    translator_fr.suggest_translation(model.name, 'en', 'fr') == '1'

    add_with_translation('a', '2')
    add_with_translation('a', '2')
    translator_fr.suggest_translation(model.name, 'en', 'fr') == '2'
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:31,代码来源:test_suggestions.py

示例4: bound_session

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def bound_session(request, session, session_cls):
    # importing at the module level messes up coverage
    from taal import Translator
    from tests.models import Translation

    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session)
    return session
开发者ID:onefinestay,项目名称:taal,代码行数:10,代码来源:conftest.py

示例5: test_labeled_hierarchy

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

    translator = Translator(Translation, session, 'en')
    translator.bind(manager)

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

    assert isinstance(entity[1], TranslatableString)
开发者ID:timbu,项目名称:taal,代码行数:12,代码来源:test_manager.py

示例6: bound_manager

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def bound_manager(request, session_cls, translating_manager):
    # importing at the module level messes up coverage
    from taal import Translator
    from tests.models import Translation

    manager = translating_manager

    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(manager)
    return manager
开发者ID:onefinestay,项目名称:taal,代码行数:12,代码来源:conftest.py

示例7: test_set_from_other_model

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_set_from_other_model(session, session_cls):
    model1 = Model(name='name')
    model2 = RequiredModel(name=model1.name)
    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session)
    session.add(model1)
    session.add(model2)
    session.commit()

    assert translator.session.query(
        Translation.context).distinct().count() == 2
开发者ID:timbu,项目名称:taal,代码行数:13,代码来源:test_sqlalchemy.py

示例8: test_unknown_language

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

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

    assert translator.suggest_translation(model.name, 'en', 'foo') is None
    assert translator.suggest_translation(model.name, 'foo', 'en') is None
开发者ID:martinpengellyphillips,项目名称:taal,代码行数:13,代码来源:test_suggestions.py

示例9: test_query_values

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_query_values(session_cls):
    session1 = session_cls()
    session2 = session_cls()

    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session1)
    translator.bind(session2)
    model = Model(name='name')
    session1.add(model)
    session1.commit()

    (value,) = session2.query(Model.name).one()
    assert value == PlaceholderValue
开发者ID:timbu,项目名称:taal,代码行数:15,代码来源:test_sqlalchemy.py

示例10: test_merge_from_other_session

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_merge_from_other_session(session_cls):
    """ regression test """
    session1 = session_cls()
    session2 = session_cls()

    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session1)
    translator.bind(session2)

    instance = Model(name='name')
    session1.add(instance)
    session1.commit()

    session2.merge(instance)
    session2.commit()
开发者ID:timbu,项目名称:taal,代码行数:17,代码来源:test_sqlalchemy.py

示例11: test_removing_translations

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_removing_translations(session, session_cls, first, second):
    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session)
    instance = Model(name=first)
    session.add(instance)
    session.commit()

    expected_count = 1 if is_translatable_value(first) else 0
    assert translator.session.query(Translation).count() == expected_count

    instance.name = second
    session.commit()

    expected_count = 1 if is_translatable_value(second) else 0
    assert translator.session.query(Translation).count() == expected_count
开发者ID:timbu,项目名称:taal,代码行数:17,代码来源:test_sqlalchemy.py

示例12: test_load

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_load(session, session_cls, value):
    instance = Model(name=value)
    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session)
    session.add(instance)
    session.commit()
    pk = instance.id

    # make a new session
    session = session_cls()
    translator.bind(session)
    instance = session.query(Model).get(pk)
    if value is None:
        assert instance.name is None
    else:
        assert isinstance(instance.name, TranslatableString)
开发者ID:timbu,项目名称:taal,代码行数:18,代码来源:test_sqlalchemy.py

示例13: test_corrupt_db

# 需要导入模块: from taal import Translator [as 别名]
# 或者: from taal.Translator import bind [as 别名]
def test_corrupt_db(session, session_cls):
    class CorruptModel(Base):
        __tablename__ = "models"

        id = Column(Integer, primary_key=True)
        name = Column(Text)
        identifier = Column(Text)

    corrupt = CorruptModel(id=1, name='name')
    session.add(corrupt)
    session.commit()

    translator = Translator(Translation, session_cls(), 'language')
    translator.bind(session)
    with pytest.raises(RuntimeError):
        session.query(Model).get(1)
开发者ID:timbu,项目名称:taal,代码行数:18,代码来源:test_sqlalchemy.py

示例14: test_translating_class_labels

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

示例15: test_savepoints

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

        instance1 = Model(name='instance 1')
        session.add(instance1)

        session.begin_nested()

        instance2 = Model(name='instance 2')
        session.add(instance2)
        session.flush()
        assert session in flush_log
        assert len(flush_log[session]) == 2

        session.rollback()
        session.commit()

        assert session.query(Model).count() == 1
        assert translator.session.query(Translation).count() == 1
开发者ID:timbu,项目名称:taal,代码行数:22,代码来源:test_sqlalchemy.py


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