mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
setup.py
This commit is contained in:
35
fpakman/core/util.py
Normal file
35
fpakman/core/util.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import locale
|
||||
|
||||
from fpakman.core import resource
|
||||
import glob
|
||||
|
||||
|
||||
def get_locale_keys():
|
||||
|
||||
current_locale = locale.getdefaultlocale()
|
||||
locale_path = None
|
||||
if current_locale:
|
||||
current_locale = current_locale[0]
|
||||
|
||||
locale_dir = '{}/resources/locale'.format(resource.get_app_dir())
|
||||
|
||||
for locale_file in glob.glob(locale_dir + '/*'):
|
||||
name = locale_file.split('/')[-1]
|
||||
|
||||
if current_locale == name or current_locale.startswith(name + '_'):
|
||||
locale_path = locale_file
|
||||
break
|
||||
|
||||
if not locale_path:
|
||||
locale_path = '{}/resources/locale/en'.format(resource.get_app_dir())
|
||||
|
||||
with open(locale_path, 'r') as f:
|
||||
locale_keys = f.readlines()
|
||||
|
||||
locale_obj = {}
|
||||
for line in locale_keys:
|
||||
if line:
|
||||
keyval = line.strip().split('=')
|
||||
locale_obj[keyval[0].strip()] = keyval[1].strip()
|
||||
|
||||
return locale_obj
|
||||
Reference in New Issue
Block a user