Skip to content

Commit 246671a

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 3ae7cbd commit 246671a

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
@@ -940,10 +940,37 @@ def initialize_options(self):
940940
self.sort_by_file = None
941941

942942
def finalize_options(self):
943-
pass
943+
if not self.input_files:
944+
raise OptionError('you must specify the input files')
945+
if not self.output_file:
946+
raise OptionError('you must specify the output file')
947+
948+
# временно всегда используется первый перевод
949+
if self.use_first is None:
950+
self.use_first = True
944951

945952
def run(self):
946-
pass
953+
catalog = Catalog(fuzzy=False)
954+
955+
for filenum, filename in enumerate(self.input_files):
956+
with open(filename, 'r') as pofile:
957+
template = read_po(pofile)
958+
959+
if filenum == 0:
960+
catalog.update(template)
961+
continue
962+
963+
for message in template:
964+
if not message.id:
965+
continue
966+
967+
if message.id in catalog and catalog[message.id].string != message.string and not self.use_first:
968+
raise NotImplementedError()
969+
970+
catalog[message.id] = message
971+
972+
with open(self.output_file, 'wb') as outfile:
973+
write_po(outfile, catalog)
947974

948975

949976
class MessageMerge(CommandMixin):

0 commit comments

Comments
 (0)