# 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)
- 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!
# 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()):
val = trans[key].replace('\\', '\\\\').replace('"', '\\"')
res = ContextRe.search(val)
if res != None:
val = res.group(1)
key = key.replace('\\', '\\\\').replace('"', '\\"')
val = trans[key].replace('\\', '\\\\').replace('"', '\\"')
res = ContextRe.search(val)
if res != None:
val = res.group(1)
key = key.replace('\\', '\\\\').replace('"', '\\"')
- 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)
(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)
- 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: