Пример #1
0
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'
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'
Пример #3
0
    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
Пример #4
0
    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'
Пример #5
0
    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'
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
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'
Пример #9
0
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'
Пример #10
0
    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
Пример #11
0
    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
Пример #12
0
def test_save_empty(session):
    translatable = TranslatableString()
    translator = Translator(Translation, session, 'language')
    with pytest.raises(RuntimeError):
        translator.save_translation(translatable)
Пример #13
0
def test_save_empty(session):
    translatable = TranslatableString()
    translator = Translator(Translation, session, 'language')
    with pytest.raises(RuntimeError):
        translator.save_translation(translatable)