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

This commit is contained in:
Teodor-Stelian Baltaretu 2024-07-12 14:40:05 +03:00
commit e673c599bb

View file

@ -71,19 +71,29 @@ def main():
try: try:
# Attempt to get the system's locale settings
language_code, encoding = locale.getlocale() language_code, encoding = locale.getlocale()
# If encoding is not returned, get the encoding
if not encoding: if not encoding:
encoding = locale.getencoding() encoding = locale.getencoding()
# Special case for Windows where getlocale doesn't return correctly # Special handling for Windows platform
if sys.platform == 'win32': if sys.platform == 'win32':
# Get the kernel of the OS and the default UI Language to locate the language code in Windows # Get the user's default UI language on Windows
windll = ctypes.windll.kernel32 windll = ctypes.windll.kernel32
language_code = locale.windows_locale[windll.GetUserDefaultUILanguage()] lang_id = windll.GetUserDefaultUILanguage()
# Map Windows language ID to locale identifier
language_code = locale.windows_locale.get(lang_id, '')
# Set encoding to Windows default encoding
encoding = "cp1252" encoding = "cp1252"
# Assign values to application-specific variable
plexpy.SYS_LANGUAGE = language_code plexpy.SYS_LANGUAGE = language_code
plexpy.SYS_ENCODING = encoding plexpy.SYS_ENCODING = encoding
except (locale.Error, IOError): except (locale.Error, IOError):
pass pass