package languageCfg

import (
	"server/gamedata"
	"server/msg"
)

const (
	CFG_LANGUAGE    = "LanguageData"
	CFG_ALLLANGUAGE = "AllLanguage"
)

func init() {
	gamedata.InitCfg(CFG_LANGUAGE)
	gamedata.InitCfg(CFG_ALLLANGUAGE)
}

func GetLanguage(lang msg.LANG_TYPE, key string) string {
	data, err := gamedata.GetDataByKey(CFG_ALLLANGUAGE, key)
	if err != nil {
		return key
	}
	switch lang {
	case msg.LANG_TYPE_LANG_EN:
		return gamedata.GetStringValue(data, "en_US")
	case msg.LANG_TYPE_LANG_PTBR:
		return gamedata.GetStringValue(data, "pt_BR")
	case msg.LANG_TYPE_LANG_CN:
		return gamedata.GetStringValue(data, "zh_CN")
	case msg.LANG_TYPE_LANG_ES_LATAM:
		return gamedata.GetStringValue(data, "es_LATAM")
	default:
		return key
	}
}
