Ejemplo n.º 1
0
 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");
     }
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void SetLanguage(SystemLanguage systemLanguage)
 {
     SetLanguage(ISO6391.GetCode(systemLanguage));
 }