MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / generate

Function generate

tools/python-3.11.9-amd64/Tools/i18n/msgfmt.py:58–96  ·  view source on GitHub ↗

Return the generated output.

()

Source from the content-addressed store, hash-verified

56
57
58def generate():
59 "Return the generated output."
60 global MESSAGES
61 # the keys are sorted in the .mo file
62 keys = sorted(MESSAGES.keys())
63 offsets = []
64 ids = strs = b''
65 for id in keys:
66 # For each string, we need size and file offset. Each string is NUL
67 # terminated; the NUL does not count into the size.
68 offsets.append((len(ids), len(id), len(strs), len(MESSAGES[id])))
69 ids += id + b'\0'
70 strs += MESSAGES[id] + b'\0'
71 output = ''
72 # The header is 7 32-bit unsigned integers. We don't use hash tables, so
73 # the keys start right after the index tables.
74 # translated string.
75 keystart = 7*4+16*len(keys)
76 # and the values start after the keys
77 valuestart = keystart + len(ids)
78 koffsets = []
79 voffsets = []
80 # The string table first has the list of keys, then the list of values.
81 # Each entry has first the size of the string, then the file offset.
82 for o1, l1, o2, l2 in offsets:
83 koffsets += [l1, o1+keystart]
84 voffsets += [l2, o2+valuestart]
85 offsets = koffsets + voffsets
86 output = struct.pack("Iiiiiii",
87 0x950412de, # Magic
88 0, # Version
89 len(keys), # # of entries
90 7*4, # start of key index
91 7*4+len(keys)*8, # start of value index
92 0, 0) # size and offset of hash table
93 output += array.array("i", offsets).tobytes()
94 output += ids
95 output += strs
96 return output
97
98
99def make(filename, outfile):

Callers 1

makeFunction · 0.70

Calls 4

sortedFunction · 0.85
keysMethod · 0.45
appendMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected