|
@ -16,6 +16,8 @@ __all__ = ['translate'] |
|
|
_LANG = i18n_config.LANG |
|
|
_LANG = i18n_config.LANG |
|
|
_DEFAULT_DIR = os.path.join(os.path.dirname(__file__), 'languages') |
|
|
_DEFAULT_DIR = os.path.join(os.path.dirname(__file__), 'languages') |
|
|
|
|
|
|
|
|
|
|
|
_DICTIONARY = None |
|
|
|
|
|
|
|
|
def get_path(language): |
|
|
def get_path(language): |
|
|
''' Returns the full path to the language file ''' |
|
|
''' Returns the full path to the language file ''' |
|
|
filename = language.lower() + '.json' |
|
|
filename = language.lower() + '.json' |
|
@ -25,17 +27,17 @@ def get_path(language): |
|
|
return lang_file_path |
|
|
return lang_file_path |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(filepath): |
|
|
|
|
|
|
|
|
def load(filename): |
|
|
''' Open and return the supplied json file ''' |
|
|
''' Open and return the supplied json file ''' |
|
|
|
|
|
global _DICTIONARY |
|
|
try: |
|
|
try: |
|
|
with open(filepath, 'rb') as f: |
|
|
|
|
|
return json.load(f) |
|
|
|
|
|
|
|
|
json_file = filename + '.json' |
|
|
|
|
|
with open(os.path.join(_DEFAULT_DIR, json_file), 'rb') as f: |
|
|
|
|
|
_DICTIONARY = json.load(f) |
|
|
except IOError: |
|
|
except IOError: |
|
|
raise IOError('Language file not found. Make sure that your ', |
|
|
raise IOError('Language file not found. Make sure that your ', |
|
|
'translation file is in the languages directory, ') |
|
|
'translation file is in the languages directory, ') |
|
|
|
|
|
|
|
|
_DICTIONARY = load(get_path(_LANG)) |
|
|
|
|
|
|
|
|
|
|
|
def translate(key): |
|
|
def translate(key): |
|
|
return _DICTIONARY[key] |
|
|
return _DICTIONARY[key] |
|
|
|
|
|
|
|
|