Skip to content

Commit 54b68b1

Browse files
committed
- Remove unused lowercase setting.
- Replace all_utf8_yes_really_all with ansi_console - Console files are in utf-8 by default now. Ref BGforgeNet/bg2-wildmage#30
1 parent aaf4593 commit 54b68b1

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

msg2po/config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ def __init__(self):
1717
"extract_format": "", # could be 'sfall'
1818
"no_female": False, # explicitly disable female extraction (TODO: reason unclear)
1919
"extract_fuzzy": False,
20-
"lowercase": True,
2120
# work with all files in utf-8
2221
"all_utf8": False,
23-
# and even console files (DOS_FILENAMES)
24-
"all_utf8_yes_really_all": False,
22+
# if all_utf8 it True, still keep console files in ansi (CONSOLE_FILENAMES)
23+
"ansi_console": False,
2524
}
2625

2726
config = translation_defaults
@@ -44,9 +43,8 @@ def __init__(self):
4443
self.extract_format = translation_config["extract_format"]
4544
self.no_female = translation_config["no_female"]
4645
self.extract_fuzzy = translation_config["extract_fuzzy"]
47-
self.lowercase = translation_config["lowercase"]
4846
self.all_utf8 = translation_config["all_utf8"]
49-
self.all_utf8_yes_really_all = translation_config["all_utf8_yes_really_all"]
47+
self.ansi_console = translation_config["ansi_console"]
5048

5149
self.po_dirname = "po"
5250
self.female_dir_suffix = "_female"

msg2po/core.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def get_enc(lang_path: str = "", file_path: str = ""):
169169
"vietnamese": "cp1258",
170170
}
171171

172-
DOS_ENCODINGS = {
172+
ANSI_ENCODINGS = {
173173
# 'czech': 'cp852',
174174
# 'polish': 'cp852',
175175
# 'polski': 'cp852',
@@ -187,7 +187,7 @@ def get_enc(lang_path: str = "", file_path: str = ""):
187187
# 'castellano': 'cp850',
188188
}
189189

190-
DOS_FILENAMES = [
190+
CONSOLE_FILENAMES = [
191191
"setup.tra",
192192
"install.tra",
193193
]
@@ -196,26 +196,34 @@ def get_enc(lang_path: str = "", file_path: str = ""):
196196
"ee.tra",
197197
]
198198

199-
if CONFIG.all_utf8_yes_really_all is True:
200-
return "utf-8"
199+
filename = basename(file_path)
200+
201+
# All utf-8, maybe except console
202+
if CONFIG.all_utf8 is True:
203+
if not CONFIG.ansi_console:
204+
return "utf-8"
205+
if filename not in CONSOLE_FILENAMES:
206+
return "utf-8"
201207

208+
# Configured encoding
202209
encoding = CONFIG.encoding
203210
lang = language_slug(lang_path)
204-
filename = basename(file_path)
205211

212+
# Try known encodings
206213
if lang in ENCODINGS:
207214
encoding = ENCODINGS[lang]
208215

209-
if filename in DOS_FILENAMES:
216+
if filename in CONSOLE_FILENAMES:
217+
# Always utf-8 for console, unless explicitly disabled
218+
if not CONFIG.ansi_console:
219+
return "utf-8"
220+
# Otherwise, try known ansi encodings
210221
try:
211-
encoding = DOS_ENCODINGS[lang]
222+
encoding = ANSI_ENCODINGS[lang]
212223
return encoding
213224
except:
214225
pass
215226

216-
if CONFIG.all_utf8 is True:
217-
return "utf-8"
218-
219227
if filename in UTF_FILENAMES:
220228
encoding = "utf-8"
221229

msg2po/unpoify.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def extract_po(pf: str, language_map: LanguageMap):
5050
print("Extracting {} from {} into {} with encoding {}".format(ef, po_path, ef_extract_path, enc))
5151
po2file(po, ef_extract_path, enc, ef, dst_dir=dst_dir, trans_map=trans_map, female_map=female_map)
5252

53+
enc = get_enc(po_path)
5354
print("Extracted {} into {} with encoding {}".format(po_path, dst_dir, enc))
5455

5556

0 commit comments

Comments
 (0)