summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/build/msgfmt.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build/msgfmt.py')
-rw-r--r--scripts/build/msgfmt.py75
1 files changed, 34 insertions, 41 deletions
diff --git a/scripts/build/msgfmt.py b/scripts/build/msgfmt.py
index 5dd5430a524..0ac8fd60a8d 100644
--- a/scripts/build/msgfmt.py
+++ b/scripts/build/msgfmt.py
@@ -1,6 +1,14 @@
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
# Written by Martin v. Löwis <loewis@informatik.hu-berlin.de>
+#
+# Changelog: (Guilherme Polo)
+# 2008-04-11
+# - Support for files with BOM UTF8 mark.
+#
+# 2008-04-10
+# - Support for fuzzy strings in output.
+# - Bumped to version 1.1.1
"""Generate binary message catalog from textual translation description.
@@ -16,6 +24,10 @@ Options:
Specify the output file to write to. If omitted, output will go to a
file named filename.mo (based off the input file name).
+ -f
+ --use-fuzzy
+ Use fuzzy entries in output
+
-h
--help
Print this message and exit.
@@ -23,6 +35,9 @@ Options:
-V
--version
Display version information and exit.
+
+Before using the -f (fuzzy) option, read this:
+ http://www.finesheer.com:8457/cgi-bin/info2html?(gettext)Fuzzy%20Entries&lang=en
"""
import sys
@@ -30,13 +45,13 @@ import os
import getopt
import struct
import array
+import codecs
-__version__ = "1.1"
+__version__ = "1.1.1"
MESSAGES = {}
-
def usage(code, msg=''):
print >> sys.stderr, __doc__
if msg:
@@ -44,15 +59,13 @@ def usage(code, msg=''):
sys.exit(code)
-
-def add(id, str, fuzzy):
- "Add a non-fuzzy translation to the dictionary."
+def add(id, str, fuzzy, use_fuzzy):
+ "Add a translation to the dictionary."
global MESSAGES
- if not fuzzy and str:
+ if (not fuzzy or use_fuzzy) and str:
MESSAGES[id] = str
-
def generate():
"Return the generated output."
global MESSAGES
@@ -95,8 +108,7 @@ def generate():
return output
-
-def make(filename, outfile):
+def make(filename, outfile, use_fuzzy):
ID = 1
STR = 2
@@ -110,6 +122,8 @@ def make(filename, outfile):
try:
lines = open(infile).readlines()
+ if lines[0].startswith(codecs.BOM_UTF8):
+ lines[0] = lines[0][len(codecs.BOM_UTF8):]
except IOError, msg:
print >> sys.stderr, msg
sys.exit(1)
@@ -123,7 +137,7 @@ def make(filename, outfile):
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)
+ add(msgid, msgstr, fuzzy, use_fuzzy)
section = None
fuzzy = 0
# Record a fuzzy mark
@@ -133,39 +147,16 @@ def make(filename, outfile):
if l[0] == '#':
continue
# Now we are in a msgid section, output previous section
- if l.startswith('msgid') and not l.startswith('msgid_plural'):
+ if l.startswith('msgid'):
if section == STR:
- add(msgid, msgstr, fuzzy)
+ add(msgid, msgstr, fuzzy, use_fuzzy)
section = ID
l = l[5:]
msgid = msgstr = ''
- is_plural = False
- # This is a message with plural forms
- elif l.startswith('msgid_plural'):
- if section != ID:
- print >> sys.stderr, 'msgid_plural not preceeded by msgid on %s:%d' %\
- (infile, lno)
- sys.exit(1)
- l = l[12:]
- msgid += '\0' # separator of singular and plural
- is_plural = True
# Now we are in a msgstr section
elif l.startswith('msgstr'):
section = STR
- if l.startswith('msgstr['):
- if not is_plural:
- print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\
- (infile, lno)
- sys.exit(1)
- l = l.split(']', 1)[1]
- if msgstr:
- msgstr += '\0' # Separator of the various plural forms
- else:
- if is_plural:
- print >> sys.stderr, 'indexed msgstr required for plural on %s:%d' %\
- (infile, lno)
- sys.exit(1)
- l = l[6:]
+ l = l[6:]
# Skip empty lines
l = l.strip()
if not l:
@@ -183,7 +174,7 @@ def make(filename, outfile):
sys.exit(1)
# Add last entry
if section == STR:
- add(msgid, msgstr, fuzzy)
+ add(msgid, msgstr, fuzzy, use_fuzzy)
# Compute output
output = generate()
@@ -194,15 +185,15 @@ def make(filename, outfile):
print >> sys.stderr, msg
-
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
- ['help', 'version', 'output-file='])
+ opts, args = getopt.getopt(sys.argv[1:], 'hVo:f',
+ ['help', 'version', 'output-file=', 'use-fuzzy'])
except getopt.error, msg:
usage(1, msg)
outfile = None
+ use_fuzzy = False
# parse options
for opt, arg in opts:
if opt in ('-h', '--help'):
@@ -210,6 +201,8 @@ def main():
elif opt in ('-V', '--version'):
print >> sys.stderr, "msgfmt.py", __version__
sys.exit(0)
+ elif opt in ('-f', '--use-fuzzy'):
+ use_fuzzy = True
elif opt in ('-o', '--output-file'):
outfile = arg
# do it
@@ -219,7 +212,7 @@ def main():
return
for filename in args:
- make(filename, outfile)
+ make(filename, outfile, use_fuzzy)
if __name__ == '__main__':