()
return output
Return the generated output.
Return the generated output.
Return the generated output .
def generate():
    "Return the generated output."
    global MESSAGES
    # the keys are sorted in the .mo file
    keys = sorted(MESSAGES.keys())
    offsets = []
    ids = strs = b''
    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 + b'\0'
        strs += MESSAGES[id] + b'\0'
    output = ''
    # 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",
                         0x950412de,       # 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).tobytes()
    output += ids
    output += strs
    return output
def generate ( ) : global MESSAGES # the keys are sorted in the .mo file keys = sorted ( MESSAGES . keys ( ) ) offsets = [ ] ids = strs = b'' 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 + b'\0' strs += MESSAGES [ id ] + b'\0' output = '' # 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" , 0x950412de , # 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 ) . tobytes ( ) output += ids output += strs return output