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:
parent
51507bf354
commit
af4e775489
26
python-programming/detect_locale.py
Normal file
26
python-programming/detect_locale.py
Normal 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())
|
Loading…
x
Reference in New Issue
Block a user