def _merge_catalogs(catalogs: List[Catalog], old: Catalog, fuzzy: FrozenSet): """ Merge `catalogs` into one big catalog. Message strings will be populated using the `old` catalog. The strings in `catalogs` must be either empty or in the same language as `old`. A message string of the resulting catalog will be marked as fuzzy if: * it was fuzzy in the `old` catalog; or * it is non-empty and its unique identifier (in the sense of `message_unique_identifier`) is in `fuzzy` """ ret = Catalog( locale=old.locale, header_comment=old.header_comment, project=old.project, version=old.version, copyright_holder=old.copyright_holder, msgid_bugs_address=old.msgid_bugs_address, creation_date=old.creation_date, revision_date=old.revision_date, last_translator=old.last_translator, language_team=old.language_team, fuzzy=old.fuzzy, ) for catalog in catalogs: fill_catalog(ret, catalog, old) mark_fuzzy(ret, fuzzy, old) return ret
def _merge_nonsource_catalog( locale_id: str, old_catalog: Catalog, source_catalog: Catalog, fuzzy: FrozenSet[MessageUID], ) -> Catalog: catalog = Catalog(locale_id) fill_catalog(catalog, source_catalog, old_catalog) mark_fuzzy(catalog, fuzzy, old_catalog) return catalog
def test_mark_fuzzy_no_mark_empty(self): target_catalog = Catalog() target_catalog.add("id1", string="") old_catalog = Catalog() fuzzy = frozenset(["id1"]) mark_fuzzy(target_catalog, fuzzy, old_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="") assert_catalogs_deeply_equal(target_catalog, expected_catalog)
def test_mark_fuzzy_mark_old(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1", flags=["fuzzy"]) old_catalog = Catalog() fuzzy = frozenset() mark_fuzzy(target_catalog, fuzzy, old_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text1", flags=["fuzzy"]) assert_catalogs_deeply_equal(target_catalog, expected_catalog)
def _merge_catalogs(catalogs: List[Catalog], old: Catalog, fuzzy: FrozenSet): """ Merge `catalogs` into one big catalog. Message strings will be populated using the `old` catalog. The strings in `catalogs` must be either empty or in the same language as `old`. A message string of the resulting catalog will be marked as fuzzy if: * it was fuzzy in the `old` catalog; or * it is non-empty and its unique identifier (in the sense of `message_unique_identifier`) is in `fuzzy` """ ret = new_catalog_from_metadata(old) for catalog in catalogs: fill_catalog(ret, catalog, old) mark_fuzzy(ret, fuzzy, old) return ret