Skip to content

Commit 78ea6b6

Browse files
committed
iw3: waifu2x: Use short language name on Windows in GUI
switched from locale.getlocale() to locale.getdefaultlocale(). However, locale.getdefaultlocale() is deprecated in Python 3.11 and there doesn't seem to be an alternative. python/cpython#82986 python/cpython#130796
1 parent bd74887 commit 78ea6b6

File tree

9 files changed

+14
-26
lines changed

9 files changed

+14
-26
lines changed

iw3/desktop/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def update_compile(self):
920920
self.chk_compile.Disable()
921921

922922

923-
LOCALE_DICT = LOCALES.get(locale.getlocale()[0], {})
923+
LOCALE_DICT = LOCALES.get(locale.getdefaultlocale()[0], {})
924924

925925

926926
def T(s):
@@ -932,7 +932,7 @@ def main():
932932
import sys
933933

934934
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
935-
parser.add_argument("--lang", type=str, help="lang, ja_JP, en_US")
935+
parser.add_argument("--lang", type=str, choices=list(LOCALES.keys()), help="translation language")
936936
args = parser.parse_args()
937937
if args.lang:
938938
global LOCALE_DICT

iw3/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def update_compile(self):
12931293
self.chk_compile.Disable()
12941294

12951295

1296-
LOCALE_DICT = LOCALES.get(locale.getlocale()[0], {})
1296+
LOCALE_DICT = LOCALES.get(locale.getdefaultlocale()[0], {})
12971297

12981298

12991299
def T(s):
@@ -1305,7 +1305,7 @@ def main():
13051305
import sys
13061306

13071307
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
1308-
parser.add_argument("--lang", type=str, help="lang, ja_JP, en_US")
1308+
parser.add_argument("--lang", type=str, choices=list(LOCALES.keys()), help="translation")
13091309
args = parser.parse_args()
13101310
if args.lang:
13111311
global LOCALE_DICT

iw3/locales/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ def load_locales(locale_dir):
99
for locale_file in files:
1010
with open(locale_file, mode="r", encoding="utf-8") as f:
1111
locale = yaml.load(f.read(), Loader=yaml.SafeLoader)
12-
if "_LOCALE_LINUX" in locale:
13-
name = locale["_LOCALE_LINUX"]
14-
names = name if isinstance(name, (list, tuple)) else [name]
15-
for name in names:
16-
locales[name] = locale
17-
if "_LOCALE_WINDOWS" in locale:
18-
name = locale["_LOCALE_WINDOWS"]
12+
if "_LOCALE" in locale:
13+
name = locale["_LOCALE"]
1914
names = name if isinstance(name, (list, tuple)) else [name]
2015
for name in names:
2116
locales[name] = locale

iw3/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
"_LOCALE_LINUX": "en_US"
2+
"_LOCALE": "en_US"

iw3/locales/ja.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
"_LOCALE_LINUX": "ja_JP"
3-
"_LOCALE_WINDOWS": "Japanese_Japan"
2+
"_LOCALE": ["ja_JP"]
43

54
"Load": "読み込み"
65
"Save": "保存"

waifu2x/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def on_tqdm(self, event):
617617
pass
618618

619619

620-
LOCALE_DICT = LOCALES.get(locale.getlocale()[0], {})
620+
LOCALE_DICT = LOCALES.get(locale.getdefaultlocale()[0], {})
621621
LOCALE_DICT_EN = LOCALES["en_US"]
622622

623623

@@ -634,7 +634,7 @@ def main():
634634
import sys
635635

636636
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
637-
parser.add_argument("--lang", type=str, help="lang, ja_JP, en_US")
637+
parser.add_argument("--lang", type=str, choices=list(LOCALES.keys()), help="translation language")
638638
args = parser.parse_args()
639639
if args.lang:
640640
global LOCALE_DICT

waifu2x/locales/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ def load_locales(locale_dir, webgen_locale_dir):
3333
locale = yaml.load(f.read(), Loader=yaml.SafeLoader)
3434
lang = path.splitext(path.basename(locale_file))[0]
3535
merge_locales(webgen_locales, locale, lang)
36-
if "_LOCALE_LINUX" in locale:
37-
name = locale["_LOCALE_LINUX"]
38-
names = name if isinstance(name, (list, tuple)) else [name]
39-
for name in names:
40-
locales[name] = locale
41-
if "_LOCALE_WINDOWS" in locale:
42-
name = locale["_LOCALE_WINDOWS"]
36+
if "_LOCALE" in locale:
37+
name = locale["_LOCALE"]
4338
names = name if isinstance(name, (list, tuple)) else [name]
4439
for name in names:
4540
locales[name] = locale

waifu2x/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
_LOCALE_LINUX: "en_US"
2+
_LOCALE: "en_US"

waifu2x/locales/ja.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
"_LOCALE_LINUX": "ja_JP"
3-
"_LOCALE_WINDOWS": "Japanese_Japan"
2+
"_LOCALE": ["ja_JP"]
43

54
"Input": "入力"
65
"Output": "出力"

0 commit comments

Comments
 (0)