def test_fill_catalog_get_properties(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1") source_catalog = Catalog() source_catalog.add("id1", string="Text1ignore", auto_comments=["comment"]) source_catalog.add("id2", string="Text2ignore", locations=[("file1", "1")]) string_source_catalog = Catalog() string_source_catalog.add( "id1", string="Text1new", auto_comments=["comment2"], locations=[("file2", "1")], ) fill_catalog(target_catalog, source_catalog, string_source_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text1new", auto_comments=["comment"]) expected_catalog.add("id2", string="", locations=[("file1", "1")]) 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 = 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_source_catalog(js_catalog, python_catalog, old_source_catalog): """ Read the message catalogs extracted from js and python for the default locale and merge them. Return - the new merged catalog for the default locale - a catalog with the new messages extracted from python code - a set with the unique identifiers (in the sense of `message_unique_identifier`) of fuzzy messages """ for message in python_catalog: if message.id: for comment in message.auto_comments: match = _default_message_re.match(comment) if match: default_message = match.group(1).strip() message.auto_comments.remove(comment) message.string = default_message fill_catalog(js_catalog, python_catalog, python_catalog) return ( js_catalog, python_catalog, find_fuzzy_messages(new_catalog=js_catalog, old_catalog=old_source_catalog), )
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_fill_catalog_preserve_old(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1") source_catalog = Catalog() string_source_catalog = Catalog() fill_catalog(target_catalog, source_catalog, string_source_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text1") assert_catalogs_deeply_equal(target_catalog, expected_catalog)
def test_fill_catalog_update_message(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1") source_catalog = Catalog() source_catalog.add("id1", string="Text1") string_source_catalog = Catalog() string_source_catalog.add("id1", string="Text2") fill_catalog(target_catalog, source_catalog, string_source_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text2") assert_catalogs_deeply_equal(target_catalog, expected_catalog)
def test_fill_catalog_add_new(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1") source_catalog = Catalog() source_catalog.add("id2", string="Text2ignore") string_source_catalog = Catalog() string_source_catalog.add("id2", string="Text2") fill_catalog(target_catalog, source_catalog, string_source_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text1") expected_catalog.add("id2", string="Text2") assert_catalogs_deeply_equal(target_catalog, expected_catalog)
def test_fill_catalog_update_properties(self): target_catalog = Catalog() target_catalog.add("id1", string="Text1", auto_comments=["comment"]) source_catalog = Catalog() source_catalog.add("id1", string="Text1ignore", auto_comments=["new comment"]) string_source_catalog = Catalog() fill_catalog(target_catalog, source_catalog, string_source_catalog) expected_catalog = Catalog() expected_catalog.add("id1", string="Text1", auto_comments=["new comment"]) 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