Source code for translate.languages

# -*- coding: utf-8 -*-
from __future__ import print_function

import json
import operator

from os.path import dirname, abspath, join, isfile

__all__ = ['translation_table', 'print_table']


[docs]def translation_table(language, filepath='supported_translations.json'): ''' Opens up file located under the etc directory containing language codes and prints them out. :param file: Path to location of json file :type file: str :return: language codes :rtype: dict ''' fullpath = abspath(join(dirname(__file__), 'etc', filepath)) if not isfile(fullpath): raise IOError('File does not exist at {0}'.format(fullpath)) with open(fullpath, 'rt') as fp: raw_data = json.load(fp).get(language, None) assert(raw_data is not None) return dict((code['language'], code['name']) for code in raw_data)