X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=po%2Flyx_pot.py;h=71bd4c7e6ac1b81bd864aa789a8c27242574236f;hb=1e519d1115f41f71c253cb9e2fbb7803e9a583a9;hp=d16a1393821cc2c27d4027f8aa0f20f07aa24c56;hpb=43c05fe16b35d302352d540a30012b353342687a;p=lyx.git diff --git a/po/lyx_pot.py b/po/lyx_pot.py index d16a139382..71bd4c7e6a 100755 --- a/po/lyx_pot.py +++ b/po/lyx_pot.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python3 # -*- coding: utf-8 -*- # file lyx_pot.py @@ -18,7 +18,7 @@ # from __future__ import print_function -import sys, os, re, getopt +import glob, sys, os, re, getopt import io def relativePath(path, base): @@ -47,6 +47,7 @@ def ui_l10n(input_files, output, base): output = io.open(output, 'w', encoding='utf_8', newline='\n') Submenu = re.compile(r'^[^#]*Submenu\s+"([^"]*)"', re.IGNORECASE) Popupmenu = re.compile(r'^[^#]*PopupMenu\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE) + Dynamicmenu = re.compile(r'^[^#]*DynamicMenu\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE) IconPalette = re.compile(r'^[^#]*IconPalette\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE) Toolbar = re.compile(r'^[^#]*Toolbar\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE) Item = re.compile(r'[^#]*Item\s+"([^"]*)"', re.IGNORECASE) @@ -59,6 +60,8 @@ def ui_l10n(input_files, output, base): string = string.replace('_', ' ') elif Popupmenu.match(line): (string,) = Popupmenu.match(line).groups() + elif Dynamicmenu.match(line): + (string,) = Dynamicmenu.match(line).groups() elif IconPalette.match(line): (string,) = IconPalette.match(line).groups() elif Toolbar.match(line): @@ -620,6 +623,59 @@ def encodings_l10n(input_files, output, base): output.close() +def examples_templates_l10n(input_files, output, base): + '''Generate pot file from lib/templates and lib/examples''' + output = io.open(output, 'w', encoding='utf_8', newline='\n') + # only record each item once + seen = [] + for src in input_files: + parseExamplesTemplates(src, seen, output) + output.close() + + +def parseExamplesTemplates(file, seen, output): + # Recursively iterate over subdirectories + if os.path.isdir(file): + for sfile in glob.glob( os.path.join(file, '*') ): + parseExamplesTemplates(sfile, seen, output) + + filename = file.split(os.sep)[-1] + if os.path.isfile(file): + if filename[-4:] != ".lyx": + return + filename = filename[:-4] + if seen.count(filename) or filename[0].islower(): + return + + seen.append(filename) + if filename != "": + print(u'#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \ + (relativePath(input_files[0], base), 0, filename.replace('_', ' ').replace('%26', '&').replace('%28', '(').replace('%29', ')')), file=output) + + +def tabletemplates_l10n(input_files, output, base): + '''Generate pot file from lib/tabletemplates ''' + output = io.open(output, 'w', encoding='utf_8', newline='\n') + # only record each item once + seen = [] + for file in input_files: + filename = file.split(os.sep)[-1] + if os.path.isfile(file): + if filename[-4:] != ".lyx": + continue + filename = filename[:-4] + if filename[-4:-1] == "_1x": + continue + if seen.count(filename): + continue + + seen.append(filename) + if filename != "": + print(u'#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \ + (relativePath(input_files[0], base), 0, filename.replace('_', ' ')), file=output) + output.close() + + Usage = ''' lyx_pot.py [-b|--base top_src_dir] [-o|--output output_file] [-h|--help] [-s|src_file filename] -t|--type input_type input_files @@ -641,6 +697,8 @@ where encodings: file lib/encodings external: external templates files formats: formats predefined in lib/configure.py + examples_templates: example and template files + tabletemplates: table template files ''' if __name__ == '__main__': @@ -664,7 +722,7 @@ if __name__ == '__main__': elif opt in ['-s', '--src_file']: input_files = [f.strip() for f in io.open(value, encoding='utf_8')] - if input_type not in ['ui', 'layouts', 'layouttranslations', 'qt4', 'languages', 'latexfonts', 'encodings', 'external', 'formats'] or output is None: + if input_type not in ['ui', 'layouts', 'layouttranslations', 'qt4', 'languages', 'latexfonts', 'encodings', 'external', 'formats', 'examples_templates', 'tabletemplates'] or output is None: print('Wrong input type or output filename.') sys.exit(1) @@ -693,7 +751,9 @@ if __name__ == '__main__': formats_l10n(input_files, output, base) elif input_type == 'encodings': encodings_l10n(input_files, output, base) + elif input_type == 'examples_templates': + examples_templates_l10n(input_files, output, base) + elif input_type == 'tabletemplates': + tabletemplates_l10n(input_files, output, base) else: languages_l10n(input_files, output, base) - -