From acb61e23001d3fee68d1886306fdadd07d8be876 Mon Sep 17 00:00:00 2001 From: lando Date: Mon, 28 Oct 2024 12:14:43 +0800 Subject: [PATCH 1/3] Reuse InitCatalog in UpdateCatalog with --init-missing --- babel/messages/frontend.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 7a9ce385f..1515ea5a1 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -779,21 +779,17 @@ def run(self): if self.check: check_status[filename] = False continue - self.log.info( - 'creating catalog %s based on %s', filename, self.input_file, - ) - - with open(self.input_file, 'rb') as infile: - # Although reading from the catalog template, read_po must - # be fed the locale in order to correctly calculate plurals - catalog = read_po(infile, locale=self.locale) - - catalog.locale = self._locale - catalog.revision_date = datetime.datetime.now(LOCALTZ) - catalog.fuzzy = False - with open(filename, 'wb') as outfile: - write_po(outfile, catalog) + tmpInitCatalog = InitCatalog(self.distribution) + tmpInitCatalog.output_dir = None + tmpInitCatalog.output_file = filename + tmpInitCatalog.input_file = self.input_file + tmpInitCatalog.locale = self.locale + tmpInitCatalog.domain = self.domain + tmpInitCatalog.no_wrap = self.no_wrap + tmpInitCatalog.width = self.width + tmpInitCatalog.finalize_options() + tmpInitCatalog.run() self.log.info('updating catalog %s based on %s', filename, self.input_file) with open(filename, 'rb') as infile: From 3a47a5c86a6c12ad1313ccb18c634720e1a3e942 Mon Sep 17 00:00:00 2001 From: lando Date: Mon, 28 Oct 2024 12:31:44 +0800 Subject: [PATCH 2/3] Use exist_ok flag instead of redundant if statement --- babel/messages/frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 1515ea5a1..25025f8ca 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -626,8 +626,8 @@ def finalize_options(self): self.output_file = os.path.join(self.output_dir, self.locale, 'LC_MESSAGES', f"{self.domain}.po") - if not os.path.exists(os.path.dirname(self.output_file)): - os.makedirs(os.path.dirname(self.output_file)) + os.makedirs(os.path.dirname(self.output_file),exist_ok=True) + if self.no_wrap and self.width: raise OptionError("'--no-wrap' and '--width' are mutually exclusive") if not self.no_wrap and not self.width: From 158b610838ea34d97c33bf9483b37a8bf1d05353 Mon Sep 17 00:00:00 2001 From: Dylan Ulster <46591250+du33169@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:13:15 +0800 Subject: [PATCH 3/3] Add a space between parameters Co-authored-by: Aarni Koskela --- babel/messages/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 25025f8ca..0142f8d61 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -626,7 +626,7 @@ def finalize_options(self): self.output_file = os.path.join(self.output_dir, self.locale, 'LC_MESSAGES', f"{self.domain}.po") - os.makedirs(os.path.dirname(self.output_file),exist_ok=True) + os.makedirs(os.path.dirname(self.output_file), exist_ok=True) if self.no_wrap and self.width: raise OptionError("'--no-wrap' and '--width' are mutually exclusive")