Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 7a258e0

Browse files
fix: Handle different locale formats when setting locale
1 parent 9c7726f commit 7a258e0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

jpyinterpreter/src/main/python/jvm_setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,19 @@ def init(*args, path: List[str] = None, include_translator_jars: bool = True,
5454
if include_translator_jars:
5555
path = path + extract_python_translator_jars()
5656

57-
locale_and_country = locale.getlocale()[0]
57+
user_locale = locale.getlocale()[0]
5858
extra_jvm_args = []
59-
if locale_and_country is not None:
60-
lang, country = locale_and_country.rsplit('_', maxsplit=1)
61-
extra_jvm_args.append(f'-Duser.language={lang}')
62-
extra_jvm_args.append(f'-Duser.country={country}')
59+
if user_locale is not None:
60+
user_locale = locale.normalize(user_locale)
61+
if '.' in user_locale:
62+
user_locale, _ = user_locale.split('.', 1)
63+
if '_' in user_locale:
64+
lang, country = user_locale.rsplit('_', maxsplit=1)
65+
extra_jvm_args.append(f'-Duser.language={lang}')
66+
extra_jvm_args.append(f'-Duser.country={country}')
67+
else:
68+
extra_jvm_args.append(f'-Duser.language={user_locale}')
69+
6370

6471
jpype.startJVM(*args, *extra_jvm_args, classpath=path, convertStrings=True) # noqa
6572

0 commit comments

Comments
 (0)