diff --git a/python-programming/detect_locale.py b/python-programming/detect_locale.py new file mode 100644 index 0000000..3a3f099 --- /dev/null +++ b/python-programming/detect_locale.py @@ -0,0 +1,26 @@ +#!/usr/bin/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 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 os.environ["LANG"] + if os_name == "nt": + return windows_locale[windll.kernel32.GetUserDefaultUILanguage()] + return None + + +if __name__ == "__main__": + print(detect_locale())