• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python taal.Translator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_unknown_language

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


示例17: test_debug_value

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


示例18: test_sentinel_value

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


示例19: test_dont_save_debug_translation

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


示例20: test_translate

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tabix.open函数代码示例发布时间:2022-05-27
下一篇:
Python general.AvcGeneral类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap