def test_update_catalog_comments(): # Based on https://web.archive.org/web/20100710131029/http://babel.edgewall.org/attachment/ticket/163/cat-update-comments.py catalog = pofile.read_po( StringIO(''' # A user comment #. An auto comment #: main.py:1 #, fuzzy, python-format msgid "foo %(name)s" msgstr "foo %(name)s" ''')) assert all(message.user_comments and message.auto_comments for message in catalog if message.id) # NOTE: in the POT file, there are no comments template = pofile.read_po( StringIO(''' #: main.py:1 #, fuzzy, python-format msgid "bar %(name)s" msgstr "" ''')) catalog.update(template) # Auto comments will be obliterated here assert all(message.user_comments for message in catalog if message.id)
def update(self, locales, use_fuzzy_matching=False, include_header=False): for locale in locales: catalog = self.get(locale) self.pod.logger.info("Updating: {}".format(locale)) catalog.update( template_path=self.template_path, use_fuzzy_matching=use_fuzzy_matching, include_header=include_header )
def update(self, locales, use_fuzzy_matching=False, include_header=False): for locale in locales: catalog = self.get(locale) self.pod.logger.info('Updating: {}'.format(locale)) catalog.update(template_path=self.template_path, use_fuzzy_matching=use_fuzzy_matching, include_header=include_header)
def update(self, locales, use_fuzzy_matching=None, include_header=None): _, _, include_header, use_fuzzy_matching = \ self.get_extract_config(include_header=include_header, use_fuzzy_matching=use_fuzzy_matching) for locale in locales: catalog = self.get(locale) self.pod.logger.info('Updating: {}'.format(locale)) catalog.update(template_path=self.template_path, use_fuzzy_matching=use_fuzzy_matching, include_header=include_header)
def update_catalog(self, use_fuzzy=False, ignore_obsolete=True, include_previous=True, width=80): locale = str(self.locale) domain = 'messages' po_filename = os.path.join(self.path, 'LC_MESSAGES', 'messages.po') pot_filename = os.path.join('translations', 'messages.pot') template = pofile.read_po(self.pod.open_file(pot_filename)) # Create a catalog if it doesn't exist. if not self.pod.file_exists(po_filename): self.init_catalog() return logging.info('Updating catalog {} using {}'.format(po_filename, pot_filename)) infile = self.pod.open_file(po_filename, 'U') try: catalog = pofile.read_po(infile, locale=locale, domain=domain) finally: infile.close() catalog.update(template, use_fuzzy) temp_filename = po_filename + '.tmp' if not self.pod.file_exists(temp_filename): self.pod.create_file(temp_filename, None) temp_file = self.pod.open_file(temp_filename, 'w') try: try: pofile.write_po(temp_file, catalog, ignore_obsolete=ignore_obsolete, include_previous=include_previous, width=width) finally: temp_file.close() except: self.pod.delete_file(temp_filename) raise self.pod.move_file_to(temp_filename, po_filename)
def update(self, locales, use_fuzzy=False): for locale in locales: catalog = self.get(locale) catalog.update(template_path=self.template_path, use_fuzzy=use_fuzzy)