# -*- coding: utf-8 -*-
from django.conf import settings
from django.utils import translation
from django.utils.translation import ugettext as _

from six import text_type
from typing import Any

import os
import ujson

def with_language(string, language):
    # type: (text_type, text_type) -> text_type
    old_language = translation.get_language()
    translation.activate(language)
    result = _(string)
    translation.activate(old_language)
    return result

def get_language_list():
    # type: () -> List[Dict[str, Any]]
    path = os.path.join(settings.STATIC_ROOT, 'locale', 'language_options.json')
    with open(path, 'r') as reader:
        languages = ujson.load(reader)
        lang_list = []
        for lang_info in languages['languages']:
            name = lang_info['name']
            lang_info['name'] = with_language(name, lang_info['code'])
            if 'percent_translated' not in lang_info:
                lang_info['percent_translated'] = 'N/A'
            lang_list.append(lang_info)

        return sorted(lang_list, key=lambda i: i['name'])

def get_available_language_codes():
    # type: () -> List[text_type]
    language_list = get_language_list()
    codes = [language['code'] for language in language_list]
    return codes

@@ -17,16 +17,56 @@
 f-8 -*-%0A
+from __future__ import absolute_import%0A%0A
 from dja
@@ -904,118 +904,8 @@
 '%5D)%0A
-            if 'percent_translated' not in lang_info:%0A                lang_info%5B'percent_translated'%5D = 'N/A'%0A
     
@@ -1188,8 +1188,9 @@
 n codes%0A
+%0A

Return unformatted list from get_language_list.