Replace msgfmt.py with local tools.

This commit is contained in:
Bastian Kleineidam 2014-09-08 18:25:03 +02:00
parent 06c6b80ed3
commit 9c3739f1c9
12 changed files with 4013 additions and 3608 deletions

1
.gitignore vendored
View file

@ -29,7 +29,6 @@ Changelog.linkchecker*
/doc/html/*.qch
/.achievements
/doc/*.mo
/po/*.mo
/LinkChecker-*-portable.zip
/LinkChecker-*.exe
/LinkChecker.egg-info

View file

@ -17,7 +17,7 @@ include linkcheck/gui/rc/Makefile
include linkcheck/gui/rc/*.png
include linkcheck/gui/rc/*.qrc
include linkcheck/gui/ui/*.ui
include po/*.po po/*.pot po/Makefile po/msgfmt.py
include po/*.po po/*.mo po/*.pot po/Makefile
include doc/*.example doc/*.txt
include doc/html/*.ico
include doc/html/*.html

View file

@ -75,7 +75,6 @@ all:
clean:
-$(PYTHON) setup.py clean --all
rm -f $(LAPPNAME)-out.* *-stamp*
$(MAKE) -C po clean
$(MAKE) -C doc/html clean
$(MAKE) -C linkcheck/HtmlParser clean
rm -f linkcheck/network/_network*.so
@ -94,7 +93,7 @@ MANIFEST: MANIFEST.in setup.py
$(PYTHON) setup.py sdist --manifest-only
locale:
$(MAKE) -C po mofiles
$(MAKE) -C po
# to build in the current directory
localbuild: MANIFEST locale

View file

@ -4,6 +4,11 @@ Features:
- checking: Support itms-services: URLs.
Closes: GH bug #532
Changes:
- installation: Remove dependency on msgfmt.py by pre-generating the
*.mo files and adding them to version control.
Reason was the difficulty to run msgfmt.py under both Python 2 and 3.
Fixes:
- checking: Correct typos in the proxy handling code.
Closes: GH bug #536

View file

@ -10,17 +10,12 @@ MYMAIL := bastian.kleineidam@web.de
LFILE = LC_MESSAGES/$(PACKAGE).mo
# defined language (add new languages here)
LANGUAGES = de fr es
MOFILES = $(wildcard *.po)
all:
all: $(MOFILES)
mofiles:
@for la in $(LANGUAGES); do \
if [ ! -d $(LDIR)/$$la/LC_MESSAGES ]; then \
mkdir -p $(LDIR)/$$la/LC_MESSAGES; \
fi; \
echo "Formatting language catalog $${la}:"; \
$(MSGFMT) -c --statistics -o $(LDIR)/$$la/$(LFILE) $$la.po; \
done
%.mo: %.po
$(MSGFMT) -c --statistics -o $@ $<
%.po: $(TEMPLATE)
$(MSGMERGE) -U --suffix=.bak $@ $<
@ -42,4 +37,4 @@ clean:
@for f in $(LANGUAGES); do rm -f $(LDIR)/$$f/$(LFILE); done
rm -f *.mo *.bak
.PHONY: mofiles clean
.PHONY: clean

BIN
po/de.mo Normal file

Binary file not shown.

BIN
po/es.mo Normal file

Binary file not shown.

3659
po/es.po

File diff suppressed because it is too large Load diff

BIN
po/fr.mo Normal file

Binary file not shown.

3698
po/fr.po

File diff suppressed because it is too large Load diff

View file

@ -1,210 +0,0 @@
# -*- coding: iso-8859-1 -*-
# License: Python license
# Copyright by Martin v. Löwis <loewis@informatik.hu-berlin.de>
# Plural forms support added by alexander smishlajev <alex@tycobka.lv>
"""
Generate binary message catalog from textual translation description.
This program converts a textual Uniforum-style message catalog (.po file) into
a binary GNU catalog (.mo file). This is essentially the same function as the
GNU msgfmt program, however, it is a simpler implementation.
Usage: msgfmt.py [OPTIONS] filename.po
Options:
-o file
--output-file=file
Specify the output file to write to. If omitted, output will go to a
file named filename.mo (based off the input file name).
-h
--help
Print this message and exit.
-V
--version
Display version information and exit.
"""
import sys
import os
import getopt
import struct
import array
__version__ = "1.1"
MESSAGES = {}
def usage (ecode, msg=''):
"""Print usage and msg and exit with given code."""
print >> sys.stderr, __doc__
if msg:
print >> sys.stderr, msg
sys.exit(ecode)
def add (msgid, transtr, fuzzy):
"""Add a non-fuzzy translation to the dictionary."""
if not fuzzy and transtr and not transtr.startswith('\0'):
MESSAGES[msgid] = transtr
def generate ():
"""Return the generated output."""
keys = MESSAGES.keys()
# the keys are sorted in the .mo file
keys.sort()
offsets = []
ids = strs = ''
for _id in keys:
# For each string, we need size and file offset. Each string is NUL
# terminated; the NUL does not count into the size.
offsets.append((len(ids), len(_id), len(strs), len(MESSAGES[_id])))
ids += _id + '\0'
strs += MESSAGES[_id] + '\0'
# The header is 7 32-bit unsigned integers. We don't use hash tables, so
# the keys start right after the index tables.
# translated string.
keystart = 7*4+16*len(keys)
# and the values start after the keys
valuestart = keystart + len(ids)
koffsets = []
voffsets = []
# The string table first has the list of keys, then the list of values.
# Each entry has first the size of the string, then the file offset.
for o1, l1, o2, l2 in offsets:
koffsets += [l1, o1+keystart]
voffsets += [l2, o2+valuestart]
offsets = koffsets + voffsets
output = struct.pack("Iiiiiii",
0x950412deL, # Magic
0, # Version
len(keys), # # of entries
7*4, # start of key index
7*4+len(keys)*8, # start of value index
0, 0) # size and offset of hash table
output += array.array("i", offsets).tostring()
output += ids
output += strs
return output
def make (filename, outfile):
ID = 1
STR = 2
MESSAGES.clear()
# Compute .mo name from .po name and arguments
if filename.endswith('.po'):
infile = filename
else:
infile = filename + '.po'
if outfile is None:
outfile = os.path.splitext(infile)[0] + '.mo'
try:
lines = open(infile).readlines()
except IOError, msg:
print >> sys.stderr, msg
sys.exit(1)
section = None
fuzzy = 0
# Parse the catalog
msgid = msgstr = ''
lno = 0
for l in lines:
lno += 1
# If we get a comment line after a msgstr, this is a new entry
if l[0] == '#' and section == STR:
add(msgid, msgstr, fuzzy)
section = None
fuzzy = 0
# Record a fuzzy mark
if l[:2] == '#,' and (l.find('fuzzy') >= 0):
fuzzy = 1
# Skip comments
if l[0] == '#':
continue
# Start of msgid_plural section, separate from singular form with \0
if l.startswith('msgid_plural'):
msgid += '\0'
l = l[12:]
# Now we are in a msgid section, output previous section
elif l.startswith('msgid'):
if section == STR:
add(msgid, msgstr, fuzzy)
section = ID
l = l[5:]
msgid = msgstr = ''
# Now we are in a msgstr section
elif l.startswith('msgstr'):
section = STR
l = l[6:]
# Check for plural forms
if l.startswith('['):
# Separate plural forms with \0
if not l.startswith('[0]'):
msgstr += '\0'
# Ignore the index - must come in sequence
l = l[l.index(']') + 1:]
# Skip empty lines
l = l.strip()
if not l:
continue
# XXX: Does this always follow Python escape semantics?
l = eval(l)
if section == ID:
msgid += l
elif section == STR:
msgstr += l
else:
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \
'before:'
print >> sys.stderr, l
sys.exit(1)
# Add last entry
if section == STR:
add(msgid, msgstr, fuzzy)
# Compute output
output = generate()
try:
open(outfile,"wb").write(output)
except IOError,msg:
print >> sys.stderr, msg
def main ():
try:
opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
['help', 'version', 'output-file='])
except getopt.error, msg:
usage(1, msg)
outfile = None
# parse options
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-V', '--version'):
print >> sys.stderr, "msgfmt.py", __version__
sys.exit(0)
elif opt in ('-o', '--output-file'):
outfile = arg
# do it
if not args:
print >> sys.stderr, 'No input file given'
print >> sys.stderr, "Try `msgfmt --help' for more information."
return
for filename in args:
make(filename, outfile)
if __name__ == '__main__':
main()

View file

@ -397,20 +397,13 @@ class MyInstallLib (install_lib, object):
class MyInstallData (install_data, object):
"""Handle locale files and permissions."""
"""Fix file permissions."""
def run (self):
"""Adjust permissions on POSIX systems."""
self.add_message_files()
super(MyInstallData, self).run()
self.fix_permissions()
def add_message_files (self):
"""Add locale message files to data_files list."""
for (src, dst) in list_message_files(self.distribution.get_name()):
dstdir = os.path.dirname(dst)
self.data_files.append((dstdir, [os.path.join("build", dst)]))
def fix_permissions (self):
"""Set correct read permissions on POSIX systems. Might also
be possible by setting umask?"""
@ -551,7 +544,7 @@ class MyBuildExt (build_ext, object):
self.build_extension(ext)
def list_message_files (package, suffix=".po"):
def list_message_files (package, suffix=".mo"):
"""Return list of all found message files and their installation paths."""
for fname in glob.glob("po/*" + suffix):
# basename (without extension) is a locale name
@ -585,21 +578,9 @@ def check_manifest ():
class MyBuild (build, object):
"""Custom build command."""
def build_message_files (self):
"""For each po/*.po, build .mo file in target locale directory."""
# msgfmt.py is in the po/ subdirectory
sys.path.append('po')
import msgfmt
for (src, dst) in list_message_files(self.distribution.get_name()):
build_dst = os.path.join("build", dst)
self.mkpath(os.path.dirname(build_dst))
self.announce("Compiling %s -> %s" % (src, build_dst))
msgfmt.make(src, build_dst)
def run (self):
"""Check MANIFEST and build message files before building."""
"""Check MANIFEST before building."""
check_manifest()
self.build_message_files()
build.run(self)
@ -668,6 +649,9 @@ data_files = [
]),
]
for (src, dst) in list_message_files(AppName):
data_files.append((src, dst))
if os.name == 'posix':
data_files.append(('share/man/man1', ['doc/en/linkchecker.1', 'doc/en/linkchecker-gui.1']))
data_files.append(('share/man/man5', ['doc/en/linkcheckerrc.5']))