Changeset 2893
- Timestamp:
- 04/10/08 19:35:51 (5 years ago)
- Files:
-
- 1 modified
-
trunk/install_scripts/utils/i18n/msgfmt.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/install_scripts/utils/i18n/msgfmt.py
r2881 r2893 2 2 # -*- coding: iso-8859-1 -*- 3 3 # Written by Martin v. L� <loewis@informatik.hu-berlin.de> 4 # 5 # Changelog: (Guilherme Polo) 6 # 2008-04-10 7 # - Support for fuzzy strings in output. 8 # - Bumped to version 1.1.1 4 9 5 10 """Generate binary message catalog from textual translation description. … … 17 22 file named filename.mo (based off the input file name). 18 23 24 -f 25 --use-fuzzy 26 Use fuzzy entries in output 27 19 28 -h 20 29 --help … … 24 33 --version 25 34 Display version information and exit. 35 36 Before using the -f (fuzzy) option, read this: 37 http://www.finesheer.com:8457/cgi-bin/info2html?(gettext)Fuzzy%20Entries&lang=en 26 38 """ 27 39 … … 32 44 import array 33 45 34 __version__ = "1.1 "46 __version__ = "1.1.1" 35 47 36 48 MESSAGES = {} 37 49 38 50 39 40 51 def usage(code, msg=''): 41 52 print >> sys.stderr, __doc__ … … 45 56 46 57 47 48 def add(id, str, fuzzy): 49 "Add a non-fuzzy translation to the dictionary." 58 def add(id, str, fuzzy, use_fuzzy): 59 "Add a translation to the dictionary." 50 60 global MESSAGES 51 if not fuzzyand str:61 if (not fuzzy or use_fuzzy) and str: 52 62 MESSAGES[id] = str 53 63 54 64 55 56 65 def generate(): 57 66 "Return the generated output." … … 96 105 97 106 98 99 def make(filename, outfile): 107 def make(filename, outfile, use_fuzzy): 100 108 ID = 1 101 109 STR = 2 … … 124 132 # If we get a comment line after a msgstr, this is a new entry 125 133 if l[0] == '#' and section == STR: 126 add(msgid, msgstr, fuzzy )134 add(msgid, msgstr, fuzzy, use_fuzzy) 127 135 section = None 128 136 fuzzy = 0 … … 136 144 if l.startswith('msgid'): 137 145 if section == STR: 138 add(msgid, msgstr, fuzzy )146 add(msgid, msgstr, fuzzy, use_fuzzy) 139 147 section = ID 140 148 l = l[5:] … … 161 169 # Add last entry 162 170 if section == STR: 163 add(msgid, msgstr, fuzzy )171 add(msgid, msgstr, fuzzy, use_fuzzy) 164 172 165 173 # Compute output … … 172 180 173 181 174 175 182 def main(): 176 183 try: 177 opts, args = getopt.getopt(sys.argv[1:], 'hVo: ',178 ['help', 'version', 'output-file='])184 opts, args = getopt.getopt(sys.argv[1:], 'hVo:f', 185 ['help', 'version', 'output-file=', 'use-fuzzy']) 179 186 except getopt.error, msg: 180 187 usage(1, msg) 181 188 182 189 outfile = None 190 use_fuzzy = False 183 191 # parse options 184 192 for opt, arg in opts: … … 188 196 print >> sys.stderr, "msgfmt.py", __version__ 189 197 sys.exit(0) 198 elif opt in ('-f', '--use-fuzzy'): 199 use_fuzzy = True 190 200 elif opt in ('-o', '--output-file'): 191 201 outfile = arg … … 197 207 198 208 for filename in args: 199 make(filename, outfile )209 make(filename, outfile, use_fuzzy) 200 210 201 211
