forked from xybu/onedrived-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
od_i18n.py
26 lines (20 loc) · 856 Bytes
/
od_i18n.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
from . import get_resource
class Translator:
DEFAULT_LOCALE = 'en_US'
def __init__(self, lang_resources, locale_str='en_US'):
"""
:param [str] lang_resources: List of language resource files to load.
Example: ['od_pref', 'configurator'] to load lang/od_pref
:param str locale_str: Locale to load.
"""
self.string_resources = dict()
for lang in lang_resources:
try:
t = get_resource('lang/%s.%s.json' % (lang, locale_str), pkg_name='onedrived')
except FileNotFoundError:
t = get_resource('lang/%s.%s.json' % (lang, self.DEFAULT_LOCALE), pkg_name='onedrived')
data = json.loads(t)
self.string_resources.update(data)
def __getitem__(self, item):
return self.string_resources[item]