mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Lowercase
This commit is contained in:
parent
8608362e6a
commit
0582facfd2
1 changed files with 13 additions and 13 deletions
|
|
@ -44,27 +44,27 @@ def usage(code, msg=''):
|
|||
sys.exit(code)
|
||||
|
||||
|
||||
def add(MESSAGES, ctxt, id, str, fuzzy):
|
||||
def add(messages, ctxt, id, str, fuzzy):
|
||||
"Add a non-fuzzy translation to the dictionary."
|
||||
if not fuzzy and str:
|
||||
if ctxt is None:
|
||||
MESSAGES[id] = str
|
||||
messages[id] = str
|
||||
else:
|
||||
MESSAGES[b"%b\x04%b" % (ctxt, id)] = str
|
||||
messages[b"%b\x04%b" % (ctxt, id)] = str
|
||||
|
||||
|
||||
def generate(MESSAGES):
|
||||
def generate(messages):
|
||||
"Return the generated output."
|
||||
# the keys are sorted in the .mo file
|
||||
keys = sorted(MESSAGES.keys())
|
||||
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])))
|
||||
offsets.append((len(ids), len(id), len(strs), len(messages[id])))
|
||||
ids += id + b'\0'
|
||||
strs += MESSAGES[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.
|
||||
|
|
@ -94,7 +94,7 @@ def generate(MESSAGES):
|
|||
|
||||
|
||||
def make(filename, outfile):
|
||||
MESSAGES = {}
|
||||
messages = {}
|
||||
ID = 1
|
||||
STR = 2
|
||||
CTXT = 3
|
||||
|
|
@ -136,7 +136,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(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
|
||||
add(messages, msgctxt, msgid, msgstr, fuzzy)
|
||||
section = msgctxt = None
|
||||
fuzzy = 0
|
||||
# Record a fuzzy mark
|
||||
|
|
@ -148,7 +148,7 @@ def make(filename, outfile):
|
|||
# Now we are in a msgid or msgctxt section, output previous section
|
||||
if l.startswith('msgctxt'):
|
||||
if section == STR:
|
||||
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
|
||||
add(messages, msgctxt, msgid, msgstr, fuzzy)
|
||||
section = CTXT
|
||||
l = l[7:]
|
||||
msgctxt = b''
|
||||
|
|
@ -165,7 +165,7 @@ def make(filename, outfile):
|
|||
charset = p.parsestr(msgstr.decode(encoding)).get_content_charset()
|
||||
if charset:
|
||||
encoding = charset
|
||||
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
|
||||
add(messages, msgctxt, msgid, msgstr, fuzzy)
|
||||
msgctxt = None
|
||||
section = ID
|
||||
l = l[5:]
|
||||
|
|
@ -215,10 +215,10 @@ def make(filename, outfile):
|
|||
sys.exit(1)
|
||||
# Add last entry
|
||||
if section == STR:
|
||||
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
|
||||
add(messages, msgctxt, msgid, msgstr, fuzzy)
|
||||
|
||||
# Compute output
|
||||
output = generate(MESSAGES)
|
||||
output = generate(messages)
|
||||
|
||||
try:
|
||||
with open(outfile,"wb") as f:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue