Esempio n. 1
0
def test_adding_the_same_sting_without_context(db_connection):
    data.add_language('polish', 'pl')
    resource_pk = data.add_resource('r').pk
    data.add_or_update_base_string(resource_pk,
                                   'x',
                                   comment='comment',
                                   context=None)
    data.add_or_update_base_string(resource_pk,
                                   'x',
                                   comment='lolz',
                                   context=None)
    preserved_strings = list(data.get_translated_strings('pl', resource_pk))
    assert preserved_strings == [
        dila.application.structures.TranslatedStringData(
            pk=mock.ANY,
            base_string='x',
            plural='',
            context='',
            translation='',
            comment='lolz',
            translator_comment='',
            resource_pk=resource_pk,
            plural_translations=None,
        )
    ]
Esempio n. 2
0
def test_deleting_old_translated_strings(db_connection):
    data.add_language('polish', 'pl')
    resource_pk = data.add_resource('r').pk
    first_string_pk = data.add_or_update_base_string(resource_pk,
                                                     'x',
                                                     comment='comment',
                                                     context='ctx')
    second_string_pk = data.add_or_update_base_string(resource_pk,
                                                      'y',
                                                      comment='comment',
                                                      context='ctx')
    data.set_translated_string('pl',
                               second_string_pk,
                               translation='y',
                               translator_comment='ytcomment')
    data.delete_old_strings(resource_pk, keep_pks=[first_string_pk])
    preserved_strings = list(data.get_translated_strings('pl', resource_pk))
    assert preserved_strings == [
        dila.application.structures.TranslatedStringData(
            pk=mock.ANY,
            base_string='x',
            plural='',
            context='ctx',
            translation='',
            comment='comment',
            translator_comment='',
            resource_pk=resource_pk,
            plural_translations=None,
        )
    ]
Esempio n. 3
0
def get_po_file(language_code, resource_pk):
    po = polib.POFile()
    for string in data.get_translated_strings(language_code, resource_pk):
        po.append(build_po_entry(string))
    po.metadata = data.get_po_metadata(language_code, resource_pk)
    return str(po)
Esempio n. 4
0
def get_translated_strings(language_code, resource_pk):
    return data.get_translated_strings(language_code, resource_pk)