+ res = CounterFormat.search(line)
+ if res != None:
+ string = res.group(1)
+ if not layouttranslations:
+ writeString(out, src, base, lineno, string)
+ continue
+ res = Float.search(line)
+ if res != None:
+ readingFloat = True
+ continue
+ 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:
+ # If a float is predefined by the package and it does not need
+ # the float package then it uses the standard babel translations.
+ # This is even true for MarginFigure, MarginTable (both from
+ # tufte-book.layout) and Planotable, Plate (both from aguplus.inc).
+ if layouttranslations and readingFloat and usesFloatPkg and not isPredefined:
+ 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 >> out, '''# 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.'''
+ for lang in languages:
+ print >> out, '\nTranslation %s' % lang
+ if lang in 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 trans.keys():
+ val = trans[key].replace('\\', '\\\\').replace('"', '\\"')
+ key = key.replace('\\', '\\\\').replace('"', '\\"')
+ print >> out, '\t"%s" "%s"' % \
+ (key.encode('utf-8'), val.encode('utf-8'))
+ # 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 >> out, '\t"%s" "%s"' % \
+ (key.encode('utf-8'), val.encode('utf-8'))
+ print >> out, 'End'
+