1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-04-14 18:39:07 +05:30

add detect_locale.py

This commit is contained in:
パチュリー・ノーレッジ 2024-07-20 18:29:50 +03:00
parent 51507bf354
commit af4e775489
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -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())