You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
790 B

  1. '''
  2. Created on Jan 25, 2014
  3. @author: Chris
  4. Provides Internationalization for all text within the program.
  5. '''
  6. import os
  7. import json
  8. __all__ = ['load', '_']
  9. _DICTIONARY = None
  10. def load(language_dir, filename):
  11. ''' Open and return the supplied json file '''
  12. global _DICTIONARY
  13. try:
  14. json_file = filename + '.json'
  15. with open(os.path.join(language_dir, json_file), 'rb') as f:
  16. _DICTIONARY = json.load(f)
  17. except IOError:
  18. raise IOError('{0} Language file not found at location {1}. '
  19. 'Make sure that your translation file is in the '
  20. 'listed language directory'.format(filename.title(), language_dir))
  21. def translate(key):
  22. return _DICTIONARY.get(key, key)
  23. def _(key):
  24. return translate(key)