Changeset 2893

Show
Ignore:
Timestamp:
04/10/08 19:35:51 (5 years ago)
Author:
ggpolo
Message:

Added support for fuzzy strings in output.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/install_scripts/utils/i18n/msgfmt.py

    r2881 r2893  
    22# -*- coding: iso-8859-1 -*- 
    33# 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 
    49 
    510"""Generate binary message catalog from textual translation description. 
     
    1722        file named filename.mo (based off the input file name). 
    1823 
     24    -f 
     25    --use-fuzzy 
     26        Use fuzzy entries in output 
     27 
    1928    -h 
    2029    --help 
     
    2433    --version 
    2534        Display version information and exit. 
     35 
     36Before using the -f (fuzzy) option, read this: 
     37    http://www.finesheer.com:8457/cgi-bin/info2html?(gettext)Fuzzy%20Entries&lang=en 
    2638""" 
    2739 
     
    3244import array 
    3345 
    34 __version__ = "1.1" 
     46__version__ = "1.1.1" 
    3547 
    3648MESSAGES = {} 
    3749 
    3850 
    39   
    4051def usage(code, msg=''): 
    4152    print >> sys.stderr, __doc__ 
     
    4556 
    4657 
    47   
    48 def add(id, str, fuzzy): 
    49     "Add a non-fuzzy translation to the dictionary." 
     58def add(id, str, fuzzy, use_fuzzy): 
     59    "Add a translation to the dictionary." 
    5060    global MESSAGES 
    51     if not fuzzy and str: 
     61    if (not fuzzy or use_fuzzy) and str: 
    5262        MESSAGES[id] = str 
    5363 
    5464 
    55   
    5665def generate(): 
    5766    "Return the generated output." 
     
    96105 
    97106 
    98   
    99 def make(filename, outfile): 
     107def make(filename, outfile, use_fuzzy): 
    100108    ID = 1 
    101109    STR = 2 
     
    124132        # If we get a comment line after a msgstr, this is a new entry 
    125133        if l[0] == '#' and section == STR: 
    126             add(msgid, msgstr, fuzzy) 
     134            add(msgid, msgstr, fuzzy, use_fuzzy) 
    127135            section = None 
    128136            fuzzy = 0 
     
    136144        if l.startswith('msgid'): 
    137145            if section == STR: 
    138                 add(msgid, msgstr, fuzzy) 
     146                add(msgid, msgstr, fuzzy, use_fuzzy) 
    139147            section = ID 
    140148            l = l[5:] 
     
    161169    # Add last entry 
    162170    if section == STR: 
    163         add(msgid, msgstr, fuzzy) 
     171        add(msgid, msgstr, fuzzy, use_fuzzy) 
    164172 
    165173    # Compute output 
     
    172180 
    173181 
    174   
    175182def main(): 
    176183    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']) 
    179186    except getopt.error, msg: 
    180187        usage(1, msg) 
    181188 
    182189    outfile = None 
     190    use_fuzzy = False 
    183191    # parse options 
    184192    for opt, arg in opts: 
     
    188196            print >> sys.stderr, "msgfmt.py", __version__ 
    189197            sys.exit(0) 
     198        elif opt in ('-f', '--use-fuzzy'): 
     199            use_fuzzy = True 
    190200        elif opt in ('-o', '--output-file'): 
    191201            outfile = arg 
     
    197207 
    198208    for filename in args: 
    199         make(filename, outfile) 
     209        make(filename, outfile, use_fuzzy) 
    200210 
    201211