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


Python taal.Translator类代码示例

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


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

示例1: test_none_value

    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,代码行数:7,代码来源:test_strategies.py

示例2: test_translate_missing

    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,代码行数:7,代码来源:test_models.py

示例3: test_use_most_frequent

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,代码行数:29,代码来源:test_suggestions.py

示例4: test_translate_structure

    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,代码行数:25,代码来源:test_models.py

示例5: test_translate_missing_debug

    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,代码行数:8,代码来源:test_models.py

示例6: bound_session

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,代码行数:8,代码来源:conftest.py

示例7: test_list_missing_translations

    def test_list_missing_translations(self, session):
        translator = Translator(Translation, session, '')
        missing_translations = translator.list_missing_translations(
            ['en', 'sv'])

        assert set(missing_translations) == set([
            ('animal', '2', 'Monkey', None),
            ('animal', '3', None, 'Flodhäst'),
        ])
开发者ID:timbu,项目名称:taal,代码行数:9,代码来源:test_sqlalchemy.py

示例8: test_list_none

    def test_list_none(self, session):
        translator = Translator(Translation, session, '')
        translations = translator.list_translations([])

        assert set(translations) == set([
            ('animal', '1'),
            ('animal', '2'),
            ('animal', '3'),
        ])
开发者ID:timbu,项目名称:taal,代码行数:9,代码来源:test_sqlalchemy.py

示例9: test_list_single

    def test_list_single(self, session):
        translator = Translator(Translation, session, '')
        translations = translator.list_translations(['en'])

        assert set(translations) == set([
            ('animal', '1', 'Moose'),
            ('animal', '2', 'Monkey'),
            ('animal', '3', None),
        ])
开发者ID:timbu,项目名称:taal,代码行数:9,代码来源:test_sqlalchemy.py

示例10: test_invalid_override

 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,代码行数:9,代码来源:test_strategies.py

示例11: test_labeled_hierarchy

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,代码行数:10,代码来源:test_manager.py

示例12: test_list_translations

    def test_list_translations(self, session):
        self.setup_(session)
        translator = Translator(Translation, session, '')
        translations = translator.list_translations(['en', 'sv'])

        assert set(translations) == set([
            ('animal', '1', 'Moose', 'Älg'),
            ('animal', '2', 'Monkey', None),
            ('animal', '3', None, 'Flodhäst'),
        ])
开发者ID:pombredanne,项目名称:taal,代码行数:10,代码来源:test_sqlalchemy.py

示例13: bound_manager

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,代码行数:10,代码来源:conftest.py

示例14: test_basic

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,代码行数:26,代码来源:test_suggestions.py

示例15: test_set_from_other_model

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,代码行数:11,代码来源:test_sqlalchemy.py


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