-# Print a header
-print("/***********************************************************************\n" \
-" *** THIS FILE IS GENERATED AUTOMATICALLY. DON'T EDIT! ***\n" \
-" ***********************************************************************/")
-
-# Process the options template and generate options.h with all
-# translations.
-template = io.open(args.template, mode="rt", encoding='utf-8')
-descMatches = []
-for line in template:
- if len(descMatches) > 0:
- matchENUM = reENUM.match(line)
- matchDESC_END = reDESC_END.match(line)
- if matchENUM:
- descMatches.append(matchENUM)
- elif matchDESC_END:
- expandMatches(descMatches, translations, line)
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--template', required=True)
+ parser.add_argument('--output', required=True)
+ parser.add_argument('--localedir', required=True)
+ parser.add_argument('--languages', nargs='*', default=[])
+ args = parser.parse_args()
+
+ # Compile a list of translation classes to all supported languages.
+ # The first translation is always a NullTranslations.
+ translations = [("en", gettext.NullTranslations())]
+ for lang in args.languages:
+ try:
+ filename = os.path.join(args.localedir, '{}.gmo'.format(lang))
+ with io.open(filename, 'rb') as f:
+ trans = gettext.GNUTranslations(f)
+ except (IOError, OSError):
+ print("Warning: language '%s' not found." % lang, file=sys.stderr)
+ continue
+ translations.append((lang, trans))
+
+ with io.open(args.output, mode='wt', encoding='utf-8') as output:
+ output.write("/* This is file is generated automatically. Don't edit! */\n")
+
+ # Process the options template and generate options.h with all
+ # translations.
+ with io.open(args.template, mode="rt", encoding='utf-8') as template: