+ res = IsPredefined.search(line)
+ if res != None:
+ string = res.group(1).lower()
+ if string == 'true':
+ isPredefined = True
+ else:
+ isPredefined = False
+ continue
+ res = UsesFloatPkg.search(line)
+ if res != None:
+ string = res.group(1).lower()
+ if string == 'true':
+ usesFloatPkg = True
+ else:
+ usesFloatPkg = False
+ continue
+ res = CiteFormat.search(line)
+ if res != None:
+ readingCiteFormats = True
+ continue
+ res = End.search(line)
+ if res != None:
+ # We have four combinations of the flags usesFloatPkg and isPredefined:
+ # usesFloatPkg and isPredefined: might use standard babel translations
+ # usesFloatPkg and not isPredefined: does not use standard babel translations
+ # not usesFloatPkg and isPredefined: uses standard babel translations
+ # not usesFloatPkg and not isPredefined: not supported by LyX
+ # The third combination is even true for MarginFigure, MarginTable (both from
+ # tufte-book.layout) and Planotable, Plate (both from aguplus.inc).
+ if layouttranslations and readingFloat and usesFloatPkg:
+ if floatname != '':
+ keyset.add(floatname)
+ if listname != '':
+ keyset.add(listname)
+ isPredefined = False
+ usesFloatPkg = True
+ listname = ''
+ floatname = ''
+ readingCiteFormats = False
+ readingFloat = False
+ continue
+ if readingCiteFormats:
+ res = KeyVal.search(line)
+ if res != None:
+ val = res.group(1)
+ if not layouttranslations:
+ writeString(out, src, base, lineno, val)
+
+ if layouttranslations:
+ # Extract translations of layout files
+ import polib
+
+ # Sort languages and key to minimize the diff between different runs
+ # with changed translations
+ languages.sort()
+ keys = []
+ for key in keyset:
+ keys.append(key)
+ keys.sort()
+
+ ContextRe = re.compile(r'(.*)(\[\[.*\]\])')
+
+ print(u'''# This file has been automatically generated by po/lyx_pot.py.
+# PLEASE MODIFY ONLY THE LAGUAGES HAVING NO .po FILE! If you want to regenerate
+# this file from the translations, run `make ../lib/layouttranslations' in po.
+# Python polib library is needed for building the output file.
+#
+# This file should remain fixed during minor LyX releases.
+# For more comments see README.localization file.''', file=out)
+ for lang in languages:
+ print(u'\nTranslation %s' % lang, file=out)
+ if lang in list(oldtrans.keys()):
+ trans = oldtrans[lang]
+ else:
+ trans = dict()
+ if not lang in oldlanguages:
+ poname = os.path.join(base, 'po/' + lang + '.po')
+ po = polib.pofile(poname)
+ # Iterate through po entries and not keys for speed reasons.
+ # FIXME: The code is still too slow
+ for entry in po:
+ if not entry.translated():
+ continue
+ if entry.msgid in keys:
+ key = entry.msgid
+ val = entry.msgstr
+ # some translators keep untranslated entries
+ if val != key:
+ trans[key] = val
+ for key in keys:
+ if key in list(trans.keys()):
+ val = trans[key].replace('\\', '\\\\').replace('"', '\\"')
+ res = ContextRe.search(val)
+ if res != None:
+ val = res.group(1)
+ key = key.replace('\\', '\\\\').replace('"', '\\"')
+ print(u'\t"%s" "%s"' % (key, val), file=out)
+ # also print untranslated entries to help translators
+ elif not lang in oldlanguages:
+ key = key.replace('\\', '\\\\').replace('"', '\\"')
+ res = ContextRe.search(key)
+ if res != None:
+ val = res.group(1)
+ else:
+ val = key
+ print(u'\t"%s" "%s"' % (key, val), file=out)
+ print(u'End', file=out)
+