2012-03-12 22:13:12 +05:30
|
|
|
#! /usr/bin/env python
|
|
|
|
#
|
2012-03-15 22:41:31 +05:30
|
|
|
# update_po - a gramps tool to update translations
|
2012-03-12 22:13:12 +05:30
|
|
|
#
|
|
|
|
# Copyright (C) 2006-2006 Kees Bakker
|
2012-03-14 19:40:21 +05:30
|
|
|
# Copyright (C) 2006 Brian Matherly
|
|
|
|
# Copyright (C) 2008 Stephen George
|
2012-03-12 22:13:12 +05:30
|
|
|
# Copyright (C) 2012
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2013-05-06 01:10:56 +05:30
|
|
|
#
|
|
|
|
# $Id$
|
2012-10-16 14:21:05 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
update_po.py for Gramps translations.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
python update_po.py -t
|
|
|
|
|
|
|
|
Tests if 'gettext' and 'python' are well configured.
|
|
|
|
|
|
|
|
python update_po.py -h
|
|
|
|
|
|
|
|
Calls help and command line interface.
|
|
|
|
|
|
|
|
python update_po.py -p
|
|
|
|
|
|
|
|
Generates a new template/catalog (gramps.pot).
|
|
|
|
|
|
|
|
python update_po.py -m de.po
|
|
|
|
|
|
|
|
Merges 'de.po' file with 'gramps.pot'.
|
|
|
|
|
|
|
|
python update_po.py -k de.po
|
|
|
|
|
|
|
|
Checks 'de.po' file, tests to compile and generates a textual resume.
|
|
|
|
"""
|
|
|
|
|
2012-10-03 17:46:06 +05:30
|
|
|
from __future__ import print_function
|
2012-03-12 22:13:12 +05:30
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2012-12-01 02:03:44 +05:30
|
|
|
from argparse import ArgumentParser
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-12-14 02:13:32 +05:30
|
|
|
# Windows OS
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
if sys.platform == 'win32':
|
|
|
|
# GetText Win 32 obtained from http://gnuwin32.sourceforge.net/packages/gettext.htm
|
|
|
|
# ....\gettext\bin\msgmerge.exe needs to be on the path
|
2012-03-29 14:49:54 +05:30
|
|
|
msgmergeCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'msgmerge.exe')
|
|
|
|
msgfmtCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'msgfmt.exe')
|
|
|
|
msgattribCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'msgattrib.exe')
|
2012-03-20 00:16:50 +05:30
|
|
|
xgettextCmd = os.path.join('C:', 'Program Files(x86)', 'gettext', 'bin', 'xgettext.exe')
|
2012-03-29 14:49:54 +05:30
|
|
|
pythonCmd = os.path.join(sys.prefix, 'bin', 'python.exe')
|
2012-12-14 02:13:32 +05:30
|
|
|
|
|
|
|
# Others OS
|
|
|
|
|
2013-02-24 06:24:18 +05:30
|
|
|
elif sys.platform in ['linux2', 'darwin', 'cygwin']:
|
2012-03-15 22:41:31 +05:30
|
|
|
msgmergeCmd = 'msgmerge'
|
|
|
|
msgfmtCmd = 'msgfmt'
|
2012-03-19 21:30:19 +05:30
|
|
|
msgattribCmd = 'msgattrib'
|
2012-03-17 00:05:35 +05:30
|
|
|
xgettextCmd = 'xgettext'
|
2012-03-29 14:49:54 +05:30
|
|
|
pythonCmd = os.path.join(sys.prefix, 'bin', 'python')
|
2012-10-03 17:46:06 +05:30
|
|
|
else:
|
2013-02-24 06:24:18 +05:30
|
|
|
print("Found platform %s, OS %s" % (sys.platform, os.name))
|
|
|
|
print ("Update PO ERROR: unknown system, don't know msgmerge, ... commands")
|
2012-10-03 17:46:06 +05:30
|
|
|
sys.exit(0)
|
2012-12-14 02:13:32 +05:30
|
|
|
|
|
|
|
# List of available languages, useful for grouped actions
|
|
|
|
|
|
|
|
# need files with po extension
|
2012-12-02 22:52:40 +05:30
|
|
|
LANG = [file for file in os.listdir('.') if file.endswith('.po')]
|
2012-12-14 02:13:32 +05:30
|
|
|
# add a special 'all' argument (for 'check' and 'merge' arguments)
|
2012-12-02 22:52:40 +05:30
|
|
|
LANG.append("all")
|
2012-12-14 02:13:32 +05:30
|
|
|
# visual polish on the languages list
|
2012-12-02 22:52:40 +05:30
|
|
|
LANG.sort()
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
def tests():
|
|
|
|
"""
|
|
|
|
Testing installed programs.
|
|
|
|
We made tests (-t flag) by displaying versions of tools if properly
|
|
|
|
installed. Cannot run all commands without 'gettext' and 'python'.
|
|
|
|
"""
|
|
|
|
try:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ("\n====='msgmerge'=(merge our translation)================\n")
|
2012-03-15 22:41:31 +05:30
|
|
|
os.system('''%(program)s -V''' % {'program': msgmergeCmd})
|
|
|
|
except:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Please, install %(program)s for updating your translation'
|
|
|
|
% {'program': msgmergeCmd})
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
try:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ("\n==='msgfmt'=(format our translation for installation)==\n")
|
2012-03-15 22:41:31 +05:30
|
|
|
os.system('''%(program)s -V''' % {'program': msgfmtCmd})
|
|
|
|
except:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Please, install %(program)s for checking your translation'
|
|
|
|
% {'program': msgfmtCmd})
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
try:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ("\n===='msgattrib'==(list groups of messages)=============\n")
|
2012-03-19 21:30:19 +05:30
|
|
|
os.system('''%(program)s -V''' % {'program': msgattribCmd})
|
|
|
|
except:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Please, install %(program)s for listing groups of messages'
|
|
|
|
% {'program': msgattribCmd})
|
2012-03-19 21:30:19 +05:30
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
print("\n===='xgettext' =(generate a new template)==============\n")
|
2012-03-17 00:05:35 +05:30
|
|
|
os.system('''%(program)s -V''' % {'program': xgettextCmd})
|
|
|
|
except:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Please, install %(program)s for generating a new template'
|
|
|
|
% {'program': xgettextCmd})
|
2012-03-17 00:05:35 +05:30
|
|
|
|
|
|
|
try:
|
2012-03-19 21:30:19 +05:30
|
|
|
print("\n=================='python'=============================\n")
|
2012-03-15 22:41:31 +05:30
|
|
|
os.system('''%(program)s -V''' % {'program': pythonCmd})
|
|
|
|
except:
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Please, install python')
|
2012-03-19 21:30:19 +05:30
|
|
|
|
2012-12-14 02:13:32 +05:30
|
|
|
|
2012-03-29 11:59:55 +05:30
|
|
|
def TipsParse(filename, mark):
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
2012-03-29 11:59:55 +05:30
|
|
|
Experimental alternative to 'intltool-extract' for 'tips.xml'.
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
2012-10-05 00:05:40 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
tree = ElementTree.parse(filename)
|
|
|
|
root = tree.getroot()
|
|
|
|
|
2012-03-19 21:30:19 +05:30
|
|
|
'''
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<tips>
|
|
|
|
<_tip number="1">
|
|
|
|
<b>Working with Dates</b>
|
|
|
|
<br/>
|
|
|
|
A range of dates can be given by using the format "between
|
|
|
|
January 4, 2000 and March 20, 2003". You can also indicate
|
|
|
|
the level of confidence in a date and even choose between seven
|
|
|
|
different calendars. Try the button next to the date field in the
|
|
|
|
Events Editor.
|
|
|
|
</_tip>
|
2012-03-29 11:59:55 +05:30
|
|
|
|
|
|
|
char *s = N_("<b>Working with Dates</b><br/>A range of dates can be
|
|
|
|
given by using the format "between January 4, 2000 and March 20,
|
|
|
|
2003". You can also indicate the level of confidence in a date
|
|
|
|
and even choose between seven different calendars. Try the button
|
|
|
|
next to the date field in the Events Editor.");
|
|
|
|
|
2012-03-19 21:30:19 +05:30
|
|
|
gramps.pot:
|
|
|
|
msgid ""
|
|
|
|
"<b>Working with Dates</b><br/>A range of dates can be given by using the "
|
|
|
|
"format "between January 4, 2000 and March 20, 2003". You can also "
|
|
|
|
"indicate the level of confidence in a date and even choose between seven "
|
|
|
|
"different calendars. Try the button next to the date field in the Events "
|
|
|
|
"Editor."
|
|
|
|
'''
|
|
|
|
|
2013-01-05 20:06:49 +05:30
|
|
|
tips = open('../data/tips.xml.in.h', 'w')
|
2012-10-03 17:46:06 +05:30
|
|
|
marklist = root.iter(mark)
|
|
|
|
for key in marklist:
|
2012-03-19 21:30:19 +05:30
|
|
|
tip = ElementTree.tostring(key, encoding="UTF-8")
|
|
|
|
tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "")
|
2012-03-29 11:59:55 +05:30
|
|
|
tip = tip.replace('\n<_tip number="%(number)s">' % key.attrib, "")
|
2012-03-19 21:30:19 +05:30
|
|
|
tip = tip.replace("<br />", "<br/>")
|
2012-10-07 22:15:58 +05:30
|
|
|
#tip = tip.replace("\n</_tip>\n", "</_tip>\n") # special case tip 7
|
|
|
|
#tip = tip.replace("\n<b>", "<b>") # special case tip 18
|
2012-03-19 21:30:19 +05:30
|
|
|
tip = tip.replace("</_tip>\n\n", "")
|
2012-03-29 11:59:55 +05:30
|
|
|
tip = tip.replace('"', '"')
|
|
|
|
tips.write('char *s = N_("%s");\n' % tip)
|
|
|
|
tips.close()
|
2013-01-05 19:54:51 +05:30
|
|
|
print ('Wrote ../data/tips.xml.in.h')
|
2012-03-29 11:59:55 +05:30
|
|
|
root.clear()
|
|
|
|
|
|
|
|
def HolidaysParse(filename, mark):
|
|
|
|
"""
|
|
|
|
Experimental alternative to 'intltool-extract' for 'holidays.xml'.
|
|
|
|
"""
|
2012-10-05 00:05:40 +05:30
|
|
|
|
2012-03-29 11:59:55 +05:30
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
tree = ElementTree.parse(filename)
|
|
|
|
root = tree.getroot()
|
2012-10-03 17:46:06 +05:30
|
|
|
ellist = root.iter()
|
2012-03-29 11:59:55 +05:30
|
|
|
|
2012-03-19 21:30:19 +05:30
|
|
|
'''
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
calendar>
|
|
|
|
<country _name="Bulgaria">
|
|
|
|
..
|
|
|
|
<country _name="Jewish Holidays">
|
|
|
|
<date _name="Yom Kippur" value="> passover(y)" offset="172"/>
|
2012-03-29 11:59:55 +05:30
|
|
|
|
|
|
|
char *s = N_("Bulgaria");
|
|
|
|
char *s = N_("Jewish Holidays");
|
|
|
|
char *s = N_("Yom Kippur");
|
|
|
|
|
2012-03-19 21:30:19 +05:30
|
|
|
gramps.pot:
|
|
|
|
msgid "Bulgaria"
|
|
|
|
msgid "Jewish Holidays"
|
|
|
|
msgid "Yom Kippur"
|
|
|
|
'''
|
2012-03-29 11:59:55 +05:30
|
|
|
|
2012-10-01 15:00:35 +05:30
|
|
|
holidays = open('../gramps/plugins/lib/holidays.xml.in.h', 'w')
|
2012-10-03 17:46:06 +05:30
|
|
|
for key in ellist:
|
2012-03-19 21:30:19 +05:30
|
|
|
if key.attrib.get(mark):
|
|
|
|
line = key.attrib
|
|
|
|
string = line.items
|
2012-12-14 02:13:32 +05:30
|
|
|
# mapping via the line dict (_name is the key)
|
2012-03-29 11:59:55 +05:30
|
|
|
name = 'char *s = N_("%(_name)s");\n' % line
|
|
|
|
holidays.write(name)
|
|
|
|
holidays.close()
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Wrote ../gramps/plugins/lib/holidays.xml.in.h')
|
2012-03-29 11:59:55 +05:30
|
|
|
root.clear()
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-10-05 00:05:40 +05:30
|
|
|
|
|
|
|
def XmlParse(filename, mark):
|
|
|
|
"""
|
2013-10-07 14:42:16 +05:30
|
|
|
Experimental alternative to 'intltool-extract' for 'file.xml.in'.
|
2012-10-05 00:05:40 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
tree = ElementTree.parse(filename)
|
|
|
|
root = tree.getroot()
|
|
|
|
|
|
|
|
'''
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
|
|
|
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
|
|
|
|
<mime-type type="application/x-gramps">
|
|
|
|
<_comment>Gramps database</_comment>
|
|
|
|
<glob pattern="*.grdb"/>
|
|
|
|
</mime-type>
|
|
|
|
<mime-type type="application/x-gedcom">
|
|
|
|
<_comment>GEDCOM</_comment>
|
|
|
|
<glob pattern="*.ged"/>
|
|
|
|
<glob pattern="*.gedcom"/>
|
|
|
|
<glob pattern="*.GED"/>
|
|
|
|
<glob pattern="*.GEDCOM"/>
|
|
|
|
|
|
|
|
msgid "Gramps database"
|
|
|
|
msgid "GEDCOM"
|
2013-10-07 14:42:16 +05:30
|
|
|
|
|
|
|
<_p> Gramps is a free software project and community.
|
|
|
|
We strive to produce a genealogy program that is both intuitive for hobbyists
|
|
|
|
and feature-complete for professional genealogists.
|
|
|
|
</p>
|
2012-10-05 00:05:40 +05:30
|
|
|
'''
|
|
|
|
|
2013-10-07 15:08:29 +05:30
|
|
|
head = open(filename + '.h', 'w')
|
2012-10-05 00:05:40 +05:30
|
|
|
|
|
|
|
for key in root.iter():
|
|
|
|
if key.tag == '{http://www.freedesktop.org/standards/shared-mime-info}%s' % mark:
|
|
|
|
comment = 'char *s = N_("%s");\n' % key.text
|
2013-10-07 15:08:29 +05:30
|
|
|
head.write(comment)
|
2013-10-07 14:42:16 +05:30
|
|
|
|
|
|
|
if root.tag == 'application':
|
|
|
|
for key in root.iter():
|
2013-10-07 15:08:29 +05:30
|
|
|
if key.tag == mark:
|
|
|
|
comment = 'char *s = N_("%s");\n' % key.text
|
|
|
|
head.write(comment)
|
2012-10-05 00:05:40 +05:30
|
|
|
|
2013-10-07 15:08:29 +05:30
|
|
|
head.close()
|
2013-10-07 14:42:16 +05:30
|
|
|
print ('Wrote %s' % filename)
|
2012-10-05 00:05:40 +05:30
|
|
|
root.clear()
|
|
|
|
|
|
|
|
|
|
|
|
def DesktopParse(filename):
|
|
|
|
"""
|
|
|
|
Experimental alternative to 'intltool-extract' for 'gramps.desktop'.
|
|
|
|
"""
|
|
|
|
|
|
|
|
'''
|
|
|
|
[Desktop Entry]
|
|
|
|
_Name=Gramps
|
|
|
|
_GenericName=Genealogy System
|
|
|
|
_X-GNOME-FullName=Gramps Genealogy System
|
|
|
|
_Comment=Manage genealogical information,
|
|
|
|
perform genealogical research and analysis
|
|
|
|
|
|
|
|
msgid "Gramps"
|
|
|
|
msgid "Genealogy System"
|
|
|
|
msgid "Gramps Genealogy System"
|
|
|
|
msgid ""
|
|
|
|
"Manage genealogical information,
|
|
|
|
perform genealogical research and analysis"
|
|
|
|
'''
|
|
|
|
|
|
|
|
desktop = open('../data/gramps.desktop.in.h', 'w')
|
|
|
|
|
|
|
|
f = open(filename)
|
|
|
|
lines = [file.strip() for file in f]
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
if line[0] == '_':
|
|
|
|
for i in range(len(line)):
|
|
|
|
if line[i] == '=':
|
|
|
|
val = 'char *s = N_("%s");\n' % line[i+1:len(line)]
|
|
|
|
desktop.write(val)
|
|
|
|
|
|
|
|
desktop.close()
|
|
|
|
print ('Wrote ../data/gramps.desktop.in.h')
|
|
|
|
|
|
|
|
|
|
|
|
def KeyParse(filename, mark):
|
|
|
|
"""
|
|
|
|
Experimental alternative to 'intltool-extract' for 'gramps.keys'.
|
|
|
|
"""
|
|
|
|
|
|
|
|
'''
|
|
|
|
application/x-gramps-xml:
|
2012-12-14 02:13:32 +05:30
|
|
|
_description=Gramps XML database
|
|
|
|
default_action_type=application
|
|
|
|
short_list_application_ids=gramps
|
|
|
|
short_list_application_ids_for_novice_user_level=gramps
|
|
|
|
short_list_application_ids_for_intermediate_user_level=gramps
|
|
|
|
short_list_application_ids_for_advanced_user_level=gramps
|
|
|
|
category=Documents/Genealogy
|
|
|
|
icon-filename=/usr/share/gramps/gramps.png
|
|
|
|
open=gramps %f
|
2012-10-05 00:05:40 +05:30
|
|
|
|
|
|
|
application/x-gedcom:
|
2012-12-14 02:13:32 +05:30
|
|
|
_description=GEDCOM
|
|
|
|
default_action_type=application
|
2012-10-05 00:05:40 +05:30
|
|
|
|
|
|
|
msgid "Gramps XML database"
|
|
|
|
msgid "GEDCOM"
|
|
|
|
'''
|
|
|
|
|
|
|
|
key = open('../data/gramps.keys.in.h', 'w')
|
|
|
|
|
|
|
|
f = open(filename)
|
|
|
|
lines = [file for file in f]
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
temp = []
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
for i in range(len(line)):
|
|
|
|
if line[i:i+12] == mark:
|
|
|
|
temp.append(line.strip())
|
|
|
|
|
|
|
|
for t in temp:
|
|
|
|
for i in range(len(t)):
|
|
|
|
if t[i] == '=':
|
|
|
|
val = 'char *s = N_("%s");\n' % t[i+1:len(t)]
|
|
|
|
key.write(val)
|
|
|
|
|
|
|
|
key.close()
|
|
|
|
print ('Wrote ../data/gramps.keys.in.h')
|
|
|
|
|
|
|
|
|
2012-03-12 22:13:12 +05:30
|
|
|
def main():
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
|
|
|
The utility for handling translation stuff.
|
|
|
|
What is need by Gramps, nothing more.
|
|
|
|
"""
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
parser = ArgumentParser(
|
2012-03-15 22:41:31 +05:30
|
|
|
description='This program generates a new template and '
|
2012-03-17 00:05:35 +05:30
|
|
|
'also provides some common features.',
|
2012-03-12 22:13:12 +05:30
|
|
|
)
|
2012-12-01 02:03:44 +05:30
|
|
|
parser.add_argument("-t", "--test",
|
2012-12-01 15:15:14 +05:30
|
|
|
action="store_true", dest="test", default=True,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="test if 'python' and 'gettext' are properly installed")
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
parser.add_argument("-x", "--xml",
|
|
|
|
action="store_true", dest="xml", default=False,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="extract messages from xml based file formats")
|
2012-12-01 02:03:44 +05:30
|
|
|
parser.add_argument("-g", "--glade",
|
|
|
|
action="store_true", dest="glade", default=False,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="extract messages from glade file format only")
|
2012-12-01 02:03:44 +05:30
|
|
|
parser.add_argument("-c", "--clean",
|
|
|
|
action="store_true", dest="clean", default=False,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="remove created files")
|
2012-12-01 02:03:44 +05:30
|
|
|
parser.add_argument("-p", "--pot",
|
|
|
|
action="store_true", dest="catalog", default=False,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="create a new catalog")
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
update = parser.add_argument_group('Update', 'Maintenance around translations')
|
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
# need at least one argument (sv.po, de.po, etc ...)
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
# lang.po files maintenance
|
2012-12-02 22:59:13 +05:30
|
|
|
update.add_argument("-m", dest="merge",
|
2012-12-02 22:52:40 +05:30
|
|
|
choices=LANG,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="merge lang.po files with last catalog")
|
2012-12-01 02:03:44 +05:30
|
|
|
|
2012-12-02 22:59:13 +05:30
|
|
|
update.add_argument("-k", dest="check",
|
2012-12-02 22:52:40 +05:30
|
|
|
choices=LANG,
|
2012-10-03 17:46:06 +05:30
|
|
|
help="check lang.po files")
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
# testing stage
|
2012-12-02 19:39:44 +05:30
|
|
|
trans = parser.add_argument_group('Translation', 'Display content of translations file')
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
# need one argument (eg, de.po)
|
2012-12-02 22:52:40 +05:30
|
|
|
|
2012-12-02 22:59:13 +05:30
|
|
|
trans.add_argument("-u", dest="untranslated",
|
2012-12-01 15:46:44 +05:30
|
|
|
choices=[file for file in os.listdir('.') if file.endswith('.po')],
|
2012-10-03 17:46:06 +05:30
|
|
|
help="list untranslated messages")
|
2012-12-02 22:59:13 +05:30
|
|
|
trans.add_argument("-f", dest="fuzzy",
|
2012-12-01 15:46:44 +05:30
|
|
|
choices=[file for file in os.listdir('.') if file.endswith('.po')],
|
2012-10-03 17:46:06 +05:30
|
|
|
help="list fuzzy messages")
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
|
2012-12-01 02:03:44 +05:30
|
|
|
args = parser.parse_args()
|
2012-12-01 15:15:14 +05:30
|
|
|
namespace, extra = parser.parse_known_args()
|
2012-12-01 02:03:44 +05:30
|
|
|
|
|
|
|
if args.test:
|
2012-03-15 22:41:31 +05:30
|
|
|
tests()
|
2012-03-14 19:40:21 +05:30
|
|
|
|
2012-12-01 02:03:44 +05:30
|
|
|
if args.xml:
|
2012-03-15 22:41:31 +05:30
|
|
|
extract_xml()
|
2012-03-14 19:40:21 +05:30
|
|
|
|
2012-12-01 02:03:44 +05:30
|
|
|
if args.glade:
|
2012-10-03 21:25:36 +05:30
|
|
|
create_filesfile()
|
2012-03-15 22:41:31 +05:30
|
|
|
extract_glade()
|
2012-10-03 21:25:36 +05:30
|
|
|
if os.path.isfile('tmpfiles'):
|
|
|
|
os.unlink('tmpfiles')
|
2012-03-15 22:41:31 +05:30
|
|
|
|
2012-12-01 02:03:44 +05:30
|
|
|
if args.catalog:
|
2012-03-15 22:41:31 +05:30
|
|
|
retrieve()
|
|
|
|
|
2012-12-01 02:03:44 +05:30
|
|
|
if args.clean:
|
2012-03-15 22:41:31 +05:30
|
|
|
clean()
|
|
|
|
|
2012-12-01 15:40:44 +05:30
|
|
|
if args.merge:
|
2012-12-14 02:13:32 +05:30
|
|
|
#retrieve() windows os?
|
2012-12-02 22:52:40 +05:30
|
|
|
if sys.argv[2:] == ['all']:
|
|
|
|
sys.argv[2:] = LANG
|
2012-12-01 02:03:44 +05:30
|
|
|
merge(sys.argv[2:])
|
2012-03-15 22:41:31 +05:30
|
|
|
|
2012-12-01 15:40:44 +05:30
|
|
|
if args.check:
|
2012-12-14 02:13:32 +05:30
|
|
|
#retrieve() windows os?
|
2012-12-02 22:52:40 +05:30
|
|
|
if sys.argv[2:] == ['all']:
|
|
|
|
sys.argv[2:] = LANG
|
2012-12-01 02:03:44 +05:30
|
|
|
check(sys.argv[2:])
|
2012-03-19 21:30:19 +05:30
|
|
|
|
2012-12-01 15:46:44 +05:30
|
|
|
if args.untranslated:
|
2012-12-01 02:03:44 +05:30
|
|
|
untranslated(sys.argv[2:])
|
2012-03-19 21:30:19 +05:30
|
|
|
|
2012-12-01 15:46:44 +05:30
|
|
|
if args.fuzzy:
|
2012-12-01 02:03:44 +05:30
|
|
|
fuzzy(sys.argv[2:])
|
2012-10-03 21:07:44 +05:30
|
|
|
|
|
|
|
def create_filesfile():
|
|
|
|
"""
|
|
|
|
Create a file with all files that we should translate.
|
|
|
|
These are all python files not in POTFILES.skip added with those in
|
|
|
|
POTFILES.in
|
|
|
|
"""
|
|
|
|
dir = os.getcwd()
|
|
|
|
topdir = os.path.normpath(os.path.join(dir, '..', 'gramps'))
|
|
|
|
lentopdir = len(topdir)
|
|
|
|
f = open('POTFILES.in')
|
|
|
|
infiles = dict(['../' + file.strip(), None] for file in f if file.strip()
|
|
|
|
and not file[0]=='#')
|
|
|
|
f.close()
|
|
|
|
f = open('POTFILES.skip')
|
|
|
|
notinfiles = dict(['../' + file.strip(), None] for file in f if file
|
|
|
|
and not file[0]=='#')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk(topdir):
|
|
|
|
root, subdir = os.path.split(dirpath)
|
|
|
|
if subdir.startswith("."):
|
|
|
|
#don't continue in this dir
|
|
|
|
dirnames[:] = []
|
|
|
|
continue
|
|
|
|
for dirname in dirnames:
|
|
|
|
# Skip hidden and system directories:
|
|
|
|
if dirname.startswith(".") or dirname in ["po", "locale"]:
|
|
|
|
dirnames.remove(dirname)
|
|
|
|
#add the files which are python or glade files
|
|
|
|
# if the directory does not exist or is a link, do nothing
|
|
|
|
if not os.path.isdir(dirpath) or os.path.islink(dirpath):
|
|
|
|
continue
|
|
|
|
|
|
|
|
for filename in os.listdir(dirpath):
|
|
|
|
name = os.path.split(filename)[1]
|
|
|
|
if name.endswith('.py') or name.endswith('.glade'):
|
|
|
|
full_filename = os.path.join(dirpath, filename)
|
|
|
|
#Skip the file if in POTFILES.skip
|
|
|
|
if full_filename[lentopdir:] in notinfiles:
|
2012-10-17 00:09:40 +05:30
|
|
|
infiles['../gramps' + full_filename[lentopdir:]] = None
|
2012-10-03 21:07:44 +05:30
|
|
|
#now we write out all the files in form ../gramps/filename
|
|
|
|
f = open('tmpfiles', 'w')
|
|
|
|
for file in sorted(infiles.keys()):
|
|
|
|
f.write(file)
|
|
|
|
f.write('\n')
|
|
|
|
f.close()
|
|
|
|
|
2012-10-03 17:46:06 +05:30
|
|
|
def listing(name, extensionlist):
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
|
|
|
List files according to extensions.
|
|
|
|
Parsing from a textual file (gramps) is faster and easy for maintenance.
|
|
|
|
Like POTFILES.in and POTFILES.skip
|
|
|
|
"""
|
|
|
|
|
2012-10-03 21:07:44 +05:30
|
|
|
f = open('tmpfiles')
|
2012-10-03 18:03:32 +05:30
|
|
|
files = [file.strip() for file in f if file and not file[0]=='#']
|
2012-03-15 22:41:31 +05:30
|
|
|
f.close()
|
|
|
|
|
|
|
|
temp = open(name, 'w')
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
for entry in files:
|
2012-10-03 17:46:06 +05:30
|
|
|
for ext in extensionlist:
|
|
|
|
if entry.endswith(ext):
|
|
|
|
temp.write(entry)
|
|
|
|
temp.write('\n')
|
|
|
|
break
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
temp.close()
|
|
|
|
|
|
|
|
def headers():
|
|
|
|
"""
|
|
|
|
Look at existing C file format headers.
|
|
|
|
Generated by 'intltool-extract' but want to get rid of this
|
|
|
|
dependency (perl, just a set of tools).
|
|
|
|
"""
|
|
|
|
headers = []
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
# in.h; extract_xml
|
2013-01-05 19:54:51 +05:30
|
|
|
if os.path.isfile('''../data/tips.xml.in.h'''):
|
|
|
|
headers.append('''../data/tips.xml.in.h''')
|
2012-10-01 15:00:35 +05:30
|
|
|
if os.path.isfile('''../gramps/plugins/lib/holidays.xml.in.h'''):
|
|
|
|
headers.append('''../gramps/plugins/lib/holidays.xml.in.h''')
|
2012-03-15 22:41:31 +05:30
|
|
|
if os.path.isfile('''../data/gramps.xml.in.h'''):
|
|
|
|
headers.append('''../data/gramps.xml.in.h''')
|
|
|
|
if os.path.isfile('''../data/gramps.desktop.in.h'''):
|
|
|
|
headers.append('''../data/gramps.desktop.in.h''')
|
|
|
|
if os.path.isfile('''../data/gramps.keys.in.h'''):
|
|
|
|
headers.append('''../data/gramps.keys.in.h''')
|
2013-10-07 14:42:16 +05:30
|
|
|
if os.path.isfile('''../data/gramps.appdata.xml.in.h'''):
|
|
|
|
headers.append('''../data/gramps.appdata.xml.in.h''')
|
2013-05-08 14:39:53 +05:30
|
|
|
if os.path.isfile('''gtklist.h'''):
|
|
|
|
headers.append('''gtklist.h''')
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
return headers
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
def extract_xml():
|
|
|
|
"""
|
|
|
|
Extract translation strings from XML based, keys, mime and desktop
|
2012-10-05 00:05:40 +05:30
|
|
|
files. Own XML files parsing and custom translation marks.
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
2012-10-05 00:05:40 +05:30
|
|
|
|
2012-10-01 15:00:35 +05:30
|
|
|
HolidaysParse('../gramps/plugins/lib/holidays.xml.in', '_name')
|
2013-01-05 20:06:49 +05:30
|
|
|
TipsParse('../data/tips.xml.in', '_tip')
|
2012-10-05 00:05:40 +05:30
|
|
|
XmlParse('../data/gramps.xml.in', '_comment')
|
2013-10-07 14:42:16 +05:30
|
|
|
XmlParse('../data/gramps.appdata.xml.in', '_p')
|
2012-10-05 00:05:40 +05:30
|
|
|
DesktopParse('../data/gramps.desktop.in')
|
|
|
|
KeyParse('../data/gramps.keys.in', '_description')
|
2012-03-15 22:41:31 +05:30
|
|
|
|
|
|
|
def create_template():
|
|
|
|
"""
|
|
|
|
Create a new file for template, if it does not exist.
|
|
|
|
"""
|
|
|
|
template = open('gramps.pot', 'w')
|
|
|
|
template.close()
|
|
|
|
|
|
|
|
def extract_glade():
|
|
|
|
"""
|
|
|
|
Extract messages from a temp file with all .glade
|
|
|
|
"""
|
|
|
|
if not os.path.isfile('gramps.pot'):
|
|
|
|
create_template()
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-10-03 17:46:06 +05:30
|
|
|
listing('glade.txt', ['.glade'])
|
2012-03-17 00:05:35 +05:30
|
|
|
os.system('''%(xgettext)s --add-comments -j -L Glade '''
|
2012-03-15 22:41:31 +05:30
|
|
|
'''--from-code=UTF-8 -o gramps.pot --files-from=glade.txt'''
|
2012-03-17 00:05:35 +05:30
|
|
|
% {'xgettext': xgettextCmd}
|
2012-03-15 22:41:31 +05:30
|
|
|
)
|
|
|
|
|
2013-05-08 14:39:53 +05:30
|
|
|
def extract_gtkbuilder():
|
|
|
|
"""
|
|
|
|
Temp workaround for xgettext bug (< gettext 0.18.3)
|
|
|
|
https://savannah.gnu.org/bugs/index.php?29216
|
|
|
|
See bug reports #6595, #5621
|
|
|
|
"""
|
|
|
|
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
'''
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<interface>
|
|
|
|
<!-- interface-requires gtk+ 3.0 -->
|
|
|
|
|
|
|
|
<object class="GtkListStore" id="model1">
|
|
|
|
<columns>
|
|
|
|
<!-- column-name gchararray -->
|
|
|
|
<column type="gchararray"/>
|
|
|
|
</columns>
|
|
|
|
<data>
|
|
|
|
<row>
|
|
|
|
<col id="0" translatable="yes">All rules must apply</col>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<col id="0" translatable="yes">At least one rule must apply</col>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<col id="0" translatable="yes">Exactly one rule must apply</col>
|
|
|
|
</row>
|
|
|
|
</data>
|
|
|
|
</object>
|
|
|
|
|
|
|
|
msgid "All rules must apply"
|
|
|
|
msgid "At least one rule must apply"
|
|
|
|
msgid "Exactly one rule must apply"
|
|
|
|
'''
|
|
|
|
|
|
|
|
files = ['../gramps/plugins/importer/importgedcom.glade', '../gramps/gui/glade/rule.glade']
|
|
|
|
temp = open('gtklist.h', 'w')
|
|
|
|
|
|
|
|
for filename in files:
|
|
|
|
tree = ElementTree.parse(filename)
|
|
|
|
root = tree.getroot()
|
|
|
|
for line in root.iter():
|
|
|
|
att = line.attrib
|
|
|
|
if att == {'id': '0', 'translatable': 'yes'}:
|
|
|
|
col = 'char *s = N_("%s");\n' % line.text
|
|
|
|
temp.write(col)
|
|
|
|
root.clear()
|
|
|
|
|
|
|
|
temp.close()
|
|
|
|
print ('Wrote gtklist.h')
|
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
def retrieve():
|
|
|
|
"""
|
|
|
|
Extract messages from all files used by Gramps (python, glade, xml)
|
|
|
|
"""
|
|
|
|
extract_xml()
|
|
|
|
|
2013-05-08 14:39:53 +05:30
|
|
|
extract_gtkbuilder()
|
|
|
|
|
2013-05-04 21:40:26 +05:30
|
|
|
create_template()
|
2012-03-15 22:41:31 +05:30
|
|
|
|
2012-10-03 21:25:36 +05:30
|
|
|
create_filesfile()
|
2012-10-03 17:46:06 +05:30
|
|
|
listing('python.txt', ['.py', '.py.in'])
|
|
|
|
|
2013-05-06 01:10:56 +05:30
|
|
|
# additional keywords must always be kept in sync with those in genpot.sh
|
2012-10-08 14:47:33 +05:30
|
|
|
os.system('''%(xgettext)s -j --directory=./ -d gramps '''
|
2012-03-15 22:41:31 +05:30
|
|
|
'''-L Python -o gramps.pot --files-from=python.txt '''
|
|
|
|
'''--keyword=_ --keyword=ngettext '''
|
2013-05-08 00:29:15 +05:30
|
|
|
'''--keyword=_T_ --keyword=trans_text '''
|
2012-03-17 00:05:35 +05:30
|
|
|
'''--keyword=sgettext --from-code=UTF-8''' % {'xgettext': xgettextCmd}
|
2012-03-15 22:41:31 +05:30
|
|
|
)
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
extract_glade()
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
# C format header (.h extension)
|
|
|
|
for h in headers():
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('xgettext for %s' % h)
|
2012-03-17 00:05:35 +05:30
|
|
|
os.system('''%(xgettext)s --add-comments -j -o gramps.pot '''
|
|
|
|
'''--keyword=N_ --from-code=UTF-8 %(head)s'''
|
|
|
|
% {'xgettext': xgettextCmd, 'head': h}
|
2012-03-15 22:41:31 +05:30
|
|
|
)
|
|
|
|
clean()
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
def clean():
|
|
|
|
"""
|
|
|
|
Remove created files (C format headers, temp listings)
|
|
|
|
"""
|
|
|
|
for h in headers():
|
|
|
|
if os.path.isfile(h):
|
2012-03-17 11:30:16 +05:30
|
|
|
os.unlink(h)
|
2012-10-03 17:46:06 +05:30
|
|
|
print ('Remove %(head)s' % {'head': h})
|
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
if os.path.isfile('python.txt'):
|
2012-03-17 00:05:35 +05:30
|
|
|
os.unlink('python.txt')
|
2012-10-03 17:46:06 +05:30
|
|
|
print ("Remove 'python.txt'")
|
|
|
|
|
2012-03-15 22:41:31 +05:30
|
|
|
if os.path.isfile('glade.txt'):
|
2012-03-17 00:05:35 +05:30
|
|
|
os.unlink('glade.txt')
|
2012-10-03 17:46:06 +05:30
|
|
|
print ("Remove 'glade.txt'")
|
|
|
|
|
2012-10-03 21:08:42 +05:30
|
|
|
if os.path.isfile('tmpfiles'):
|
|
|
|
os.unlink('tmpfiles')
|
|
|
|
print ("Remove 'tmpfiles'")
|
|
|
|
|
2012-12-02 22:52:40 +05:30
|
|
|
def merge(args):
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
|
|
|
Merge messages with 'gramps.pot'
|
|
|
|
"""
|
2012-12-01 15:40:44 +05:30
|
|
|
|
2012-12-02 22:52:40 +05:30
|
|
|
for arg in args:
|
|
|
|
if arg == 'all':
|
|
|
|
continue
|
|
|
|
print ('Merge %(lang)s with current template' % {'lang': arg})
|
|
|
|
os.system('''%(msgmerge)s --no-wrap %(lang)s gramps.pot -o updated_%(lang)s''' \
|
|
|
|
% {'msgmerge': msgmergeCmd, 'lang': arg})
|
|
|
|
print ("Updated file: 'updated_%(lang)s'." % {'lang': arg})
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-12-02 22:52:40 +05:30
|
|
|
def check(args):
|
2012-03-15 22:41:31 +05:30
|
|
|
"""
|
|
|
|
Check the translation file
|
|
|
|
"""
|
2012-12-01 15:40:44 +05:30
|
|
|
|
2012-12-02 22:52:40 +05:30
|
|
|
for arg in args:
|
|
|
|
if arg == 'all':
|
|
|
|
continue
|
|
|
|
print ("Checked file: '%(lang.po)s'. See '%(txt)s.txt'." \
|
|
|
|
% {'lang.po': arg, 'txt': arg[:-3]})
|
|
|
|
os.system('''%(python)s ./check_po -s %(lang.po)s > %(lang)s.txt''' \
|
|
|
|
% {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:-3]})
|
|
|
|
os.system('''%(msgfmt)s -c -v %(lang.po)s'''
|
|
|
|
% {'msgfmt': msgfmtCmd, 'lang.po': arg})
|
2012-03-12 22:13:12 +05:30
|
|
|
|
2012-12-01 15:46:44 +05:30
|
|
|
def untranslated(arg):
|
2012-03-19 21:30:19 +05:30
|
|
|
"""
|
|
|
|
List untranslated messages
|
|
|
|
"""
|
2012-12-02 22:52:40 +05:30
|
|
|
|
|
|
|
os.system('''%(msgattrib)s --untranslated %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-12-01 15:46:44 +05:30
|
|
|
def fuzzy(arg):
|
2012-03-19 21:30:19 +05:30
|
|
|
"""
|
|
|
|
List fuzzy messages
|
|
|
|
"""
|
2012-12-02 22:52:40 +05:30
|
|
|
|
|
|
|
os.system('''%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s''' % {'msgattrib': msgattribCmd, 'lang.po': arg[0]})
|
2012-10-03 17:46:06 +05:30
|
|
|
|
2012-03-12 22:13:12 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|