Skip to content

Commit 8608362

Browse files
Remove global var
1 parent 2144581 commit 8608362

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

Tools/i18n/msgfmt.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,24 @@
3737
__version__ = "1.2"
3838

3939

40-
MESSAGES = {}
41-
42-
4340
def usage(code, msg=''):
4441
print(__doc__, file=sys.stderr)
4542
if msg:
4643
print(msg, file=sys.stderr)
4744
sys.exit(code)
4845

4946

50-
def add(ctxt, id, str, fuzzy):
47+
def add(MESSAGES, ctxt, id, str, fuzzy):
5148
"Add a non-fuzzy translation to the dictionary."
52-
global MESSAGES
5349
if not fuzzy and str:
5450
if ctxt is None:
5551
MESSAGES[id] = str
5652
else:
5753
MESSAGES[b"%b\x04%b" % (ctxt, id)] = str
5854

5955

60-
def generate():
56+
def generate(MESSAGES):
6157
"Return the generated output."
62-
global MESSAGES
6358
# the keys are sorted in the .mo file
6459
keys = sorted(MESSAGES.keys())
6560
offsets = []
@@ -99,9 +94,7 @@ def generate():
9994

10095

10196
def make(filename, outfile):
102-
global MESSAGES
103-
MESSAGES.clear()
104-
97+
MESSAGES = {}
10598
ID = 1
10699
STR = 2
107100
CTXT = 3
@@ -143,7 +136,7 @@ def make(filename, outfile):
143136
lno += 1
144137
# If we get a comment line after a msgstr, this is a new entry
145138
if l[0] == '#' and section == STR:
146-
add(msgctxt, msgid, msgstr, fuzzy)
139+
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
147140
section = msgctxt = None
148141
fuzzy = 0
149142
# Record a fuzzy mark
@@ -155,7 +148,7 @@ def make(filename, outfile):
155148
# Now we are in a msgid or msgctxt section, output previous section
156149
if l.startswith('msgctxt'):
157150
if section == STR:
158-
add(msgctxt, msgid, msgstr, fuzzy)
151+
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
159152
section = CTXT
160153
l = l[7:]
161154
msgctxt = b''
@@ -172,7 +165,7 @@ def make(filename, outfile):
172165
charset = p.parsestr(msgstr.decode(encoding)).get_content_charset()
173166
if charset:
174167
encoding = charset
175-
add(msgctxt, msgid, msgstr, fuzzy)
168+
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
176169
msgctxt = None
177170
section = ID
178171
l = l[5:]
@@ -222,10 +215,10 @@ def make(filename, outfile):
222215
sys.exit(1)
223216
# Add last entry
224217
if section == STR:
225-
add(msgctxt, msgid, msgstr, fuzzy)
218+
add(MESSAGES, msgctxt, msgid, msgstr, fuzzy)
226219

227220
# Compute output
228-
output = generate()
221+
output = generate(MESSAGES)
229222

230223
try:
231224
with open(outfile,"wb") as f:

0 commit comments

Comments
 (0)