Removed deprecated getdefaultlocale (#2345) (#2364)

* Removed deprecated getdefaultlocale (#2345)

* Added Special Case For Windows (#2345)

* Refactored the changes into a cleaner code with comments (#2345)

* Changed the encoding method used and the selection of language

* Removed hardcoded encoding in Windows handling
This commit is contained in:
Teodor-Stelian Baltaretu 2024-08-11 05:24:06 +03:00 committed by GitHub
commit cfd81684b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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,8 +70,26 @@ def main():
plexpy.SYS_ENCODING = None plexpy.SYS_ENCODING = None
try: try:
locale.setlocale(locale.LC_ALL, "")
plexpy.SYS_LANGUAGE, plexpy.SYS_ENCODING = locale.getdefaultlocale() # Attempt to get the system's locale settings
language_code, encoding = locale.getlocale()
# Special handling for Windows platform
if sys.platform == 'win32':
# Get the user's current language settings on Windows
windll = ctypes.windll.kernel32
lang_id = windll.GetUserDefaultLCID()
# Map Windows language ID to locale identifier
language_code = locale.windows_locale.get(lang_id, '')
# Get the preferred encoding
encoding = locale.getpreferredencoding()
# Assign values to application-specific variable
plexpy.SYS_LANGUAGE = language_code
plexpy.SYS_ENCODING = encoding
except (locale.Error, IOError): except (locale.Error, IOError):
pass pass