+def layouts_l10n(input_files, output, base, layouttranslations):
+ '''Generate pot file from lib/layouts/*.{layout,inc,module} and lib/citeengines/*.citeengine'''
+ ClassDescription = re.compile(r'^\s*#\s*\\Declare(LaTeX|DocBook)Class.*\{(.*)\}$', re.IGNORECASE)
+ ClassCategory = re.compile(r'^\s*#\s*\\DeclareCategory\{(.*)\}$', re.IGNORECASE)
+ Style = re.compile(r'^\s*Style\s+(.*\S)\s*$', re.IGNORECASE)
+ # match LabelString, EndLabelString, LabelStringAppendix and maybe others but no comments
+ LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*\S)\s*$', re.IGNORECASE)
+ MenuString = re.compile(r'^[^#]*MenuString\S*\s+(.*\S)\s*$', re.IGNORECASE)
+ OutlinerName = re.compile(r'^[^#]*OutlinerName\s+(\S+|\"[^\"]*\")\s+\"([^\"]*)\"', re.IGNORECASE)
+ Tooltip = re.compile(r'^\s*Tooltip\S*\s+(.*\S)\s*$', re.IGNORECASE)
+ GuiName = re.compile(r'^\s*GuiName\s+(.*\S)\s*$', re.IGNORECASE)
+ ListName = re.compile(r'^\s*ListName\s+(.*\S)\s*$', re.IGNORECASE)
+ CategoryName = re.compile(r'^\s*Category\s+(.*\S)\s*$', re.IGNORECASE)
+ NameRE = re.compile(r'^\s*#\s*\\DeclareLyXModule.*{(.*)}$', re.IGNORECASE)
+ CiteNameRE = re.compile(r'^\s*#\s*\\DeclareLyXCiteEngine.*\{(.*)\}$', re.IGNORECASE)
+ InsetLayout = re.compile(r'^InsetLayout\s+\"?(.*)\"?\s*$', re.IGNORECASE)
+ FlexCheck = re.compile(r'^Flex:(.*)', re.IGNORECASE)
+ CaptionCheck = re.compile(r'^Caption:(.*)', re.IGNORECASE)
+ DescBegin = re.compile(r'^\s*#\s*DescriptionBegin\s*$', re.IGNORECASE)
+ DescEnd = re.compile(r'^\s*#\s*DescriptionEnd\s*$', re.IGNORECASE)
+ Category = re.compile(r'^\s*#\s*Category:\s+(.*\S)\s*$', re.IGNORECASE)
+ I18nPreamble = re.compile(r'^\s*((Lang)|(Babel))Preamble\s*$', re.IGNORECASE)
+ EndI18nPreamble = re.compile(r'^\s*End((Lang)|(Babel))Preamble\s*$', re.IGNORECASE)
+ I18nString = re.compile(r'_\(([^\)]+)\)')
+ CounterFormat = re.compile(r'^\s*PrettyFormat\s+"?(.*)"?\s*$', re.IGNORECASE)
+ CiteFormat = re.compile(r'^\s*CiteFormat', re.IGNORECASE)
+ # Note: preceding and trailing space in the val below matters
+ KeyVal = re.compile(r'^\s*_\w+\s(.*\S)*$')
+ Float = re.compile(r'^\s*Float\s*$', re.IGNORECASE)
+ UsesFloatPkg = re.compile(r'^\s*UsesFloatPkg\s+(.*\S)\s*$', re.IGNORECASE)
+ IsPredefined = re.compile(r'^\s*IsPredefined\s+(.*\S)\s*$', re.IGNORECASE)
+ End = re.compile(r'^\s*End', re.IGNORECASE)
+ Comment = re.compile(r'^(.*)#')
+ Translation = re.compile(r'^\s*Translation\s+(.*\S)\s*$', re.IGNORECASE)
+ KeyValPair = re.compile(r'\s*"(.*)"\s+"(.*)"')
+
+ oldlanguages = []
+ languages = []
+ keyset = set()
+ oldtrans = dict()
+ if layouttranslations:
+ linguas_file = os.path.join(base, 'po/LINGUAS')
+ for line in open(linguas_file).readlines():
+ res = Comment.search(line)
+ if res:
+ line = res.group(1)
+ if line.strip() != '':
+ languages.extend(line.split())
+
+ # read old translations if available
+ try:
+ input = io.open(output, encoding='utf_8')
+ lang = ''
+ for line in input.readlines():
+ res = Comment.search(line)
+ if res:
+ line = res.group(1)
+ if line.strip() == '':
+ continue
+ res = Translation.search(line)
+ if res:
+ lang = res.group(1)
+ if lang not in languages:
+ oldlanguages.append(lang)
+ languages.append(lang)
+ oldtrans[lang] = dict()
+ continue
+ res = End.search(line)
+ if res:
+ lang = ''
+ continue
+ res = KeyValPair.search(line)
+ if res and lang != '':
+ key = res.group(1)
+ val = res.group(2)
+ key = key.replace('\\"', '"').replace('\\\\', '\\')
+ val = val.replace('\\"', '"').replace('\\\\', '\\')
+ oldtrans[lang][key] = val
+ keyset.add(key)
+ continue
+ print("Error: Unable to handle line:")
+ print(line)
+ except IOError:
+ print("Warning: Unable to open %s for reading." % output)
+ print(" Old translations will be lost.")
+
+ # walon is not a known document language
+ # FIXME: Do not hardcode, read from lib/languages!
+ if 'wa' in languages:
+ languages.remove('wa')
+
+ if layouttranslations:
+ out = io.open(output, 'w', encoding='utf_8')
+ else:
+ out = io.open(output, 'w', encoding='utf_8', newline='\n')