Update po generating file, make sure py.in is present

svn: r20500
This commit is contained in:
Benny Malengier 2012-10-03 12:16:06 +00:00
parent 91e6df28c1
commit 6fc289a956

View File

@ -20,7 +20,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import print_function
import os import os
import sys import sys
@ -41,6 +41,9 @@ elif sys.platform == 'linux2' or os.name == 'darwin':
msgattribCmd = 'msgattrib' msgattribCmd = 'msgattrib'
xgettextCmd = 'xgettext' xgettextCmd = 'xgettext'
pythonCmd = os.path.join(sys.prefix, 'bin', 'python') pythonCmd = os.path.join(sys.prefix, 'bin', 'python')
else:
print ("ERROR: unknown system, don't know msgmerge, ... commands")
sys.exit(0)
def tests(): def tests():
""" """
@ -48,46 +51,46 @@ def tests():
We made tests (-t flag) by displaying versions of tools if properly We made tests (-t flag) by displaying versions of tools if properly
installed. Cannot run all commands without 'gettext' and 'python'. installed. Cannot run all commands without 'gettext' and 'python'.
""" """
try: try:
print("\n====='msgmerge'=(merge our translation)================\n") print ("\n====='msgmerge'=(merge our translation)================\n")
os.system('''%(program)s -V''' % {'program': msgmergeCmd}) os.system('''%(program)s -V''' % {'program': msgmergeCmd})
except: except:
print('Please, install %(program)s for updating your translation' % {'program': msgmergeCmd}) print ('Please, install %(program)s for updating your translation'
% {'program': msgmergeCmd})
try: try:
print("\n==='msgfmt'=(format our translation for installation)==\n") print ("\n==='msgfmt'=(format our translation for installation)==\n")
os.system('''%(program)s -V''' % {'program': msgfmtCmd}) os.system('''%(program)s -V''' % {'program': msgfmtCmd})
except: except:
print('Please, install %(program)s for checking your translation' % {'program': msgfmtCmd}) print ('Please, install %(program)s for checking your translation'
% {'program': msgfmtCmd})
try: try:
print("\n===='msgattrib'==(list groups of messages)=============\n") print ("\n===='msgattrib'==(list groups of messages)=============\n")
os.system('''%(program)s -V''' % {'program': msgattribCmd}) os.system('''%(program)s -V''' % {'program': msgattribCmd})
except: except:
print('Please, install %(program)s for listing groups of messages' % {'program': msgattribCmd}) print ('Please, install %(program)s for listing groups of messages'
% {'program': msgattribCmd})
try: try:
print("\n===='xgettext' =(generate a new template)==============\n") print("\n===='xgettext' =(generate a new template)==============\n")
os.system('''%(program)s -V''' % {'program': xgettextCmd}) os.system('''%(program)s -V''' % {'program': xgettextCmd})
except: except:
print('Please, install %(program)s for generating a new template' % {'program': xgettextCmd}) print ('Please, install %(program)s for generating a new template'
% {'program': xgettextCmd})
try: try:
print("\n=================='python'=============================\n") print("\n=================='python'=============================\n")
os.system('''%(program)s -V''' % {'program': pythonCmd}) os.system('''%(program)s -V''' % {'program': pythonCmd})
except: except:
print('Please, install python') print ('Please, install python')
# See also 'get_string' from Gramps 2.0 (sample with SAX) # See also 'get_string' from Gramps 2.0 (sample with SAX)
def TipsParse(filename, mark): def TipsParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'tips.xml'. Experimental alternative to 'intltool-extract' for 'tips.xml'.
""" """
# in progress ... # in progress ...
from xml.etree import ElementTree from xml.etree import ElementTree
@ -123,14 +126,8 @@ def TipsParse(filename, mark):
''' '''
tips = open('../gramps/data/tips.xml.in.h', 'w') tips = open('../gramps/data/tips.xml.in.h', 'w')
marklist = root.iter(mark)
# python 2.7 for key in marklist:
# iter() is the new name for getiterator;
# in ET 1.3, it is implemented as a generator method,
# but is otherwise identical
# it works with python 2.6 only !
for key in root.getiterator(mark):
tip = ElementTree.tostring(key, encoding="UTF-8") tip = ElementTree.tostring(key, encoding="UTF-8")
tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "") tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "")
tip = tip.replace('\n<_tip number="%(number)s">' % key.attrib, "") tip = tip.replace('\n<_tip number="%(number)s">' % key.attrib, "")
@ -140,35 +137,20 @@ def TipsParse(filename, mark):
tip = tip.replace("</_tip>\n\n", "") tip = tip.replace("</_tip>\n\n", "")
tip = tip.replace('"', '&quot;') tip = tip.replace('"', '&quot;')
tips.write('char *s = N_("%s");\n' % tip) tips.write('char *s = N_("%s");\n' % tip)
tips.close() tips.close()
print ('Wrote ../gramps/data/tips.xml.in.h')
root.clear() root.clear()
def HolidaysParse(filename, mark): def HolidaysParse(filename, mark):
""" """
Experimental alternative to 'intltool-extract' for 'holidays.xml'. Experimental alternative to 'intltool-extract' for 'holidays.xml'.
""" """
# in progress ... # in progress ...
from xml.etree import ElementTree from xml.etree import ElementTree
tree = ElementTree.parse(filename) tree = ElementTree.parse(filename)
root = tree.getroot() root = tree.getroot()
ellist = root.iter()
python_v = sys.version_info
# python 2.7
# iter() is the new name for getiterator;
# in ET 1.3, it is implemented as a generator method,
# but is otherwise identical
# getiterator() for python 2.6
ITERATION = root.getiterator()
# iter() for python 2.7 and greater versions
if sys.version_info[1] ==7:
ITERATION = root.iter()
''' '''
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
@ -189,19 +171,16 @@ def HolidaysParse(filename, mark):
''' '''
holidays = open('../gramps/plugins/lib/holidays.xml.in.h', 'w') holidays = open('../gramps/plugins/lib/holidays.xml.in.h', 'w')
for key in ellist:
for key in ITERATION:
if key.attrib.get(mark): if key.attrib.get(mark):
line = key.attrib line = key.attrib
string = line.items string = line.items
name = 'char *s = N_("%(_name)s");\n' % line name = 'char *s = N_("%(_name)s");\n' % line
holidays.write(name) holidays.write(name)
holidays.close() holidays.close()
print ('Wrote ../gramps/plugins/lib/holidays.xml.in.h')
root.clear() root.clear()
def main(): def main():
""" """
The utility for handling translation stuff. The utility for handling translation stuff.
@ -236,37 +215,37 @@ def main():
parser.add_option_group(trans) parser.add_option_group(trans)
parser.add_option("-t", "--test", parser.add_option("-t", "--test",
action="store_true", dest="test", default=False, action="store_true", dest="test", default=False,
help="test if 'python' and 'gettext' are properly installed") help="test if 'python' and 'gettext' are properly installed")
extract.add_option("-x", "--xml", extract.add_option("-x", "--xml",
action="store_true", dest="xml", default=False, action="store_true", dest="xml", default=False,
help="extract messages from xml based file formats") help="extract messages from xml based file formats")
extract.add_option("-g", "--glade", extract.add_option("-g", "--glade",
action="store_true", dest="glade", default=False, action="store_true", dest="glade", default=False,
help="extract messages from glade file format only") help="extract messages from glade file format only")
extract.add_option("-c", "--clean", extract.add_option("-c", "--clean",
action="store_true", dest="clean", default=False, action="store_true", dest="clean", default=False,
help="remove created files") help="remove created files")
extract.add_option("-p", "--pot", extract.add_option("-p", "--pot",
action="store_true", dest="catalog", default=False, action="store_true", dest="catalog", default=False,
help="create a new catalog") help="create a new catalog")
# need at least one argument (sv.po, de.po, etc ...) # need at least one argument (sv.po, de.po, etc ...)
update.add_option("-m", "--merge", update.add_option("-m", "--merge",
action="store_true", dest="merge", default=False, action="store_true", dest="merge", default=False,
help="merge lang.po files with last catalog") help="merge lang.po files with last catalog")
update.add_option("-k", "--check", update.add_option("-k", "--check",
action="store_true", dest="check", default=False, action="store_true", dest="check", default=False,
help="check lang.po files") help="check lang.po files")
# testing stage # testing stage
trans.add_option("-u", "--untranslated", trans.add_option("-u", "--untranslated",
action="store_true", dest="untranslated", default=False, action="store_true", dest="untranslated", default=False,
help="list untranslated messages") help="list untranslated messages")
trans.add_option("-f", "--fuzzy", trans.add_option("-f", "--fuzzy",
action="store_true", dest="fuzzy", default=False, action="store_true", dest="fuzzy", default=False,
help="list fuzzy messages") help="list fuzzy messages")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -297,7 +276,7 @@ def main():
if options.fuzzy: if options.fuzzy:
fuzzy(args) fuzzy(args)
def listing(name, extension): def listing(name, extensionlist):
""" """
List files according to extensions. List files according to extensions.
Parsing from a textual file (gramps) is faster and easy for maintenance. Parsing from a textual file (gramps) is faster and easy for maintenance.
@ -311,21 +290,20 @@ def listing(name, extension):
temp = open(name, 'w') temp = open(name, 'w')
for entry in files: for entry in files:
(module, ext) = os.path.splitext(entry) for ext in extensionlist:
if ext == extension: if entry.endswith(ext):
temp.write(entry) temp.write(entry)
temp.write('\n') temp.write('\n')
break
temp.close() temp.close()
def headers(): def headers():
""" """
Look at existing C file format headers. Look at existing C file format headers.
Generated by 'intltool-extract' but want to get rid of this Generated by 'intltool-extract' but want to get rid of this
dependency (perl, just a set of tools). dependency (perl, just a set of tools).
""" """
headers = [] headers = []
# in.h; extract_xml # in.h; extract_xml
@ -344,14 +322,12 @@ def headers():
return headers return headers
def extract_xml(): def extract_xml():
""" """
Extract translation strings from XML based, keys, mime and desktop Extract translation strings from XML based, keys, mime and desktop
files. Still performed by 'intltool-update'. files. Still performed by 'intltool-update'.
Need to look at own XML files parsing and custom translation marks. Need to look at own XML files parsing and custom translation marks.
""" """
#os.system('''intltool-extract --type=gettext/xml ../gramps/data/tips.xml.in''') #os.system('''intltool-extract --type=gettext/xml ../gramps/data/tips.xml.in''')
#os.system('''intltool-extract --type=gettext/xml ../gramps/plugins/lib/holidays.xml.in''') #os.system('''intltool-extract --type=gettext/xml ../gramps/plugins/lib/holidays.xml.in''')
@ -364,42 +340,37 @@ def extract_xml():
os.system('''intltool-extract --type=gettext/ini ../data/gramps.desktop.in''') os.system('''intltool-extract --type=gettext/ini ../data/gramps.desktop.in''')
os.system('''intltool-extract --type=gettext/keys ../data/gramps.keys.in''') os.system('''intltool-extract --type=gettext/keys ../data/gramps.keys.in''')
def create_template(): def create_template():
""" """
Create a new file for template, if it does not exist. Create a new file for template, if it does not exist.
""" """
template = open('gramps.pot', 'w') template = open('gramps.pot', 'w')
template.close() template.close()
def extract_glade(): def extract_glade():
""" """
Extract messages from a temp file with all .glade Extract messages from a temp file with all .glade
""" """
if not os.path.isfile('gramps.pot'): if not os.path.isfile('gramps.pot'):
create_template() create_template()
listing('glade.txt', '.glade') listing('glade.txt', ['.glade'])
os.system('''%(xgettext)s --add-comments -j -L Glade ''' os.system('''%(xgettext)s --add-comments -j -L Glade '''
'''--from-code=UTF-8 -o gramps.pot --files-from=glade.txt''' '''--from-code=UTF-8 -o gramps.pot --files-from=glade.txt'''
% {'xgettext': xgettextCmd} % {'xgettext': xgettextCmd}
) )
def retrieve(): def retrieve():
""" """
Extract messages from all files used by Gramps (python, glade, xml) Extract messages from all files used by Gramps (python, glade, xml)
""" """
extract_xml() extract_xml()
if not os.path.isfile('gramps.pot'): if not os.path.isfile('gramps.pot'):
create_template() create_template()
listing('python.txt', '.py') listing('python.txt', ['.py', '.py.in'])
os.system('''%(xgettext)s --add-comments -j --directory=./ -d gramps ''' os.system('''%(xgettext)s --add-comments -j --directory=./ -d gramps '''
'''-L Python -o gramps.pot --files-from=python.txt ''' '''-L Python -o gramps.pot --files-from=python.txt '''
'''--keyword=_ --keyword=ngettext ''' '''--keyword=_ --keyword=ngettext '''
@ -410,77 +381,70 @@ def retrieve():
# C format header (.h extension) # C format header (.h extension)
for h in headers(): for h in headers():
print('xgettext for %s') % h print ('xgettext for %s' % h)
os.system('''%(xgettext)s --add-comments -j -o gramps.pot ''' os.system('''%(xgettext)s --add-comments -j -o gramps.pot '''
'''--keyword=N_ --from-code=UTF-8 %(head)s''' '''--keyword=N_ --from-code=UTF-8 %(head)s'''
% {'xgettext': xgettextCmd, 'head': h} % {'xgettext': xgettextCmd, 'head': h}
) )
clean() clean()
def clean(): def clean():
""" """
Remove created files (C format headers, temp listings) Remove created files (C format headers, temp listings)
""" """
for h in headers(): for h in headers():
if os.path.isfile(h): if os.path.isfile(h):
os.unlink(h) os.unlink(h)
print('Remove %(head)s' % {'head': h}) print ('Remove %(head)s' % {'head': h})
if os.path.isfile('python.txt'): if os.path.isfile('python.txt'):
os.unlink('python.txt') os.unlink('python.txt')
print("Remove 'python.txt'") print ("Remove 'python.txt'")
if os.path.isfile('glade.txt'): if os.path.isfile('glade.txt'):
os.unlink('glade.txt') os.unlink('glade.txt')
print("Remove 'glade.txt'") print ("Remove 'glade.txt'")
def merge(args): def merge(args):
""" """
Merge messages with 'gramps.pot' Merge messages with 'gramps.pot'
""" """
if not args: if not args:
print('Please, add at least one argument (sv.po, de.po).') print ('Please, add at least one argument (sv.po, de.po).')
for arg in args: for arg in args:
if arg[-3:] == '.po': if arg[-3:] == '.po':
print('Merge %(lang)s with current template' % {'lang': arg}) print ('Merge %(lang)s with current template' % {'lang': arg})
os.system('''%(msgmerge)s --no-wrap %(lang)s gramps.pot -o updated_%(lang)s''' \ os.system('''%(msgmerge)s --no-wrap %(lang)s gramps.pot -o updated_%(lang)s''' \
% {'msgmerge': msgmergeCmd, 'lang': arg}) % {'msgmerge': msgmergeCmd, 'lang': arg})
print("Updated file: 'updated_%(lang)s'." % {'lang': arg}) print ("Updated file: 'updated_%(lang)s'." % {'lang': arg})
else: else:
print("Please, try to set an argument with .po extension like '%(arg)s.po'." % {'arg': arg}) print ("Please, try to set an argument with .po extension like "
"'%(arg)s.po'." % {'arg': arg})
def check(args): def check(args):
""" """
Check the translation file Check the translation file
""" """
if not args: if not args:
print('Please, add at least one argument (sv.po, de.po).') print ('Please, add at least one argument (sv.po, de.po).')
for arg in args: for arg in args:
if arg[-3:] == '.po': if arg[-3:] == '.po':
print("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \ print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \
% {'lang.po': arg, 'txt': arg[:2]}) % {'lang.po': arg, 'txt': arg[:2]})
os.system('''%(python)s ./check_po --skip-fuzzy ./%(lang.po)s > %(lang)s.txt''' \ os.system('''%(python)s ./check_po --skip-fuzzy ./%(lang.po)s > %(lang)s.txt''' \
% {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:2]}) % {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:2]})
os.system('''%(msgfmt)s -c -v %(lang.po)s''' % {'msgfmt': msgfmtCmd, 'lang.po': arg}) os.system('''%(msgfmt)s -c -v %(lang.po)s''' % {'msgfmt': msgfmtCmd, 'lang.po': arg})
else: else:
print("Please, try to set an argument with .po extension like '%(arg)s.po'." % {'arg': arg}) print ("Please, try to set an argument with .po extension like "
"'%(arg)s.po'." % {'arg': arg})
def untranslated(args): def untranslated(args):
""" """
List untranslated messages List untranslated messages
""" """
if len(args) > 1: if len(args) > 1:
print('Please, use only one argument (ex: fr.po).') print ('Please, use only one argument (ex: fr.po).')
return return
os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': args[0]}) os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': args[0]})
@ -489,9 +453,8 @@ def fuzzy(args):
""" """
List fuzzy messages List fuzzy messages
""" """
if len(args) > 1: if len(args) > 1:
print('Please, use only one argument (ex: fr.po).') print ('Please, use only one argument (ex: fr.po).')
return return
os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': args[0]}) os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': args[0]})