+def formats_l10n(input_files, output, base):
+ '''Generate pot file from configure.py'''
+ output = io.open(output, 'w', encoding='utf_8', newline='\n')
+ GuiName = re.compile(r'.*\\Format\s+\S+\s+\S+\s+"([^"]*)"\s+(\S*)\s+.*', re.IGNORECASE)
+ GuiName2 = re.compile(r'.*\\Format\s+\S+\s+\S+\s+([^"]\S+)\s+(\S*)\s+.*', re.IGNORECASE)
+ input = io.open(input_files[0], encoding='utf_8')
+ for lineno, line in enumerate(input.readlines()):
+ label = ""
+ labelsc = ""
+ if GuiName.match(line):
+ label = GuiName.match(line).group(1)
+ shortcut = GuiName.match(line).group(2).replace('"', '')
+ elif GuiName2.match(line):
+ label = GuiName2.match(line).group(1)
+ shortcut = GuiName2.match(line).group(2).replace('"', '')
+ else:
+ continue
+ label = label.replace('\\', '\\\\').replace('"', '')
+ if shortcut != "":
+ labelsc = label + "|" + shortcut
+ if label != "":
+ print(u'#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, label), file=output)
+ if labelsc != "":
+ print(u'#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, labelsc), file=output)
+ input.close()
+ output.close()
+
+
+def encodings_l10n(input_files, output, base):
+ '''Generate pot file from lib/encodings'''
+ output = io.open(output, 'w', encoding='utf_8', newline='\n')
+ # assuming only one encodings file
+ # Encoding utf8 utf8 "Unicode (utf8)" UTF-8 variable inputenc
+ reg = re.compile('Encoding [\w-]+\s+[\w-]+\s+"([\w \-\(\)\[\]\/^"]*)"\s+["\w-]+\s+(fixed|variable|variableunsafe)\s+\w+.*')
+ input = io.open(input_files[0], encoding='utf_8')
+ for lineno, line in enumerate(input.readlines()):
+ if not line.startswith('Encoding'):
+ continue
+ if reg.match(line):
+ guiname = reg.match(line).groups()[0]
+ if guiname != "":
+ print(u'#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, guiname), file=output)
+ else:
+ print("Error: Unable to handle line:")
+ print(line)
+ # No need to abort if the parsing fails
+ # sys.exit(1)
+ input.close()
+ 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 = os.path.normpath(os.path.realpath(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 = os.path.normpath(os.path.realpath(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()
+
+
+