1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-04-09 01:09:05 +05:30
gists/python-programming/detect_locale.py

27 lines
578 B
Python

#!/usr/bin/env python3
# detect_locale.py
#
# Author: Intel A80486DX2-66
# License: Creative Commons Zero 1.0 Universal or Unlicense
# SPDX-License-Identifier: CC0-1.0 OR Unlicense
from typing import Optional
from os import environ, name as os_name
if os_name == "nt":
from ctypes import windll
from locale import windows_locale
def detect_locale() -> Optional[str]:
if os_name == "posix":
return environ["LANG"]
if os_name == "nt":
return windows_locale[windll.kernel32.GetUserDefaultUILanguage()]
return None
if __name__ == "__main__":
print(detect_locale())