# This script will extract translatable strings from input files and write
# to output in gettext .pot format.
#
# This script will extract translatable strings from input files and write
# to output in gettext .pot format.
#
import sys, os, re, getopt
import sys, os, re, getopt
def relativePath(path, base):
'''return relative path from top source dir'''
def relativePath(path, base):
'''return relative path from top source dir'''
path1 = os.path.normpath(os.path.realpath(path)).split(os.sep)
path2 = os.path.normpath(os.path.realpath(base)).split(os.sep)
if path1[:len(path2)] != path2:
path1 = os.path.normpath(os.path.realpath(path)).split(os.sep)
path2 = os.path.normpath(os.path.realpath(base)).split(os.sep)
if path1[:len(path2)] != path2:
path3 = os.path.join(*path1[len(path2):]);
# replace all \ by / such that we get the same comments on Windows and *nix
path3 = path3.replace('\\', '/')
path3 = os.path.join(*path1[len(path2):]);
# replace all \ by / such that we get the same comments on Windows and *nix
path3 = path3.replace('\\', '/')
- print >> outfile, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(infile, basefile), lineno, string)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(infile, basefile), lineno, string), file=outfile)
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(src, base), lineno+1, string)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(src, base), lineno+1, string), file=output)
# 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)
# 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)
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)
InsetLayout = re.compile(r'^InsetLayout\s+\"?(.*)\"?\s*$', re.IGNORECASE)
FlexCheck = re.compile(r'^Flex:(.*)', 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)
InsetLayout = re.compile(r'^InsetLayout\s+\"?(.*)\"?\s*$', re.IGNORECASE)
FlexCheck = re.compile(r'^Flex:(.*)', re.IGNORECASE)
DescBegin = re.compile(r'^\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)
DescBegin = re.compile(r'^\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)
- print "Warning: Unable to open %s for reading." % output
- print " Old translations will be lost."
+ 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!
# walon is not a known document language
# FIXME: Do not hardcode, read from lib/languages!
#if not layouttranslations:
# writeString(out, src, base, lineno, string)
m = FlexCheck.search(string)
#if not layouttranslations:
# writeString(out, src, base, lineno, string)
m = FlexCheck.search(string)
+ if m:
+ if not layouttranslations:
+ writeString(out, src, base, lineno, m.group(1))
+ m = CaptionCheck.search(string)
if m:
if not layouttranslations:
writeString(out, src, base, lineno, m.group(1))
if m:
if not layouttranslations:
writeString(out, src, base, lineno, m.group(1))
- # 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
+ # 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
# 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.
# 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.
- print >> out, '\nTranslation %s' % lang
- if lang in oldtrans.keys():
+ print('\nTranslation %s' % lang, file=out)
+ if lang in list(oldtrans.keys()):
- print >> out, '\t"%s" "%s"' % \
- (key.encode('utf-8'), val.encode('utf-8'))
+ print('\t"%s" "%s"' % \
+ (key.encode('utf-8'), val.encode('utf-8')), file=out)
# also print untranslated entries to help translators
elif not lang in oldlanguages:
key = key.replace('\\', '\\\\').replace('"', '\\"')
# also print untranslated entries to help translators
elif not lang in oldlanguages:
key = key.replace('\\', '\\\\').replace('"', '\\"')
- print >> out, '\t"%s" "%s"' % \
- (key.encode('utf-8'), val.encode('utf-8'))
- print >> out, 'End'
+ print('\t"%s" "%s"' % \
+ (key.encode('utf-8'), val.encode('utf-8')), file=out)
+ print('End', file=out)
string = string.replace('<', '<').replace('>', '>')
string = string.replace('\\', '\\\\').replace('"', r'\"')
string = string.replace('
', r'\n')
string = string.replace('<', '<').replace('>', '>')
string = string.replace('\\', '\\\\').replace('"', r'\"')
string = string.replace('
', r'\n')
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(src, base), lineno+1, string)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(src, base), lineno+1, string), file=output)
Template = re.compile(r'^Template\s+(.*)', re.IGNORECASE)
GuiName = re.compile(r'\s*GuiName\s+(.*)', re.IGNORECASE)
HelpTextStart = re.compile(r'\s*HelpText\s', re.IGNORECASE)
Template = re.compile(r'^Template\s+(.*)', re.IGNORECASE)
GuiName = re.compile(r'\s*GuiName\s+(.*)', re.IGNORECASE)
HelpTextStart = re.compile(r'\s*HelpText\s', re.IGNORECASE)
(help_string,) = HelpTextSection.match(line).groups()
help_string = help_string.replace('"', '')
if help_string != "" and prev_help_string == '':
(help_string,) = HelpTextSection.match(line).groups()
help_string = help_string.replace('"', '')
if help_string != "" and prev_help_string == '':
- print >> output, '#: %s:%d\nmsgid ""\n"%s\\n"' % \
- (relativePath(src, base), lineno+1, help_string)
+ print('#: %s:%d\nmsgid ""\n"%s\\n"' % \
+ (relativePath(src, base), lineno+1, help_string), file=output)
continue
string = string.replace('"', '')
if string != "" and not inHelp:
continue
string = string.replace('"', '')
if string != "" and not inHelp:
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(src, base), lineno+1, string)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(src, base), lineno+1, string), file=output)
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(input_files[0], base), lineno+1, label)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, label), file=output)
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(input_files[0], base), lineno+1, labelsc)
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, labelsc), file=output)
output = open(output, 'w')
# assuming only one encodings file
# Encoding utf8 utf8 "Unicode (utf8)" UTF-8 variable inputenc
output = open(output, 'w')
# assuming only one encodings file
# Encoding utf8 utf8 "Unicode (utf8)" UTF-8 variable inputenc
input = open(input_files[0])
for lineno, line in enumerate(input.readlines()):
if not line.startswith('Encoding'):
continue
if reg.match(line):
input = open(input_files[0])
for lineno, line in enumerate(input.readlines()):
if not line.startswith('Encoding'):
continue
if reg.match(line):
- print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
- (relativePath(input_files[0], base), lineno+1, reg.match(line).groups()[0])
+ print('#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
+ (relativePath(input_files[0], base), lineno+1, reg.match(line).groups()[0]), file=output)
['help', 'type=', 'output=', 'base=', 'src_file='])
for (opt, value) in optlist:
if opt in ['-h', '--help']:
['help', 'type=', 'output=', 'base=', 'src_file='])
for (opt, value) in optlist:
if opt in ['-h', '--help']:
input_files = [f.strip() for f in open(value)]
if input_type not in ['ui', 'layouts', 'layouttranslations', 'qt4', 'languages', 'latexfonts', 'encodings', 'external', 'formats'] or output is None:
input_files = [f.strip() for f in open(value)]
if input_type not in ['ui', 'layouts', 'layouttranslations', 'qt4', 'languages', 'latexfonts', 'encodings', 'external', 'formats'] or output is None: