Esempio n. 1
0
        private bool LoadTranslations()
        {
            string path = FileSystem.Normalize(label.install_path);

            if (!System.IO.Directory.Exists(path))
            {
                return(false);
            }
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            HashSetPool <Localization.Locale, Mod> .PooledHashSet pooledHashSet = HashSetPool <Localization.Locale, Mod> .Allocate();

            FileInfo[] files = directoryInfo.GetFiles();
            foreach (FileInfo fileInfo in files)
            {
                if (!(fileInfo.Extension.ToLower() != ".po"))
                {
                    string[] lines = File.ReadAllLines(fileInfo.FullName, Encoding.UTF8);
                    pooledHashSet.Add(Localization.GetLocale(lines));
                    Dictionary <string, string> translated_strings = Localization.ExtractTranslatedStrings(lines, false);
                    Localization.OverloadStrings(translated_strings);
                }
            }
            if (pooledHashSet.Count == 0)
            {
                return(false);
            }
            Localization.Locale new_locale = pooledHashSet.First();
            if (!pooledHashSet.All((Localization.Locale locale) => locale == new_locale))
            {
                return(false);
            }
            Localization.SetLocale(new_locale);
            Localization.SwapToLocalizedFont(new_locale.FontName);
            KPlayerPrefs.SetString(Localization.SELECTED_LANGUAGE_TYPE_KEY, 2.ToString());
            KPlayerPrefs.SetString(Localization.SELECTED_LANGUAGE_CODE_KEY, new_locale.Code);
            return(true);
        }