예제 #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
파일: test_models.py 프로젝트: timbu/taal
    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
파일: test_manager.py 프로젝트: timbu/taal
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
파일: test_models.py 프로젝트: timbu/taal
    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)