@@ -1025,30 +1025,30 @@ def run(self):
10251025
10261026
10271027class MergeCatalog (CommandMixin ):
1028- description = 'updates translation PO file by merging them with updated template POT file with using compendium'
1029- user_options = [
1030- ('input-files' , None , 'def.po (obsolete translations) ref.pot (actual template)' ),
1028+ description = 'update a PO file by merging it with a newer POT template, optionally using a compendium'
1029+ user_options = [
1030+ ('input-files' , None , 'exactly two input files: def.po (obsolete translations); ref.pot (current template)' ),
10311031 ('compendium=' , 'C' , 'additional library of message translations, may be specified more than once' ),
1032- ('compendium-overwrite' , '' , 'overwrite mode of compendium' ),
1033- ('no-compendium-comment' , '' , '' ),
1034- ('update' , 'U' , 'pdate def.po, do nothing if def.po already up to date' ),
1032+ ('compendium-overwrite' , None , 'overwrite existing translations with compendium entries ' ),
1033+ ('no-compendium-comment' , None , 'do not add a comment for translations taken from a compendium ' ),
1034+ ('update' , 'U' , 'update def.po, do nothing if def.po already up to date' ),
10351035 ('output-file=' , 'o' , 'write output to specified file, the results are written '
10361036 'to standard output if no output file is specified' ),
10371037 ('backup' , None , 'make a backup of def.po' ),
1038- ('suffix=' , None , 'override the usual backup suffix' ),
1038+ ('suffix=' , None , 'use SUFFIX as backup suffix instead of ~ (tilde) ' ),
10391039 ('no-fuzzy-matching' , 'N' , 'do not use fuzzy matching' ),
1040- ('no-location' , None , 'suppress \' #: filename: line\' lines ' ),
1041- ('width=' , 'w' , 'set output page width' ),
1040+ ('no-location' , None , 'do not include location comments with filename and line number ' ),
1041+ ('width=' , 'w' , 'set output line width (default 76) ' ),
10421042 ('no-wrap' , None , 'do not break long message lines, longer '
1043- 'than the output page width, into several lines' ),
1043+ 'than the output line width, into several lines' ),
10441044 ('sort-output' , 's' , 'generate sorted output' ),
10451045 ('sort-by-file' , 'F' , 'sort output by file location' ),
10461046 ]
10471047
10481048 as_args = 'input-files'
10491049
10501050 multiple_value_options = (
1051- 'compendium'
1051+ 'compendium' ,
10521052 )
10531053
10541054 boolean_options = [
@@ -1081,9 +1081,11 @@ def initialize_options(self):
10811081
10821082 def finalize_options (self ):
10831083 if not self .input_files or len (self .input_files ) != 2 :
1084- raise OptionError ('must be two po files' )
1084+ raise OptionError (
1085+ f'exactly two input files are required (def.po and ref.pot), got: { self .input_files !r} '
1086+ )
10851087 if not self .output_file and not self .update :
1086- raise OptionError ('you must specify the output file or update existing ' )
1088+ raise OptionError ('you must specify the output file or use --update ' )
10871089
10881090 if self .no_wrap and self .width :
10891091 raise OptionError ("'--no-wrap' and '--width' are mutually exclusive" )
@@ -1092,8 +1094,10 @@ def finalize_options(self):
10921094 elif self .width is not None :
10931095 self .width = int (self .width )
10941096
1095- def _get_message_from_compendium (self , compendium ):
1096- for file_path in compendium :
1097+ def _get_messages_from_compendiums (self , compendium_paths ):
1098+ if not compendium_paths :
1099+ return
1100+ for file_path in compendium_paths :
10971101 with open (file_path , 'r' ) as pofile :
10981102 catalog = read_po (pofile )
10991103 for message in catalog :
@@ -1111,19 +1115,17 @@ def run(self):
11111115 no_fuzzy_matching = self .no_fuzzy_matching
11121116 )
11131117
1114- if self .compendium :
1115- for message , compendium_path in self ._get_message_from_compendium (self .compendium ):
1116- current = catalog [message .id ]
1117- if message .id in catalog and (not current .string or current .fuzzy or self .compendium_overwrite ):
1118- if self .compendium_overwrite and not current .fuzzy and current .string :
1119- catalog .obsolete [message .id ] = current .clone ()
1118+ for message , compendium_path in self ._get_messages_from_compendiums (self .compendium ):
1119+ if (current := catalog .get (message .id )) and (not current .string or current .fuzzy or self .compendium_overwrite ):
1120+ if self .compendium_overwrite and not current .fuzzy and current .string :
1121+ catalog .obsolete [message .id ] = current .clone ()
11201122
1121- current .string = message .string
1122- if current .fuzzy :
1123- current .flags .remove ('fuzzy' )
1123+ current .string = message .string
1124+ if current .fuzzy :
1125+ current .flags .remove ('fuzzy' )
11241126
1125- if not self .no_compendium_comment :
1126- current .auto_comments .append (compendium_path )
1127+ if not self .no_compendium_comment :
1128+ current .auto_comments .append (compendium_path )
11271129
11281130 catalog .fuzzy = any (message .fuzzy for message in catalog )
11291131 output_path = def_file if self .update else self .output_file
0 commit comments