Update po generating file, make sure py.in is present
svn: r20500
This commit is contained in:
parent
91e6df28c1
commit
6fc289a956
@ -20,7 +20,7 @@
|
||||
# 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
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
@ -41,6 +41,9 @@ elif sys.platform == 'linux2' or os.name == 'darwin':
|
||||
msgattribCmd = 'msgattrib'
|
||||
xgettextCmd = 'xgettext'
|
||||
pythonCmd = os.path.join(sys.prefix, 'bin', 'python')
|
||||
else:
|
||||
print ("ERROR: unknown system, don't know msgmerge, ... commands")
|
||||
sys.exit(0)
|
||||
|
||||
def tests():
|
||||
"""
|
||||
@ -48,31 +51,34 @@ def tests():
|
||||
We made tests (-t flag) by displaying versions of tools if properly
|
||||
installed. Cannot run all commands without 'gettext' and 'python'.
|
||||
"""
|
||||
|
||||
try:
|
||||
print ("\n====='msgmerge'=(merge our translation)================\n")
|
||||
os.system('''%(program)s -V''' % {'program': msgmergeCmd})
|
||||
except:
|
||||
print('Please, install %(program)s for updating your translation' % {'program': msgmergeCmd})
|
||||
print ('Please, install %(program)s for updating your translation'
|
||||
% {'program': msgmergeCmd})
|
||||
|
||||
try:
|
||||
print ("\n==='msgfmt'=(format our translation for installation)==\n")
|
||||
os.system('''%(program)s -V''' % {'program': msgfmtCmd})
|
||||
except:
|
||||
print('Please, install %(program)s for checking your translation' % {'program': msgfmtCmd})
|
||||
print ('Please, install %(program)s for checking your translation'
|
||||
% {'program': msgfmtCmd})
|
||||
|
||||
try:
|
||||
print ("\n===='msgattrib'==(list groups of messages)=============\n")
|
||||
os.system('''%(program)s -V''' % {'program': msgattribCmd})
|
||||
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:
|
||||
print("\n===='xgettext' =(generate a new template)==============\n")
|
||||
os.system('''%(program)s -V''' % {'program': xgettextCmd})
|
||||
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:
|
||||
print("\n=================='python'=============================\n")
|
||||
@ -80,14 +86,11 @@ def tests():
|
||||
except:
|
||||
print ('Please, install python')
|
||||
|
||||
|
||||
# See also 'get_string' from Gramps 2.0 (sample with SAX)
|
||||
|
||||
def TipsParse(filename, mark):
|
||||
"""
|
||||
Experimental alternative to 'intltool-extract' for 'tips.xml'.
|
||||
"""
|
||||
|
||||
# in progress ...
|
||||
from xml.etree import ElementTree
|
||||
|
||||
@ -123,14 +126,8 @@ def TipsParse(filename, mark):
|
||||
'''
|
||||
|
||||
tips = open('../gramps/data/tips.xml.in.h', 'w')
|
||||
|
||||
# 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
|
||||
|
||||
# it works with python 2.6 only !
|
||||
for key in root.getiterator(mark):
|
||||
marklist = root.iter(mark)
|
||||
for key in marklist:
|
||||
tip = ElementTree.tostring(key, encoding="UTF-8")
|
||||
tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "")
|
||||
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('"', '"')
|
||||
tips.write('char *s = N_("%s");\n' % tip)
|
||||
|
||||
tips.close()
|
||||
|
||||
print ('Wrote ../gramps/data/tips.xml.in.h')
|
||||
root.clear()
|
||||
|
||||
def HolidaysParse(filename, mark):
|
||||
"""
|
||||
Experimental alternative to 'intltool-extract' for 'holidays.xml'.
|
||||
"""
|
||||
|
||||
# in progress ...
|
||||
from xml.etree import ElementTree
|
||||
|
||||
tree = ElementTree.parse(filename)
|
||||
root = tree.getroot()
|
||||
|
||||
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()
|
||||
ellist = root.iter()
|
||||
|
||||
'''
|
||||
<?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')
|
||||
|
||||
for key in ITERATION:
|
||||
for key in ellist:
|
||||
if key.attrib.get(mark):
|
||||
line = key.attrib
|
||||
string = line.items
|
||||
name = 'char *s = N_("%(_name)s");\n' % line
|
||||
holidays.write(name)
|
||||
|
||||
holidays.close()
|
||||
|
||||
print ('Wrote ../gramps/plugins/lib/holidays.xml.in.h')
|
||||
root.clear()
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
The utility for handling translation stuff.
|
||||
@ -297,7 +276,7 @@ def main():
|
||||
if options.fuzzy:
|
||||
fuzzy(args)
|
||||
|
||||
def listing(name, extension):
|
||||
def listing(name, extensionlist):
|
||||
"""
|
||||
List files according to extensions.
|
||||
Parsing from a textual file (gramps) is faster and easy for maintenance.
|
||||
@ -311,21 +290,20 @@ def listing(name, extension):
|
||||
temp = open(name, 'w')
|
||||
|
||||
for entry in files:
|
||||
(module, ext) = os.path.splitext(entry)
|
||||
if ext == extension:
|
||||
for ext in extensionlist:
|
||||
if entry.endswith(ext):
|
||||
temp.write(entry)
|
||||
temp.write('\n')
|
||||
break
|
||||
|
||||
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 = []
|
||||
|
||||
# in.h; extract_xml
|
||||
@ -344,14 +322,12 @@ def headers():
|
||||
|
||||
return headers
|
||||
|
||||
|
||||
def extract_xml():
|
||||
"""
|
||||
Extract translation strings from XML based, keys, mime and desktop
|
||||
files. Still performed by 'intltool-update'.
|
||||
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/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/keys ../data/gramps.keys.in''')
|
||||
|
||||
|
||||
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()
|
||||
|
||||
listing('glade.txt', '.glade')
|
||||
listing('glade.txt', ['.glade'])
|
||||
os.system('''%(xgettext)s --add-comments -j -L Glade '''
|
||||
'''--from-code=UTF-8 -o gramps.pot --files-from=glade.txt'''
|
||||
% {'xgettext': xgettextCmd}
|
||||
)
|
||||
|
||||
|
||||
def retrieve():
|
||||
"""
|
||||
Extract messages from all files used by Gramps (python, glade, xml)
|
||||
"""
|
||||
|
||||
extract_xml()
|
||||
|
||||
if not os.path.isfile('gramps.pot'):
|
||||
create_template()
|
||||
|
||||
listing('python.txt', '.py')
|
||||
listing('python.txt', ['.py', '.py.in'])
|
||||
|
||||
os.system('''%(xgettext)s --add-comments -j --directory=./ -d gramps '''
|
||||
'''-L Python -o gramps.pot --files-from=python.txt '''
|
||||
'''--keyword=_ --keyword=ngettext '''
|
||||
@ -410,20 +381,17 @@ def retrieve():
|
||||
|
||||
# C format header (.h extension)
|
||||
for h in headers():
|
||||
print('xgettext for %s') % h
|
||||
print ('xgettext for %s' % h)
|
||||
os.system('''%(xgettext)s --add-comments -j -o gramps.pot '''
|
||||
'''--keyword=N_ --from-code=UTF-8 %(head)s'''
|
||||
% {'xgettext': xgettextCmd, 'head': h}
|
||||
)
|
||||
|
||||
clean()
|
||||
|
||||
|
||||
def clean():
|
||||
"""
|
||||
Remove created files (C format headers, temp listings)
|
||||
"""
|
||||
|
||||
for h in headers():
|
||||
if os.path.isfile(h):
|
||||
os.unlink(h)
|
||||
@ -437,15 +405,12 @@ def clean():
|
||||
os.unlink('glade.txt')
|
||||
print ("Remove 'glade.txt'")
|
||||
|
||||
|
||||
def merge(args):
|
||||
"""
|
||||
Merge messages with 'gramps.pot'
|
||||
"""
|
||||
|
||||
if not args:
|
||||
print ('Please, add at least one argument (sv.po, de.po).')
|
||||
|
||||
for arg in args:
|
||||
if arg[-3:] == '.po':
|
||||
print ('Merge %(lang)s with current template' % {'lang': arg})
|
||||
@ -453,14 +418,13 @@ def merge(args):
|
||||
% {'msgmerge': msgmergeCmd, 'lang': arg})
|
||||
print ("Updated file: 'updated_%(lang)s'." % {'lang': arg})
|
||||
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):
|
||||
"""
|
||||
Check the translation file
|
||||
"""
|
||||
|
||||
if not args:
|
||||
print ('Please, add at least one argument (sv.po, de.po).')
|
||||
|
||||
@ -472,13 +436,13 @@ def check(args):
|
||||
% {'python': pythonCmd, 'lang.po': arg, 'lang': arg[:2]})
|
||||
os.system('''%(msgfmt)s -c -v %(lang.po)s''' % {'msgfmt': msgfmtCmd, 'lang.po': arg})
|
||||
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):
|
||||
"""
|
||||
List untranslated messages
|
||||
"""
|
||||
|
||||
if len(args) > 1:
|
||||
print ('Please, use only one argument (ex: fr.po).')
|
||||
return
|
||||
@ -489,7 +453,6 @@ def fuzzy(args):
|
||||
"""
|
||||
List fuzzy messages
|
||||
"""
|
||||
|
||||
if len(args) > 1:
|
||||
print ('Please, use only one argument (ex: fr.po).')
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user