예제 #1
0
 private static string TranslateTextSpecific(string key, XIHLanguage language)
 {
     if (!wordsAllDics.ContainsKey(key))
     {
         return($"<color=red>key[{key}] is Not Exist</color>");
     }
     if (wordsAllDics[key].ContainsKey(language))
     {
         return(wordsAllDics[key][language]);
     }
     return("");
 }
        static HashSet <string> GetCfg(XIHLanguage language, ISheet sheet, int col)
        {
            LanguageCfg cfg = AssetDatabase.LoadAssetAtPath <LanguageCfg>($"Assets/Resources/Config/Localization/{language}");

            if (cfg == null)
            {
                cfg = ScriptableObject.CreateInstance <LanguageCfg>();
                AssetDatabase.CreateAsset(cfg, $"Assets/Resources/Config/Localization/{language}.asset");
            }
            cfg.keyWords = new List <KeyWord>();
            int              rowNum = 1;
            IRow             row    = sheet.GetRow(rowNum);
            string           key    = row?.GetCell(0)?.StringCellValue;
            HashSet <string> keys   = new HashSet <string>();

            while (!string.IsNullOrEmpty(key))
            {
                key = key.ToLower();
                if (keys.Contains(key))
                {
                    Debug.LogWarning($"包含重复Key:{key},在表中位置【{rowNum + 1}】行");
                }
                else
                {
                    string word = row.GetCell(col)?.StringCellValue;
                    if (string.IsNullOrEmpty(word))
                    {
                        Debug.LogWarning($"Key:{key}所对应word为空,在表中位置【{rowNum + 1}】行,【{col + 1}】列");
                    }
                    else
                    {
                        cfg.keyWords.Add(new KeyWord()
                        {
                            key = key, word = word
                        });
                    }
                }
                keys.Add(key);
                row = sheet.GetRow(++rowNum);
                key = row?.GetCell(0)?.StringCellValue;
            }
            EditorUtility.SetDirty(cfg);
            AssetDatabase.SaveAssets();
            return(keys);
        }
예제 #3
0
        public static void SetLanguage(XIHLanguage language)
        {
            if (SavedLanguage == language && wordsDics.Count > 0)
            {
                return;
            }
            PlayerPrefs.SetInt("FATTY_LANGUAGE", (int)language);
            PlayerPrefs.Save();
            SavedLanguage = language;
            LanguageCfg cfg = ResUtil.LoadScriptableObject <LanguageCfg>($"Config/Localization/{SavedLanguage}");

            if (cfg == null)
            {
                Debug.LogError($"File Not Exits in Config/Localization/{SavedLanguage}");
                return;
            }
            wordsDics.Clear();
            foreach (var kw in cfg.keyWords)
            {
                wordsDics[kw.key] = kw.word;
            }
            LanugeChanged?.Invoke(SavedLanguage);
        }
예제 #4
0
        static LocalizationUtil()
        {
            int lag = PlayerPrefs.GetInt("FATTY_LANGUAGE", 0);

            SavedLanguage = (XIHLanguage)lag;
            if (SavedLanguage == XIHLanguage.none)
            {
                SystemLanguage language = Application.systemLanguage;
                if (language == SystemLanguage.English)
                {
                    SavedLanguage = XIHLanguage.en;
                }
                else if (language == SystemLanguage.ChineseTraditional)
                {
                    SavedLanguage = XIHLanguage.zh_TW;
                }
                else
                {
                    SavedLanguage = XIHLanguage.cn;
                }
            }
            SetLanguage(SavedLanguage);
        }
예제 #5
0
 private static Texture2D TranslateImgSpecific(string relativeName, XIHLanguage lag)
 {
     return(ResUtil.LoadSprite($"Sprite/Localization/{relativeName}_{lag}")?.texture);
 }
예제 #6
0
 void OnLanguageChanged(XIHLanguage language)
 {
     DoTranslate(relativePath);
 }
예제 #7
0
 void OnLanguageChanged(XIHLanguage language)
 {
     text.text = string.Format(LocalizationConsts.CUR_LAG, LocalizationConsts.LANGUAGE);
 }
예제 #8
0
 void OnLanguageChanged(XIHLanguage language)
 {
     DoTranslate(key, inserts);
 }