Added Special Case For Windows (#2345)

This commit is contained in:
Teodor-Stelian Baltaretu 2024-07-12 01:42:38 +03:00
commit 6dc53da8bf

View file

@ -34,6 +34,7 @@ import shutil
import time import time
import threading import threading
import tzlocal import tzlocal
import ctypes
import plexpy import plexpy
from plexpy import common, config, database, helpers, logger, webstart from plexpy import common, config, database, helpers, logger, webstart
@ -69,10 +70,20 @@ def main():
plexpy.SYS_ENCODING = None plexpy.SYS_ENCODING = None
try: try:
locale.setlocale(locale.LC_ALL, "")
plexpy.SYS_LANGUAGE, plexpy.SYS_ENCODING = locale.getlocale() language_code, encoding = locale.getlocale()
if not plexpy.SYS_ENCODING: if not encoding:
plexpy.SYS_ENCODING = locale.getencoding() encoding = locale.getencoding()
# Special case for Windows where getlocale doesn't return correctly
if sys.platform == 'win32':
# Get the kernel of the OS and the default UI Language to locate the language code in Windows
windll = ctypes.windll.kernel32
language_code = locale.windows_locale[windll.GetUserDefaultUILanguage()]
encoding = "cp1252"
plexpy.SYS_LANGUAGE = language_code
plexpy.SYS_ENCODING = encoding
except (locale.Error, IOError): except (locale.Error, IOError):
pass pass