12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Globalization;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading;
- using UnityEngine;
- namespace I2.Loc
- {
- public static class LocalizationManager
- {
- public static void InitializeIfNeeded()
- {
- if (string.IsNullOrEmpty(LocalizationManager.mCurrentLanguage) || LocalizationManager.Sources.Count == 0)
- {
- LocalizationManager.UpdateSources();
- LocalizationManager.SelectStartupLanguage();
- }
- }
- public static string GetVersion()
- {
- return "2.8.6 f2";
- }
- public static int GetRequiredWebServiceVersion()
- {
- return 5;
- }
- public static string GetWebServiceURL(LanguageSource source = null)
- {
- if (source != null && !string.IsNullOrEmpty(source.Google_WebServiceURL))
- {
- return source.Google_WebServiceURL;
- }
- LocalizationManager.InitializeIfNeeded();
- for (int i = 0; i < LocalizationManager.Sources.Count; i++)
- {
- if (LocalizationManager.Sources[i] != null && !string.IsNullOrEmpty(LocalizationManager.Sources[i].Google_WebServiceURL))
- {
- return LocalizationManager.Sources[i].Google_WebServiceURL;
- }
- }
- return string.Empty;
- }
- public static string CurrentLanguage
- {
- get
- {
- LocalizationManager.InitializeIfNeeded();
- return LocalizationManager.mCurrentLanguage;
- }
- set
- {
- LocalizationManager.InitializeIfNeeded();
- string supportedLanguage = LocalizationManager.GetSupportedLanguage(value);
- if (!string.IsNullOrEmpty(supportedLanguage) && LocalizationManager.mCurrentLanguage != supportedLanguage)
- {
- LocalizationManager.SetLanguageAndCode(supportedLanguage, LocalizationManager.GetLanguageCode(supportedLanguage), true, false);
- }
- }
- }
- public static string CurrentLanguageCode
- {
- get
- {
- LocalizationManager.InitializeIfNeeded();
- return LocalizationManager.mLanguageCode;
- }
- set
- {
- LocalizationManager.InitializeIfNeeded();
- if (LocalizationManager.mLanguageCode != value)
- {
- string languageFromCode = LocalizationManager.GetLanguageFromCode(value, true);
- if (!string.IsNullOrEmpty(languageFromCode))
- {
- LocalizationManager.SetLanguageAndCode(languageFromCode, value, true, false);
- }
- }
- }
- }
- public static string CurrentRegion
- {
- get
- {
- string currentLanguage = LocalizationManager.CurrentLanguage;
- int num = currentLanguage.IndexOfAny("/\\".ToCharArray());
- if (num > 0)
- {
- return currentLanguage.Substring(num + 1);
- }
- num = currentLanguage.IndexOfAny("[(".ToCharArray());
- int num2 = currentLanguage.LastIndexOfAny("])".ToCharArray());
- if (num > 0 && num != num2)
- {
- return currentLanguage.Substring(num + 1, num2 - num - 1);
- }
- return string.Empty;
- }
- set
- {
- string text = LocalizationManager.CurrentLanguage;
- int num = text.IndexOfAny("/\\".ToCharArray());
- if (num > 0)
- {
- LocalizationManager.CurrentLanguage = text.Substring(num + 1) + value;
- return;
- }
- num = text.IndexOfAny("[(".ToCharArray());
- int num2 = text.LastIndexOfAny("])".ToCharArray());
- if (num > 0 && num != num2)
- {
- text = text.Substring(num);
- }
- LocalizationManager.CurrentLanguage = text + "(" + value + ")";
- }
- }
- public static string CurrentRegionCode
- {
- get
- {
- string currentLanguageCode = LocalizationManager.CurrentLanguageCode;
- int num = currentLanguageCode.IndexOfAny(" -_/\\".ToCharArray());
- return (num >= 0) ? currentLanguageCode.Substring(num + 1) : string.Empty;
- }
- set
- {
- string text = LocalizationManager.CurrentLanguageCode;
- int num = text.IndexOfAny(" -_/\\".ToCharArray());
- if (num > 0)
- {
- text = text.Substring(0, num);
- }
- LocalizationManager.CurrentLanguageCode = text + "-" + value;
- }
- }
- public static CultureInfo CurrentCulture
- {
- get
- {
- return LocalizationManager.mCurrentCulture;
- }
- }
- public static void SetLanguageAndCode(string LanguageName, string LanguageCode, bool RememberLanguage = true, bool Force = false)
- {
- if (LocalizationManager.mCurrentLanguage != LanguageName || LocalizationManager.mLanguageCode != LanguageCode || Force)
- {
- if (RememberLanguage)
- {
- PersistentStorage.SetSetting_String("I2 Language", LanguageName);
- }
- LocalizationManager.mCurrentLanguage = LanguageName;
- LocalizationManager.mLanguageCode = LanguageCode;
- LocalizationManager.mCurrentCulture = LocalizationManager.CreateCultureForCode(LanguageCode);
- if (LocalizationManager.mChangeCultureInfo)
- {
- LocalizationManager.SetCurrentCultureInfo();
- }
- LocalizationManager.IsRight2Left = LocalizationManager.IsRTL(LocalizationManager.mLanguageCode);
- LocalizationManager.HasJoinedWords = GoogleLanguages.LanguageCode_HasJoinedWord(LocalizationManager.mLanguageCode);
- LocalizationManager.LocalizeAll(Force);
- }
- }
- private static CultureInfo CreateCultureForCode(string code)
- {
- CultureInfo result;
- try
- {
- result = CultureInfo.CreateSpecificCulture(code);
- }
- catch (Exception)
- {
- result = CultureInfo.InvariantCulture;
- }
- return result;
- }
- public static void EnableChangingCultureInfo(bool bEnable)
- {
- if (!LocalizationManager.mChangeCultureInfo && bEnable)
- {
- LocalizationManager.SetCurrentCultureInfo();
- }
- LocalizationManager.mChangeCultureInfo = bEnable;
- }
- private static void SetCurrentCultureInfo()
- {
- Thread.CurrentThread.CurrentCulture = LocalizationManager.mCurrentCulture;
- }
- private static void SelectStartupLanguage()
- {
- if (LocalizationManager.Sources.Count == 0)
- {
- return;
- }
- string setting_String = PersistentStorage.GetSetting_String("I2 Language", string.Empty);
- string currentDeviceLanguage = LocalizationManager.GetCurrentDeviceLanguage();
- if (!string.IsNullOrEmpty(setting_String) && LocalizationManager.HasLanguage(setting_String, true, false, true))
- {
- LocalizationManager.SetLanguageAndCode(setting_String, LocalizationManager.GetLanguageCode(setting_String), true, false);
- return;
- }
- if (!LocalizationManager.Sources[0].IgnoreDeviceLanguage)
- {
- string supportedLanguage = LocalizationManager.GetSupportedLanguage(currentDeviceLanguage);
- if (!string.IsNullOrEmpty(supportedLanguage))
- {
- LocalizationManager.SetLanguageAndCode(supportedLanguage, LocalizationManager.GetLanguageCode(supportedLanguage), false, false);
- return;
- }
- }
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- if (LocalizationManager.Sources[i].mLanguages.Count > 0)
- {
- for (int j = 0; j < LocalizationManager.Sources[i].mLanguages.Count; j++)
- {
- if (LocalizationManager.Sources[i].mLanguages[j].IsEnabled())
- {
- LocalizationManager.SetLanguageAndCode(LocalizationManager.Sources[i].mLanguages[j].Name, LocalizationManager.Sources[i].mLanguages[j].Code, false, false);
- return;
- }
- }
- }
- i++;
- }
- }
- public static bool HasLanguage(string Language, bool AllowDiscartingRegion = true, bool Initialize = true, bool SkipDisabled = true)
- {
- if (Initialize)
- {
- LocalizationManager.InitializeIfNeeded();
- }
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- if (LocalizationManager.Sources[i].GetLanguageIndex(Language, false, SkipDisabled) >= 0)
- {
- return true;
- }
- i++;
- }
- if (AllowDiscartingRegion)
- {
- int j = 0;
- int count2 = LocalizationManager.Sources.Count;
- while (j < count2)
- {
- if (LocalizationManager.Sources[j].GetLanguageIndex(Language, true, SkipDisabled) >= 0)
- {
- return true;
- }
- j++;
- }
- }
- return false;
- }
- public static string GetSupportedLanguage(string Language)
- {
- string languageCode = GoogleLanguages.GetLanguageCode(Language, false);
- if (!string.IsNullOrEmpty(languageCode))
- {
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- int languageIndexFromCode = LocalizationManager.Sources[i].GetLanguageIndexFromCode(languageCode, true);
- if (languageIndexFromCode >= 0)
- {
- return LocalizationManager.Sources[i].mLanguages[languageIndexFromCode].Name;
- }
- i++;
- }
- int j = 0;
- int count2 = LocalizationManager.Sources.Count;
- while (j < count2)
- {
- int languageIndexFromCode2 = LocalizationManager.Sources[j].GetLanguageIndexFromCode(languageCode, false);
- if (languageIndexFromCode2 >= 0)
- {
- return LocalizationManager.Sources[j].mLanguages[languageIndexFromCode2].Name;
- }
- j++;
- }
- }
- int k = 0;
- int count3 = LocalizationManager.Sources.Count;
- while (k < count3)
- {
- int languageIndex = LocalizationManager.Sources[k].GetLanguageIndex(Language, false, true);
- if (languageIndex >= 0)
- {
- return LocalizationManager.Sources[k].mLanguages[languageIndex].Name;
- }
- k++;
- }
- int l = 0;
- int count4 = LocalizationManager.Sources.Count;
- while (l < count4)
- {
- int languageIndex2 = LocalizationManager.Sources[l].GetLanguageIndex(Language, true, true);
- if (languageIndex2 >= 0)
- {
- return LocalizationManager.Sources[l].mLanguages[languageIndex2].Name;
- }
- l++;
- }
- return string.Empty;
- }
- public static string GetLanguageCode(string Language)
- {
- if (LocalizationManager.Sources.Count == 0)
- {
- LocalizationManager.UpdateSources();
- }
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- int languageIndex = LocalizationManager.Sources[i].GetLanguageIndex(Language, true, true);
- if (languageIndex >= 0)
- {
- return LocalizationManager.Sources[i].mLanguages[languageIndex].Code;
- }
- i++;
- }
- return string.Empty;
- }
- public static string GetLanguageFromCode(string Code, bool exactMatch = true)
- {
- if (LocalizationManager.Sources.Count == 0)
- {
- LocalizationManager.UpdateSources();
- }
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- int languageIndexFromCode = LocalizationManager.Sources[i].GetLanguageIndexFromCode(Code, exactMatch);
- if (languageIndexFromCode >= 0)
- {
- return LocalizationManager.Sources[i].mLanguages[languageIndexFromCode].Name;
- }
- i++;
- }
- return string.Empty;
- }
- public static List<string> GetAllLanguages(bool SkipDisabled = true)
- {
- if (LocalizationManager.Sources.Count == 0)
- {
- LocalizationManager.UpdateSources();
- }
- List<string> Languages = new List<string>();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- Languages.AddRange(from x in LocalizationManager.Sources[i].GetLanguages(SkipDisabled)
- where !Languages.Contains(x)
- select x);
- i++;
- }
- return Languages;
- }
- public static List<string> GetAllLanguagesCode(bool allowRegions = true, bool SkipDisabled = true)
- {
- List<string> Languages = new List<string>();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- Languages.AddRange(from x in LocalizationManager.Sources[i].GetLanguagesCode(allowRegions, SkipDisabled)
- where !Languages.Contains(x)
- select x);
- i++;
- }
- return Languages;
- }
- public static bool IsLanguageEnabled(string Language)
- {
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- if (!LocalizationManager.Sources[i].IsLanguageEnabled(Language))
- {
- return false;
- }
- i++;
- }
- return true;
- }
- private static void LoadCurrentLanguage()
- {
- for (int i = 0; i < LocalizationManager.Sources.Count; i++)
- {
- int languageIndex = LocalizationManager.Sources[i].GetLanguageIndex(LocalizationManager.mCurrentLanguage, true, false);
- LocalizationManager.Sources[i].LoadLanguage(languageIndex, true, true, true, false);
- }
- }
- public static void ApplyLocalizationParams(ref string translation)
- {
- LocalizationManager.ApplyLocalizationParams(ref translation, (string p) => LocalizationManager.GetLocalizationParam(p, null));
- }
- public static void ApplyLocalizationParams(ref string translation, GameObject root)
- {
- LocalizationManager.ApplyLocalizationParams(ref translation, (string p) => LocalizationManager.GetLocalizationParam(p, root));
- }
- public static void ApplyLocalizationParams(ref string translation, Dictionary<string, object> parameters)
- {
- LocalizationManager.ApplyLocalizationParams(ref translation, delegate(string p)
- {
- object result = null;
- if (parameters.TryGetValue(p, out result))
- {
- return result;
- }
- return null;
- });
- }
- public static void ApplyLocalizationParams(ref string translation, LocalizationManager._GetParam getParam)
- {
- if (translation == null)
- {
- return;
- }
- string text = null;
- int num = translation.Length;
- int num2 = 0;
- while (num2 >= 0 && num2 < translation.Length)
- {
- int num3 = translation.IndexOf("{[", num2);
- if (num3 < 0)
- {
- break;
- }
- int num4 = translation.IndexOf("]}", num3);
- if (num4 < 0)
- {
- break;
- }
- int num5 = translation.IndexOf("{[", num3 + 1);
- if (num5 > 0 && num5 < num4)
- {
- num2 = num5;
- }
- else
- {
- int num6 = (translation[num3 + 2] != '#') ? 2 : 3;
- string param = translation.Substring(num3 + num6, num4 - num3 - num6);
- string text2 = (string)getParam(param);
- if (text2 != null)
- {
- string text3;
- if (LocalizationManager.TryGetTranslation(text2, out text3, true, 0, true, false, null, null))
- {
- text2 = text3;
- }
- string oldValue = translation.Substring(num3, num4 - num3 + 2);
- translation = translation.Replace(oldValue, text2);
- int n = 0;
- if (int.TryParse(text2, out n))
- {
- text = GoogleLanguages.GetPluralType(LocalizationManager.CurrentLanguageCode, n).ToString();
- }
- num2 = num3 + text2.Length;
- }
- else
- {
- num2 = num4 + 2;
- }
- }
- }
- if (text != null)
- {
- string text4 = "[i2p_" + text + "]";
- int num7 = translation.IndexOf(text4, StringComparison.OrdinalIgnoreCase);
- if (num7 < 0)
- {
- num7 = 0;
- }
- else
- {
- num7 += text4.Length;
- }
- num = translation.IndexOf("[i2p_", num7 + 1, StringComparison.OrdinalIgnoreCase);
- if (num < 0)
- {
- num = translation.Length;
- }
- translation = translation.Substring(num7, num - num7);
- }
- }
- internal static string GetLocalizationParam(string ParamName, GameObject root)
- {
- if (root)
- {
- MonoBehaviour[] components = root.GetComponents<MonoBehaviour>();
- int i = 0;
- int num = components.Length;
- while (i < num)
- {
- ILocalizationParamsManager localizationParamsManager = components[i] as ILocalizationParamsManager;
- if (localizationParamsManager != null && components[i].enabled)
- {
- string parameterValue = localizationParamsManager.GetParameterValue(ParamName);
- if (parameterValue != null)
- {
- return parameterValue;
- }
- }
- i++;
- }
- }
- int j = 0;
- int count = LocalizationManager.ParamManagers.Count;
- while (j < count)
- {
- string parameterValue = LocalizationManager.ParamManagers[j].GetParameterValue(ParamName);
- if (parameterValue != null)
- {
- return parameterValue;
- }
- j++;
- }
- return null;
- }
- private static string GetPluralType(MatchCollection matches, string langCode, LocalizationManager._GetParam getParam)
- {
- int i = 0;
- int count = matches.Count;
- while (i < count)
- {
- Match match = matches[i];
- string value = match.Groups[match.Groups.Count - 1].Value;
- string text = (string)getParam(value);
- if (text != null)
- {
- int n = 0;
- if (int.TryParse(text, out n))
- {
- return GoogleLanguages.GetPluralType(langCode, n).ToString();
- }
- }
- i++;
- }
- return null;
- }
- public static string ApplyRTLfix(string line)
- {
- return LocalizationManager.ApplyRTLfix(line, 0, true);
- }
- public static string ApplyRTLfix(string line, int maxCharacters, bool ignoreNumbers)
- {
- if (string.IsNullOrEmpty(line))
- {
- return line;
- }
- char c = line[0];
- if (c == '!' || c == '.' || c == '?')
- {
- line = line.Substring(1) + c;
- }
- int num = -1;
- int num2 = 0;
- int num3 = 40000;
- num2 = 0;
- List<string> list = new List<string>();
- while (I2Utils.FindNextTag(line, num2, out num, out num2))
- {
- string str = "@@" + (char)(num3 + list.Count) + "@@";
- list.Add(line.Substring(num, num2 - num + 1));
- line = line.Substring(0, num) + str + line.Substring(num2 + 1);
- num2 = num + 5;
- }
- line = line.Replace("\r\n", "\n");
- line = I2Utils.SplitLine(line, maxCharacters);
- line = RTLFixer.Fix(line, true, !ignoreNumbers);
- for (int i = 0; i < list.Count; i++)
- {
- int length = line.Length;
- for (int j = 0; j < length; j++)
- {
- if (line[j] == '@' && line[j + 1] == '@' && (int)line[j + 2] >= num3 && line[j + 3] == '@' && line[j + 4] == '@')
- {
- int num4 = (int)line[j + 2] - num3;
- if (num4 % 2 == 0)
- {
- num4++;
- }
- else
- {
- num4--;
- }
- if (num4 >= list.Count)
- {
- num4 = list.Count - 1;
- }
- line = line.Substring(0, j) + list[num4] + line.Substring(j + 5);
- break;
- }
- }
- }
- return line;
- }
- public static string FixRTL_IfNeeded(string text, int maxCharacters = 0, bool ignoreNumber = false)
- {
- if (LocalizationManager.IsRight2Left)
- {
- return LocalizationManager.ApplyRTLfix(text, maxCharacters, ignoreNumber);
- }
- return text;
- }
- public static bool IsRTL(string Code)
- {
- return Array.IndexOf<string>(LocalizationManager.LanguagesRTL, Code) >= 0;
- }
- public static bool UpdateSources()
- {
- LocalizationManager.UnregisterDeletededSources();
- LocalizationManager.RegisterSourceInResources();
- LocalizationManager.RegisterSceneSources();
- return LocalizationManager.Sources.Count > 0;
- }
- private static void UnregisterDeletededSources()
- {
- for (int i = LocalizationManager.Sources.Count - 1; i >= 0; i--)
- {
- if (LocalizationManager.Sources[i] == null)
- {
- LocalizationManager.RemoveSource(LocalizationManager.Sources[i]);
- }
- }
- }
- private static void RegisterSceneSources()
- {
- LanguageSource[] array = (LanguageSource[])Resources.FindObjectsOfTypeAll(typeof(LanguageSource));
- int i = 0;
- int num = array.Length;
- while (i < num)
- {
- if (!LocalizationManager.Sources.Contains(array[i]))
- {
- LocalizationManager.AddSource(array[i]);
- }
- i++;
- }
- }
- private static void RegisterSourceInResources()
- {
- foreach (string name in LocalizationManager.GlobalSources)
- {
- GameObject asset = ResourceManager.pInstance.GetAsset<GameObject>(name);
- LanguageSource languageSource = (!asset) ? null : asset.GetComponent<LanguageSource>();
- if (languageSource && !LocalizationManager.Sources.Contains(languageSource))
- {
- languageSource.mIsGlobalSource = true;
- LocalizationManager.AddSource(languageSource);
- }
- }
- }
- internal static void AddSource(LanguageSource Source)
- {
- if (LocalizationManager.Sources.Contains(Source))
- {
- return;
- }
- LocalizationManager.Sources.Add(Source);
- if (Source.HasGoogleSpreadsheet() && Source.GoogleUpdateFrequency != LanguageSource.eGoogleUpdateFrequency.Never)
- {
- Source.Import_Google_FromCache();
- bool justCheck = false;
- if (Source.GoogleUpdateDelay > 0f)
- {
- CoroutineManager.Start(LocalizationManager.Delayed_Import_Google(Source, Source.GoogleUpdateDelay, justCheck));
- }
- else
- {
- Source.Import_Google(false, justCheck);
- }
- }
- for (int i = 0; i < Source.mLanguages.Count<LanguageData>(); i++)
- {
- Source.mLanguages[i].SetLoaded(true);
- }
- if (Source.mDictionary.Count == 0)
- {
- Source.UpdateDictionary(true);
- }
- }
- private static IEnumerator Delayed_Import_Google(LanguageSource source, float delay, bool justCheck)
- {
- yield return new WaitForSeconds(delay);
- source.Import_Google(false, justCheck);
- yield break;
- }
- internal static void RemoveSource(LanguageSource Source)
- {
- LocalizationManager.Sources.Remove(Source);
- }
- public static bool IsGlobalSource(string SourceName)
- {
- return Array.IndexOf<string>(LocalizationManager.GlobalSources, SourceName) >= 0;
- }
- public static LanguageSource GetSourceContaining(string term, bool fallbackToFirst = true)
- {
- if (!string.IsNullOrEmpty(term))
- {
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- if (LocalizationManager.Sources[i].GetTermData(term, false) != null)
- {
- return LocalizationManager.Sources[i];
- }
- i++;
- }
- }
- return (!fallbackToFirst || LocalizationManager.Sources.Count <= 0) ? null : LocalizationManager.Sources[0];
- }
- public static UnityEngine.Object FindAsset(string value)
- {
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- UnityEngine.Object @object = LocalizationManager.Sources[i].FindAsset(value);
- if (@object)
- {
- return @object;
- }
- i++;
- }
- return null;
- }
- public static string GetCurrentDeviceLanguage()
- {
- if (string.IsNullOrEmpty(LocalizationManager.mCurrentDeviceLanguage))
- {
- LocalizationManager.DetectDeviceLanguage();
- }
- return LocalizationManager.mCurrentDeviceLanguage;
- }
- private static void DetectDeviceLanguage()
- {
- LocalizationManager.mCurrentDeviceLanguage = Application.systemLanguage.ToString();
- if (LocalizationManager.mCurrentDeviceLanguage == "ChineseSimplified")
- {
- LocalizationManager.mCurrentDeviceLanguage = "Chinese (Simplified)";
- }
- if (LocalizationManager.mCurrentDeviceLanguage == "ChineseTraditional")
- {
- LocalizationManager.mCurrentDeviceLanguage = "Chinese (Traditional)";
- }
- }
- public static void RegisterTarget(ILocalizeTargetDescriptor desc)
- {
- if (LocalizationManager.mLocalizeTargets.FindIndex((ILocalizeTargetDescriptor x) => x.Name == desc.Name) != -1)
- {
- return;
- }
- for (int i = 0; i < LocalizationManager.mLocalizeTargets.Count; i++)
- {
- if (LocalizationManager.mLocalizeTargets[i].Priority > desc.Priority)
- {
- LocalizationManager.mLocalizeTargets.Insert(i, desc);
- return;
- }
- }
- LocalizationManager.mLocalizeTargets.Add(desc);
- }
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event LocalizationManager.OnLocalizeCallback OnLocalizeEvent;
- public static string GetTranslation(string Term, bool FixForRTL = true, int maxLineLengthForRTL = 0, bool ignoreRTLnumbers = true, bool applyParameters = false, GameObject localParametersRoot = null, string overrideLanguage = null)
- {
- string result = null;
- LocalizationManager.TryGetTranslation(Term, out result, FixForRTL, maxLineLengthForRTL, ignoreRTLnumbers, applyParameters, localParametersRoot, overrideLanguage);
- return result;
- }
- public static string GetTermTranslation(string Term, bool FixForRTL = true, int maxLineLengthForRTL = 0, bool ignoreRTLnumbers = true, bool applyParameters = false, GameObject localParametersRoot = null, string overrideLanguage = null)
- {
- return LocalizationManager.GetTranslation(Term, FixForRTL, maxLineLengthForRTL, ignoreRTLnumbers, applyParameters, localParametersRoot, overrideLanguage);
- }
- public static bool TryGetTranslation(string Term, out string Translation, bool FixForRTL = true, int maxLineLengthForRTL = 0, bool ignoreRTLnumbers = true, bool applyParameters = false, GameObject localParametersRoot = null, string overrideLanguage = null)
- {
- Translation = null;
- if (string.IsNullOrEmpty(Term))
- {
- return false;
- }
- LocalizationManager.InitializeIfNeeded();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- if (LocalizationManager.Sources[i].TryGetTranslation(Term, out Translation, overrideLanguage, null, false, false))
- {
- if (applyParameters)
- {
- LocalizationManager.ApplyLocalizationParams(ref Translation, localParametersRoot);
- }
- if (LocalizationManager.IsRight2Left && FixForRTL)
- {
- Translation = LocalizationManager.ApplyRTLfix(Translation, maxLineLengthForRTL, ignoreRTLnumbers);
- }
- return true;
- }
- i++;
- }
- return false;
- }
- public static string GetAppName(string languageCode)
- {
- if (!string.IsNullOrEmpty(languageCode))
- {
- for (int i = 0; i < LocalizationManager.Sources.Count; i++)
- {
- if (!string.IsNullOrEmpty(LocalizationManager.Sources[i].mTerm_AppName))
- {
- int languageIndexFromCode = LocalizationManager.Sources[i].GetLanguageIndexFromCode(languageCode, false);
- if (languageIndexFromCode >= 0)
- {
- TermData termData = LocalizationManager.Sources[i].GetTermData(LocalizationManager.Sources[i].mTerm_AppName, false);
- if (termData != null)
- {
- string translation = termData.GetTranslation(languageIndexFromCode, null);
- if (!string.IsNullOrEmpty(translation))
- {
- return translation;
- }
- }
- }
- }
- }
- }
- return Application.productName;
- }
- public static void LocalizeAll(bool Force = false)
- {
- LocalizationManager.LoadCurrentLanguage();
- if (!Application.isPlaying)
- {
- LocalizationManager.DoLocalizeAll(Force);
- return;
- }
- LocalizationManager.mLocalizeIsScheduledWithForcedValue = (LocalizationManager.mLocalizeIsScheduledWithForcedValue || Force);
- if (LocalizationManager.mLocalizeIsScheduled)
- {
- return;
- }
- CoroutineManager.Start(LocalizationManager.Coroutine_LocalizeAll());
- }
- private static IEnumerator Coroutine_LocalizeAll()
- {
- LocalizationManager.mLocalizeIsScheduled = true;
- yield return null;
- LocalizationManager.mLocalizeIsScheduled = false;
- bool force = LocalizationManager.mLocalizeIsScheduledWithForcedValue;
- LocalizationManager.mLocalizeIsScheduledWithForcedValue = false;
- LocalizationManager.DoLocalizeAll(force);
- yield break;
- }
- private static void DoLocalizeAll(bool Force = false)
- {
- Localize[] array = (Localize[])Resources.FindObjectsOfTypeAll(typeof(Localize));
- int i = 0;
- int num = array.Length;
- while (i < num)
- {
- Localize localize = array[i];
- localize.OnLocalize(Force);
- i++;
- }
- if (LocalizationManager.OnLocalizeEvent != null)
- {
- LocalizationManager.OnLocalizeEvent();
- }
- ResourceManager.pInstance.CleanResourceCache();
- }
- public static List<string> GetCategories()
- {
- List<string> list = new List<string>();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- LocalizationManager.Sources[i].GetCategories(false, list);
- i++;
- }
- return list;
- }
- public static List<string> GetTermsList(string Category = null)
- {
- if (LocalizationManager.Sources.Count == 0)
- {
- LocalizationManager.UpdateSources();
- }
- if (LocalizationManager.Sources.Count == 1)
- {
- return LocalizationManager.Sources[0].GetTermsList(Category);
- }
- HashSet<string> hashSet = new HashSet<string>();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- hashSet.UnionWith(LocalizationManager.Sources[i].GetTermsList(Category));
- i++;
- }
- return new List<string>(hashSet);
- }
- public static TermData GetTermData(string term)
- {
- LocalizationManager.InitializeIfNeeded();
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- TermData termData = LocalizationManager.Sources[i].GetTermData(term, false);
- if (termData != null)
- {
- return termData;
- }
- i++;
- }
- return null;
- }
- private static string mCurrentLanguage;
- private static string mLanguageCode;
- private static CultureInfo mCurrentCulture;
- private static bool mChangeCultureInfo = false;
- public static bool IsRight2Left = false;
- public static bool HasJoinedWords = false;
- public static List<ILocalizationParamsManager> ParamManagers = new List<ILocalizationParamsManager>();
- private static string[] LanguagesRTL = new string[]
- {
- "ar-DZ",
- "ar",
- "ar-BH",
- "ar-EG",
- "ar-IQ",
- "ar-JO",
- "ar-KW",
- "ar-LB",
- "ar-LY",
- "ar-MA",
- "ar-OM",
- "ar-QA",
- "ar-SA",
- "ar-SY",
- "ar-TN",
- "ar-AE",
- "ar-YE",
- "he",
- "ur",
- "ji"
- };
- public static List<LanguageSource> Sources = new List<LanguageSource>();
- public static string[] GlobalSources = new string[]
- {
- "I2Languages"
- };
- private static string mCurrentDeviceLanguage;
- public static List<ILocalizeTargetDescriptor> mLocalizeTargets = new List<ILocalizeTargetDescriptor>();
- private static bool mLocalizeIsScheduled = false;
- private static bool mLocalizeIsScheduledWithForcedValue = false;
- public static bool HighlightLocalizedTargets = false;
- public delegate object _GetParam(string param);
- public delegate void OnLocalizeCallback();
- }
- }
|