Skip to content

Commit a5f6295

Browse files
committed
Implement basic logic for concatenating catalogs
* Add validation for main msgcat options - input_files, output_file * Temporarily set use_first option to true to avoid handling cases with different translations for the same messages
1 parent d4eac53 commit a5f6295

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

babel/messages/frontend.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,37 @@ def initialize_options(self):
975975
self.sort_by_file = None
976976

977977
def finalize_options(self):
978-
pass
978+
if not self.input_files:
979+
raise OptionError('you must specify the input files')
980+
if not self.output_file:
981+
raise OptionError('you must specify the output file')
982+
983+
# временно всегда используется первый перевод
984+
if self.use_first is None:
985+
self.use_first = True
979986

980987
def run(self):
981-
pass
988+
catalog = Catalog(fuzzy=False)
989+
990+
for filenum, filename in enumerate(self.input_files):
991+
with open(filename, 'r') as pofile:
992+
template = read_po(pofile)
993+
994+
if filenum == 0:
995+
catalog.update(template)
996+
continue
997+
998+
for message in template:
999+
if not message.id:
1000+
continue
1001+
1002+
if message.id in catalog and catalog[message.id].string != message.string and not self.use_first:
1003+
raise NotImplementedError()
1004+
1005+
catalog[message.id] = message
1006+
1007+
with open(self.output_file, 'wb') as outfile:
1008+
write_po(outfile, catalog)
9821009

9831010

9841011
class MessageMerge(CommandMixin):

0 commit comments

Comments
 (0)