public void OnBeforeSerialize() { if (string.IsNullOrEmpty(_code) || string.IsNullOrEmpty(_langName) || !ISO6391.IsCode(_code) || !ISO6391.IsLangName(_langName)) { throw new Exception("language code or name is error"); } }
public void SetLanguage(string codeOrName, bool UseDefaultIfNone = true) { _dict.Clear(); Language language; if (ISO6391.IsCode(codeOrName)) { language = _langePacks.Find(x => x.code == codeOrName); } else if (ISO6391.IsLangName(codeOrName)) { language = _langePacks.Find(x => x.langName == codeOrName); } else { throw new Exception(string.Format("Not Code ,Not LangName -> {0}", codeOrName)); } currentLang = ISO6391.GetLang(codeOrName); if (language == null && UseDefaultIfNone) { language = _langePacks.Find(x => x.code == codeOrName || x.langName == codeOrName); } else { throw new Exception(string.Format("Language Not Found. And Not Use Default -> {0}", codeOrName)); } if (language == null) { throw new Exception(string.Format("Language Not Found. And No Default-> {0}", codeOrName)); } var words = language.Words; for (int i = 0; i < words.Count; i++) { var word = words[i]; _dict.Add(word.key, word.value); } }
public void Add(Language languagePack) { for (int i = _langePacks.Count - 1; i >= 0; i--) { var pack = _langePacks[i]; if (pack.code == languagePack.code) { _langePacks.RemoveAt(i); if (pack == languagePack) { continue; } #if UNITY_EDITOR if (pack != null) { if (Application.isPlaying) { GameObject.Destroy(pack); } else { GameObject.DestroyImmediate(pack); } } #else if (pack != null) { GameObject.Destroy(pack); } #endif } } if (languagePack.isDefault) { defaultLang = ISO6391.GetLang(languagePack.code); } _langePacks.Add(languagePack); }
public void SetLanguage(SystemLanguage systemLanguage) { SetLanguage(ISO6391.GetCode(systemLanguage)); }