mirror of
https://github.com/lutris/lutris
synced 2024-09-04 23:13:35 +00:00
Check for locale presence
This commit is contained in:
parent
116fdda6a7
commit
d56dff0847
|
@ -1,15 +1,27 @@
|
|||
"""Language and translation utilities"""
|
||||
import locale
|
||||
|
||||
from lutris.util.log import logger
|
||||
|
||||
def get_user_locale():
|
||||
user_locale, _user_encoding = locale.getlocale()
|
||||
if not user_locale:
|
||||
logger.error("Unable to get locale")
|
||||
return
|
||||
return user_locale
|
||||
|
||||
def get_lang():
|
||||
"""Return the 2 letter language code used by the system"""
|
||||
user_locale, _user_encoding = locale.getlocale()
|
||||
user_locale = get_user_locale()
|
||||
if not user_locale:
|
||||
return ""
|
||||
return user_locale[:2]
|
||||
|
||||
|
||||
def get_lang_and_country():
|
||||
"""Return language code and country for the current user"""
|
||||
user_locale, _user_encoding = locale.getlocale()
|
||||
user_locale = get_user_locale()
|
||||
if not user_locale:
|
||||
return "", ""
|
||||
lang_code, country = user_locale.split('-' if '-' in locale else '_')
|
||||
return lang_code, country
|
||||
|
|
Loading…
Reference in a new issue