From 6dc53da8bf0d5e7cf9e3707ba159584a229e0a5a Mon Sep 17 00:00:00 2001 From: Teodor-Stelian Baltaretu Date: Fri, 12 Jul 2024 01:42:38 +0300 Subject: [PATCH] Added Special Case For Windows (#2345) --- Tautulli.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Tautulli.py b/Tautulli.py index 24bf216a..8f1738e9 100755 --- a/Tautulli.py +++ b/Tautulli.py @@ -34,6 +34,7 @@ import shutil import time import threading import tzlocal +import ctypes import plexpy from plexpy import common, config, database, helpers, logger, webstart @@ -69,10 +70,20 @@ def main(): plexpy.SYS_ENCODING = None try: - locale.setlocale(locale.LC_ALL, "") - plexpy.SYS_LANGUAGE, plexpy.SYS_ENCODING = locale.getlocale() - if not plexpy.SYS_ENCODING: - plexpy.SYS_ENCODING = locale.getencoding() + + language_code, encoding = locale.getlocale() + if not encoding: + 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): pass