Skip to content

Commit 4cbe604

Browse files
committed
Ability to specify multiple compendiums
1 parent 133c8db commit 4cbe604

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

babel/messages/frontend.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ class ConcatenationCatalog(CommandMixin):
872872
('to-code=','t', 'encoding for output'),
873873
('use-first', None, 'use first available translation for each'
874874
'message, don\'t merge several translations'),
875-
('lang=', None, 'set 'Language' field in the header entry'),
875+
('lang=', None, 'set \'Language\' field in the header entry'),
876876
('color=', None, 'use colors and other text attributes always'),
877877
('style=', None, 'specify CSS style rule file for --color'),
878878
('no-escape', 'e', 'do not use C escapes in output (default)'),
@@ -1020,12 +1020,12 @@ class MergeCatalog(CommandMixin):
10201020
('backup', None, 'make a backup of def.po'),
10211021
('suffix=', None, 'override the usual backup suffix'),
10221022
('multi-domain', 'm', 'apply ref.pot to each of the domains in def.po'),
1023-
('for-msgfmt', None, 'produce output for 'msgfmt', not for a translator'),
1023+
('for-msgfmt', None, 'produce output for \'msgfmt\', not for a translator'),
10241024
('no-fuzzy-matching', 'N', 'do not use fuzzy matching'),
10251025
('previous', None, 'keep previous msgids of translated messages'),
10261026
('properties-input', 'P', 'input files are in Java .properties syntax'),
10271027
('stringtable-input', None, 'input files are in NeXTstep/GNUstep .strings syntax'),
1028-
('lang=', None, 'set 'Language' field in the header entry'),
1028+
('lang=', None, 'set \'Language\' field in the header entry'),
10291029
('color=', None, 'use colors and other text attributes always'),
10301030
('style=', None, 'specify CSS style rule file for --color'),
10311031
('no-escape', 'e', 'do not use C escapes in output (default)'),
@@ -1043,7 +1043,11 @@ class MergeCatalog(CommandMixin):
10431043
('sort-by-file', 'F', 'sort output by file location'),
10441044
]
10451045

1046-
as_args='input-files'
1046+
as_args = 'input-files'
1047+
1048+
multiple_value_options = (
1049+
'compendium'
1050+
)
10471051

10481052
boolean_options = [
10491053
'update',
@@ -1120,6 +1124,13 @@ def finalize_options(self):
11201124
elif self.width is not None:
11211125
self.width = int(self.width)
11221126

1127+
def _get_message_from_compendium(self, compendium):
1128+
for file_path in compendium:
1129+
with open(file_path, 'r') as pofile:
1130+
catalog = read_po(pofile)
1131+
for message in catalog:
1132+
yield message, file_path
1133+
11231134
def run(self):
11241135
def_file, ref_file = self.input_files
11251136

@@ -1136,10 +1147,7 @@ def run(self):
11361147
)
11371148

11381149
if self.compendium:
1139-
with open(self.compendium, 'r') as pofile:
1140-
compendium_catalog = read_po(pofile)
1141-
1142-
for message in compendium_catalog:
1150+
for message, compendium_path in self._get_message_from_compendium(self.compendium):
11431151
current = catalog[message.id]
11441152
if message.id in catalog and (not current.string or current.fuzzy or self.compendium_overwrite):
11451153
if self.compendium_overwrite and not current.fuzzy and current.string:
@@ -1150,7 +1158,7 @@ def run(self):
11501158
current.flags.remove('fuzzy')
11511159

11521160
if not self.no_compendium_comment:
1153-
current.auto_comments.append(self.compendium)
1161+
current.auto_comments.append(compendium_path)
11541162

11551163
catalog.fuzzy = any(message.fuzzy for message in catalog)
11561164
output_path = def_file if self.update else self.output_file

0 commit comments

Comments
 (0)