import os
import json

appdata = os.getenv("APPDATA")


def read_language():
    with open(appdata + "/.NFLmusic/language/zh_cn.json", "r") as f:
        zh_cn = json.loads(f.read())

    with open(appdata + "/.NFLmusic/language/en_us.json", "r") as f:
        en_us = json.loads(f.read())

    language0 = {
        "简体中文": zh_cn,
        "English(US)": en_us
    }
    return language0


def get(lang, key, replace_word=None):
    language0 = read_language()
    if replace_word is None:
        replace_word = {}
    try:
        if len(replace_word) == 0:
            return language0[lang][key]
        else:
            replaced_language = language0[lang][key]
            for word in replace_word.keys():
                replaced_language = replaced_language.replace(word, replace_word[word])
    except:
        replaced_language = key
    return replaced_language


def list_languages():
    return read_language().keys()
