123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace I2.Loc
- {
- [AddComponentMenu("I2/Localization/Source")]
- [ExecuteInEditMode]
- public class LanguageSource : MonoBehaviour
- {
- private void Awake()
- {
- this.NeverDestroy = false;
- if (this.NeverDestroy)
- {
- if (this.ManagerHasASimilarSource())
- {
- UnityEngine.Object.Destroy(this);
- return;
- }
- if (Application.isPlaying)
- {
- UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
- }
- }
- LocalizationManager.AddSource(this);
- this.UpdateDictionary(false);
- this.UpdateAssetDictionary();
- LocalizationManager.LocalizeAll(true);
- }
- private void OnDestroy()
- {
- this.NeverDestroy = false;
- if (!this.NeverDestroy)
- {
- LocalizationManager.RemoveSource(this);
- }
- }
- public string GetSourceName()
- {
- string text = base.gameObject.name;
- Transform parent = base.transform.parent;
- while (parent)
- {
- text = parent.name + "_" + text;
- parent = parent.parent;
- }
- return text;
- }
- public bool IsEqualTo(LanguageSource Source)
- {
- if (Source.mLanguages.Count != this.mLanguages.Count)
- {
- return false;
- }
- int i = 0;
- int count = this.mLanguages.Count;
- while (i < count)
- {
- if (Source.GetLanguageIndex(this.mLanguages[i].Name, true, true) < 0)
- {
- return false;
- }
- i++;
- }
- if (Source.mTerms.Count != this.mTerms.Count)
- {
- return false;
- }
- for (int j = 0; j < this.mTerms.Count; j++)
- {
- if (Source.GetTermData(this.mTerms[j].Term, false) == null)
- {
- return false;
- }
- }
- return true;
- }
- internal bool ManagerHasASimilarSource()
- {
- int i = 0;
- int count = LocalizationManager.Sources.Count;
- while (i < count)
- {
- LanguageSource languageSource = LocalizationManager.Sources[i];
- if (languageSource != null && languageSource.IsEqualTo(this) && languageSource != this)
- {
- return true;
- }
- i++;
- }
- return false;
- }
- public void ClearAllData()
- {
- this.mTerms.Clear();
- this.mLanguages.Clear();
- this.mDictionary.Clear();
- this.mAssetDictionary.Clear();
- }
- public bool IsGlobalSource()
- {
- return this.mIsGlobalSource;
- }
- public void UpdateAssetDictionary()
- {
- this.Assets.RemoveAll((UnityEngine.Object x) => x == null);
- this.mAssetDictionary = this.Assets.Distinct<UnityEngine.Object>().ToDictionary((UnityEngine.Object o) => o.name);
- }
- public UnityEngine.Object FindAsset(string Name)
- {
- if (this.Assets != null)
- {
- if (this.mAssetDictionary == null || this.mAssetDictionary.Count != this.Assets.Count)
- {
- this.UpdateAssetDictionary();
- }
- UnityEngine.Object result;
- if (this.mAssetDictionary.TryGetValue(Name, out result))
- {
- return result;
- }
- }
- return null;
- }
- public bool HasAsset(UnityEngine.Object Obj)
- {
- return this.Assets.Contains(Obj);
- }
- public void AddAsset(UnityEngine.Object Obj)
- {
- if (this.Assets.Contains(Obj))
- {
- return;
- }
- this.Assets.Add(Obj);
- this.UpdateAssetDictionary();
- }
- public string Export_I2CSV(string Category, char Separator = ',', bool specializationsAsRows = true)
- {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.Append("Key[*]Type[*]Desc");
- foreach (LanguageData languageData in this.mLanguages)
- {
- stringBuilder.Append("[*]");
- if (!languageData.IsEnabled())
- {
- stringBuilder.Append('$');
- }
- stringBuilder.Append(GoogleLanguages.GetCodedLanguage(languageData.Name, languageData.Code));
- }
- stringBuilder.Append("[ln]");
- int count = this.mLanguages.Count;
- bool flag = true;
- foreach (TermData termData in this.mTerms)
- {
- string term;
- if (string.IsNullOrEmpty(Category) || (Category == LanguageSource.EmptyCategory && termData.Term.IndexOfAny(LanguageSource.CategorySeparators) < 0))
- {
- term = termData.Term;
- }
- else
- {
- if (!termData.Term.StartsWith(Category + "/") || !(Category != termData.Term))
- {
- continue;
- }
- term = termData.Term.Substring(Category.Length + 1);
- }
- if (!flag)
- {
- stringBuilder.Append("[ln]");
- }
- flag = false;
- if (!specializationsAsRows)
- {
- LanguageSource.AppendI2Term(stringBuilder, count, term, termData, Separator, null);
- }
- else
- {
- List<string> allSpecializations = termData.GetAllSpecializations();
- for (int i = 0; i < allSpecializations.Count; i++)
- {
- if (i != 0)
- {
- stringBuilder.Append("[ln]");
- }
- string forceSpecialization = allSpecializations[i];
- LanguageSource.AppendI2Term(stringBuilder, count, term, termData, Separator, forceSpecialization);
- }
- }
- }
- return stringBuilder.ToString();
- }
- private static void AppendI2Term(StringBuilder Builder, int nLanguages, string Term, TermData termData, char Separator, string forceSpecialization)
- {
- LanguageSource.AppendI2Text(Builder, Term);
- if (!string.IsNullOrEmpty(forceSpecialization) && forceSpecialization != "Any")
- {
- Builder.Append("[");
- Builder.Append(forceSpecialization);
- Builder.Append("]");
- }
- Builder.Append("[*]");
- Builder.Append(termData.TermType.ToString());
- Builder.Append("[*]");
- Builder.Append(termData.Description);
- for (int i = 0; i < Mathf.Min(nLanguages, termData.Languages.Length); i++)
- {
- Builder.Append("[*]");
- string text = termData.Languages[i];
- if (!string.IsNullOrEmpty(forceSpecialization))
- {
- text = termData.GetTranslation(i, forceSpecialization);
- }
- LanguageSource.AppendI2Text(Builder, text);
- }
- }
- private static void AppendI2Text(StringBuilder Builder, string text)
- {
- if (string.IsNullOrEmpty(text))
- {
- return;
- }
- if (text.StartsWith("'") || text.StartsWith("="))
- {
- Builder.Append('\'');
- }
- Builder.Append(text);
- }
- private string Export_Language_to_Cache(int langIndex, bool fillTermWithFallback)
- {
- if (!this.mLanguages[langIndex].IsLoaded())
- {
- return null;
- }
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < this.mTerms.Count; i++)
- {
- if (i > 0)
- {
- stringBuilder.Append("[i2t]");
- }
- TermData termData = this.mTerms[i];
- string text = termData.Languages[langIndex];
- if (this.OnMissingTranslation == LanguageSource.MissingTranslationAction.Fallback && string.IsNullOrEmpty(text) && this.TryGetFallbackTranslation(termData, out text, langIndex, null, true))
- {
- stringBuilder.Append("[i2fb]");
- if (fillTermWithFallback)
- {
- termData.Languages[langIndex] = text;
- }
- }
- if (!string.IsNullOrEmpty(text))
- {
- stringBuilder.Append(text);
- }
- }
- return stringBuilder.ToString();
- }
- public string Export_CSV(string Category, char Separator = ',', bool specializationsAsRows = true)
- {
- StringBuilder stringBuilder = new StringBuilder();
- int count = this.mLanguages.Count;
- stringBuilder.AppendFormat("Key{0}Type{0}Desc", Separator);
- foreach (LanguageData languageData in this.mLanguages)
- {
- stringBuilder.Append(Separator);
- if (!languageData.IsEnabled())
- {
- stringBuilder.Append('$');
- }
- LanguageSource.AppendString(stringBuilder, GoogleLanguages.GetCodedLanguage(languageData.Name, languageData.Code), Separator);
- }
- stringBuilder.Append("\n");
- this.mTerms.Sort((TermData a, TermData b) => string.CompareOrdinal(a.Term, b.Term));
- foreach (TermData termData in this.mTerms)
- {
- string term;
- if (string.IsNullOrEmpty(Category) || (Category == LanguageSource.EmptyCategory && termData.Term.IndexOfAny(LanguageSource.CategorySeparators) < 0))
- {
- term = termData.Term;
- }
- else
- {
- if (!termData.Term.StartsWith(Category + "/") || !(Category != termData.Term))
- {
- continue;
- }
- term = termData.Term.Substring(Category.Length + 1);
- }
- if (specializationsAsRows)
- {
- foreach (string specialization in termData.GetAllSpecializations())
- {
- LanguageSource.AppendTerm(stringBuilder, count, term, termData, specialization, Separator);
- }
- }
- else
- {
- LanguageSource.AppendTerm(stringBuilder, count, term, termData, null, Separator);
- }
- }
- return stringBuilder.ToString();
- }
- private static void AppendTerm(StringBuilder Builder, int nLanguages, string Term, TermData termData, string specialization, char Separator)
- {
- LanguageSource.AppendString(Builder, Term, Separator);
- if (!string.IsNullOrEmpty(specialization) && specialization != "Any")
- {
- Builder.AppendFormat("[{0}]", specialization);
- }
- Builder.Append(Separator);
- Builder.Append(termData.TermType.ToString());
- Builder.Append(Separator);
- LanguageSource.AppendString(Builder, termData.Description, Separator);
- for (int i = 0; i < Mathf.Min(nLanguages, termData.Languages.Length); i++)
- {
- Builder.Append(Separator);
- string text = termData.Languages[i];
- if (!string.IsNullOrEmpty(specialization))
- {
- text = termData.GetTranslation(i, specialization);
- }
- LanguageSource.AppendTranslation(Builder, text, Separator, null);
- }
- Builder.Append("\n");
- }
- private static void AppendString(StringBuilder Builder, string Text, char Separator)
- {
- if (string.IsNullOrEmpty(Text))
- {
- return;
- }
- Text = Text.Replace("\\n", "\n");
- if (Text.IndexOfAny((Separator + "\n\"").ToCharArray()) >= 0)
- {
- Text = Text.Replace("\"", "\"\"");
- Builder.AppendFormat("\"{0}\"", Text);
- }
- else
- {
- Builder.Append(Text);
- }
- }
- private static void AppendTranslation(StringBuilder Builder, string Text, char Separator, string tags)
- {
- if (string.IsNullOrEmpty(Text))
- {
- return;
- }
- Text = Text.Replace("\\n", "\n");
- if (Text.IndexOfAny((Separator + "\n\"").ToCharArray()) >= 0)
- {
- Text = Text.Replace("\"", "\"\"");
- Builder.AppendFormat("\"{0}{1}\"", tags, Text);
- }
- else
- {
- Builder.Append(tags);
- Builder.Append(Text);
- }
- }
- public WWW Export_Google_CreateWWWcall(eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
- {
- string value = this.Export_Google_CreateData();
- WWWForm wwwform = new WWWForm();
- wwwform.AddField("key", this.Google_SpreadsheetKey);
- wwwform.AddField("action", "SetLanguageSource");
- wwwform.AddField("data", value);
- wwwform.AddField("updateMode", UpdateMode.ToString());
- return new WWW(LocalizationManager.GetWebServiceURL(this), wwwform);
- }
- private string Export_Google_CreateData()
- {
- List<string> categories = this.GetCategories(true, null);
- StringBuilder stringBuilder = new StringBuilder();
- bool flag = true;
- foreach (string text in categories)
- {
- if (flag)
- {
- flag = false;
- }
- else
- {
- stringBuilder.Append("<I2Loc>");
- }
- bool flag2 = true;
- string category = text;
- bool specializationsAsRows = flag2;
- string value = this.Export_I2CSV(category, ',', specializationsAsRows);
- stringBuilder.Append(text);
- stringBuilder.Append("<I2Loc>");
- stringBuilder.Append(value);
- }
- return stringBuilder.ToString();
- }
- public string Import_CSV(string Category, string CSVstring, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace, char Separator = ',')
- {
- List<string[]> csv = LocalizationReader.ReadCSV(CSVstring, Separator);
- return this.Import_CSV(Category, csv, UpdateMode);
- }
- public string Import_I2CSV(string Category, string I2CSVstring, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
- {
- List<string[]> csv = LocalizationReader.ReadI2CSV(I2CSVstring);
- return this.Import_CSV(Category, csv, UpdateMode);
- }
- public string Import_CSV(string Category, List<string[]> CSV, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
- {
- string[] array = CSV[0];
- int num = 1;
- int num2 = -1;
- int num3 = -1;
- string[] texts = new string[]
- {
- "Key"
- };
- string[] texts2 = new string[]
- {
- "Type"
- };
- string[] texts3 = new string[]
- {
- "Desc",
- "Description"
- };
- if (array.Length > 1 && this.ArrayContains(array[0], texts))
- {
- if (UpdateMode == eSpreadsheetUpdateMode.Replace)
- {
- this.ClearAllData();
- }
- if (array.Length > 2)
- {
- if (this.ArrayContains(array[1], texts2))
- {
- num2 = 1;
- num = 2;
- }
- if (this.ArrayContains(array[1], texts3))
- {
- num3 = 1;
- num = 2;
- }
- }
- if (array.Length > 3)
- {
- if (this.ArrayContains(array[2], texts2))
- {
- num2 = 2;
- num = 3;
- }
- if (this.ArrayContains(array[2], texts3))
- {
- num3 = 2;
- num = 3;
- }
- }
- int num4 = Mathf.Max(array.Length - num, 0);
- int[] array2 = new int[num4];
- for (int i = 0; i < num4; i++)
- {
- if (string.IsNullOrEmpty(array[i + num]))
- {
- array2[i] = -1;
- }
- else
- {
- string text = array[i + num];
- bool flag = true;
- if (text.StartsWith("$"))
- {
- flag = false;
- text = text.Substring(1);
- }
- string text2;
- string text3;
- GoogleLanguages.UnPackCodeFromLanguageName(text, out text2, out text3);
- int num5;
- if (!string.IsNullOrEmpty(text3))
- {
- num5 = this.GetLanguageIndexFromCode(text3, true);
- }
- else
- {
- num5 = this.GetLanguageIndex(text2, true, false);
- }
- if (num5 < 0)
- {
- LanguageData languageData = new LanguageData();
- languageData.Name = text2;
- languageData.Code = text3;
- languageData.Flags = (byte)(0 | ((!flag) ? 1 : 0));
- this.mLanguages.Add(languageData);
- num5 = this.mLanguages.Count - 1;
- }
- array2[i] = num5;
- }
- }
- num4 = this.mLanguages.Count;
- int j = 0;
- int count = this.mTerms.Count;
- while (j < count)
- {
- TermData termData = this.mTerms[j];
- if (termData.Languages.Length < num4)
- {
- Array.Resize<string>(ref termData.Languages, num4);
- Array.Resize<byte>(ref termData.Flags, num4);
- }
- j++;
- }
- int k = 1;
- int count2 = CSV.Count;
- while (k < count2)
- {
- array = CSV[k];
- string text4 = (!string.IsNullOrEmpty(Category)) ? (Category + "/" + array[0]) : array[0];
- string text5 = null;
- if (text4.EndsWith("]"))
- {
- int num6 = text4.LastIndexOf('[');
- if (num6 > 0)
- {
- text5 = text4.Substring(num6 + 1, text4.Length - num6 - 2);
- if (text5 == "touch")
- {
- text5 = "Touch";
- }
- text4 = text4.Remove(num6);
- }
- }
- LanguageSource.ValidateFullTerm(ref text4);
- if (!string.IsNullOrEmpty(text4))
- {
- TermData termData2 = this.GetTermData(text4, false);
- if (termData2 == null)
- {
- termData2 = new TermData();
- termData2.Term = text4;
- termData2.Languages = new string[this.mLanguages.Count];
- termData2.Flags = new byte[this.mLanguages.Count];
- for (int l = 0; l < this.mLanguages.Count; l++)
- {
- termData2.Languages[l] = string.Empty;
- }
- this.mTerms.Add(termData2);
- this.mDictionary.Add(text4, termData2);
- }
- else if (UpdateMode == eSpreadsheetUpdateMode.AddNewTerms)
- {
- goto IL_461;
- }
- if (num2 > 0)
- {
- termData2.TermType = LanguageSource.GetTermType(array[num2]);
- }
- if (num3 > 0)
- {
- termData2.Description = array[num3];
- }
- int num7 = 0;
- while (num7 < array2.Length && num7 < array.Length - num)
- {
- if (!string.IsNullOrEmpty(array[num7 + num]))
- {
- int num8 = array2[num7];
- if (num8 >= 0)
- {
- string text6 = array[num7 + num];
- if (text6 == "-")
- {
- text6 = string.Empty;
- }
- else if (text6 == string.Empty)
- {
- text6 = null;
- }
- termData2.SetTranslation(num8, text6, text5);
- }
- }
- num7++;
- }
- }
- IL_461:
- k++;
- }
- return string.Empty;
- }
- return "Bad Spreadsheet Format.\nFirst columns should be 'Key', 'Type' and 'Desc'";
- }
- private bool ArrayContains(string MainText, params string[] texts)
- {
- int i = 0;
- int num = texts.Length;
- while (i < num)
- {
- if (MainText.IndexOf(texts[i], StringComparison.OrdinalIgnoreCase) >= 0)
- {
- return true;
- }
- i++;
- }
- return false;
- }
- public static eTermType GetTermType(string type)
- {
- int i = 0;
- int num = 10;
- while (i <= num)
- {
- eTermType eTermType = (eTermType)i;
- if (string.Equals(eTermType.ToString(), type, StringComparison.OrdinalIgnoreCase))
- {
- return (eTermType)i;
- }
- i++;
- }
- return eTermType.Text;
- }
- private void Import_Language_from_Cache(int langIndex, string langData, bool useFallback, bool onlyCurrentSpecialization)
- {
- int num = 0;
- int num2;
- for (int i = 0; i < langData.Length; i = num2 + 5)
- {
- TermData termData = this.mTerms[num];
- num++;
- num2 = langData.IndexOf("[i2t]", i);
- if (num2 < 0)
- {
- num2 = langData.Length;
- }
- string text = null;
- if (i != num2)
- {
- text = langData.Substring(i, num2 - i);
- if (text.StartsWith("[i2fb]"))
- {
- text = ((!useFallback) ? null : text.Substring(6));
- }
- if (onlyCurrentSpecialization && text != null)
- {
- text = SpecializationManager.GetSpecializedText(text, null);
- }
- }
- termData.Languages[langIndex] = text;
- }
- }
- public event Action<LanguageSource, bool, string> Event_OnSourceUpdateFromGoogle;
- public static void FreeUnusedLanguages()
- {
- LanguageSource languageSource = LocalizationManager.Sources[0];
- int languageIndex = languageSource.GetLanguageIndex(LocalizationManager.CurrentLanguage, true, true);
- for (int i = 0; i < languageSource.mTerms.Count; i++)
- {
- TermData termData = languageSource.mTerms[i];
- for (int j = 0; j < termData.Languages.Length; j++)
- {
- if (j != languageIndex)
- {
- termData.Languages[j] = null;
- }
- }
- }
- }
- public void Import_Google_FromCache()
- {
- if (this.GoogleUpdateFrequency == LanguageSource.eGoogleUpdateFrequency.Never)
- {
- return;
- }
- if (!I2Utils.IsPlaying())
- {
- return;
- }
- string sourcePlayerPrefName = this.GetSourcePlayerPrefName();
- string text = PersistentStorage.LoadFile(PersistentStorage.eFileType.Persistent, "I2Source_" + sourcePlayerPrefName + ".loc", false);
- if (string.IsNullOrEmpty(text))
- {
- return;
- }
- if (text.StartsWith("[i2e]", StringComparison.Ordinal))
- {
- text = StringObfucator.Decode(text.Substring(5, text.Length - 5));
- }
- bool flag = false;
- string text2 = this.Google_LastUpdatedVersion;
- if (PersistentStorage.HasSetting("I2SourceVersion_" + sourcePlayerPrefName))
- {
- text2 = PersistentStorage.GetSetting_String("I2SourceVersion_" + sourcePlayerPrefName, this.Google_LastUpdatedVersion);
- flag = this.IsNewerVersion(this.Google_LastUpdatedVersion, text2);
- }
- if (!flag)
- {
- PersistentStorage.DeleteFile(PersistentStorage.eFileType.Persistent, "I2Source_" + sourcePlayerPrefName + ".loc", false);
- PersistentStorage.DeleteSetting("I2SourceVersion_" + sourcePlayerPrefName);
- return;
- }
- if (text2.Length > 19)
- {
- text2 = string.Empty;
- }
- this.Google_LastUpdatedVersion = text2;
- this.Import_Google_Result(text, eSpreadsheetUpdateMode.Replace, false);
- }
- private bool IsNewerVersion(string currentVersion, string newVersion)
- {
- long num;
- long num2;
- return !string.IsNullOrEmpty(newVersion) && (string.IsNullOrEmpty(currentVersion) || (!long.TryParse(newVersion, out num) || !long.TryParse(currentVersion, out num2)) || num > num2);
- }
- public void Import_Google(bool ForceUpdate, bool justCheck)
- {
- if (!ForceUpdate && this.GoogleUpdateFrequency == LanguageSource.eGoogleUpdateFrequency.Never)
- {
- return;
- }
- if (!I2Utils.IsPlaying())
- {
- return;
- }
- LanguageSource.eGoogleUpdateFrequency googleUpdateFrequency = this.GoogleUpdateFrequency;
- string sourcePlayerPrefName = this.GetSourcePlayerPrefName();
- if (!ForceUpdate && googleUpdateFrequency != LanguageSource.eGoogleUpdateFrequency.Always)
- {
- string setting_String = PersistentStorage.GetSetting_String("LastGoogleUpdate_" + sourcePlayerPrefName, string.Empty);
- try
- {
- DateTime d;
- if (DateTime.TryParse(setting_String, out d))
- {
- double totalDays = (DateTime.Now - d).TotalDays;
- switch (googleUpdateFrequency)
- {
- case LanguageSource.eGoogleUpdateFrequency.Daily:
- if (totalDays < 1.0)
- {
- return;
- }
- break;
- case LanguageSource.eGoogleUpdateFrequency.Weekly:
- if (totalDays < 8.0)
- {
- return;
- }
- break;
- case LanguageSource.eGoogleUpdateFrequency.Monthly:
- if (totalDays < 31.0)
- {
- return;
- }
- break;
- case LanguageSource.eGoogleUpdateFrequency.OnlyOnce:
- return;
- }
- }
- }
- catch (Exception)
- {
- }
- }
- PersistentStorage.SetSetting_String("LastGoogleUpdate_" + sourcePlayerPrefName, DateTime.Now.ToString());
- CoroutineManager.Start(this.Import_Google_Coroutine(justCheck));
- }
- private string GetSourcePlayerPrefName()
- {
- string text = base.name;
- if (!string.IsNullOrEmpty(this.Google_SpreadsheetKey))
- {
- text += this.Google_SpreadsheetKey;
- }
- if (Array.IndexOf<string>(LocalizationManager.GlobalSources, base.name) >= 0)
- {
- return text;
- }
- return SceneManager.GetActiveScene().name + "_" + text;
- }
- private IEnumerator Import_Google_Coroutine(bool JustCheck)
- {
- WWW www = this.Import_Google_CreateWWWcall(false, JustCheck);
- if (www == null)
- {
- yield break;
- }
- while (!www.isDone)
- {
- yield return null;
- }
- bool notError = string.IsNullOrEmpty(www.error);
- string wwwText = null;
- if (notError)
- {
- byte[] bytes = www.bytes;
- wwwText = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
- bool flag = string.IsNullOrEmpty(wwwText) || wwwText == "\"\"";
- if (JustCheck)
- {
- if (!flag)
- {
- Debug.LogWarning("Spreadsheet is not up-to-date and Google Live Synchronization is enabled\nWhen playing in the device the Spreadsheet will be downloaded and translations may not behave as what you see in the editor.\nTo fix this, Import or Export replace to Google");
- }
- yield break;
- }
- if (!flag)
- {
- string value = this.Import_Google_Result(wwwText, eSpreadsheetUpdateMode.Replace, true);
- if (string.IsNullOrEmpty(value))
- {
- if (this.Event_OnSourceUpdateFromGoogle != null)
- {
- this.Event_OnSourceUpdateFromGoogle(this, true, www.error);
- }
- LocalizationManager.LocalizeAll(true);
- Debug.Log("Done Google Sync");
- }
- else
- {
- if (this.Event_OnSourceUpdateFromGoogle != null)
- {
- this.Event_OnSourceUpdateFromGoogle(this, false, www.error);
- }
- Debug.Log("Done Google Sync: source was up-to-date");
- }
- yield break;
- }
- }
- if (this.Event_OnSourceUpdateFromGoogle != null)
- {
- this.Event_OnSourceUpdateFromGoogle(this, false, www.error);
- }
- Debug.Log("Language Source was up-to-date with Google Spreadsheet");
- yield break;
- }
- public WWW Import_Google_CreateWWWcall(bool ForceUpdate, bool justCheck)
- {
- if (!this.HasGoogleSpreadsheet())
- {
- return null;
- }
- string text = PersistentStorage.GetSetting_String("I2SourceVersion_" + this.GetSourcePlayerPrefName(), this.Google_LastUpdatedVersion);
- if (text.Length > 19)
- {
- text = string.Empty;
- }
- if (this.IsNewerVersion(text, this.Google_LastUpdatedVersion))
- {
- this.Google_LastUpdatedVersion = text;
- }
- string url = string.Format("{0}?key={1}&action=GetLanguageSource&version={2}", LocalizationManager.GetWebServiceURL(this), this.Google_SpreadsheetKey, (!ForceUpdate) ? this.Google_LastUpdatedVersion : "0");
- return new WWW(url);
- }
- public bool HasGoogleSpreadsheet()
- {
- return !string.IsNullOrEmpty(this.Google_WebServiceURL) && !string.IsNullOrEmpty(this.Google_SpreadsheetKey) && !string.IsNullOrEmpty(LocalizationManager.GetWebServiceURL(this));
- }
- public string Import_Google_Result(string JsonString, eSpreadsheetUpdateMode UpdateMode, bool saveInPlayerPrefs = false)
- {
- string result;
- try
- {
- string empty = string.Empty;
- if (string.IsNullOrEmpty(JsonString) || JsonString == "\"\"")
- {
- result = empty;
- }
- else
- {
- int num = JsonString.IndexOf("version=", StringComparison.Ordinal);
- int num2 = JsonString.IndexOf("script_version=", StringComparison.Ordinal);
- if (num < 0 || num2 < 0)
- {
- result = "Invalid Response from Google, Most likely the WebService needs to be updated";
- }
- else
- {
- num += "version=".Length;
- num2 += "script_version=".Length;
- string text = JsonString.Substring(num, JsonString.IndexOf(",", num, StringComparison.Ordinal) - num);
- int num3 = int.Parse(JsonString.Substring(num2, JsonString.IndexOf(",", num2, StringComparison.Ordinal) - num2));
- if (text.Length > 19)
- {
- text = string.Empty;
- }
- if (num3 != LocalizationManager.GetRequiredWebServiceVersion())
- {
- result = "The current Google WebService is not supported.\nPlease, delete the WebService from the Google Drive and Install the latest version.";
- }
- else if (saveInPlayerPrefs && !this.IsNewerVersion(this.Google_LastUpdatedVersion, text))
- {
- result = "LanguageSource is up-to-date";
- }
- else
- {
- if (saveInPlayerPrefs)
- {
- string sourcePlayerPrefName = this.GetSourcePlayerPrefName();
- PersistentStorage.SaveFile(PersistentStorage.eFileType.Persistent, "I2Source_" + sourcePlayerPrefName, "[i2e]" + StringObfucator.Encode(JsonString) + ".loc", true);
- PersistentStorage.SetSetting_String("I2SourceVersion_" + sourcePlayerPrefName, text);
- PersistentStorage.ForceSaveSettings();
- }
- this.Google_LastUpdatedVersion = text;
- if (UpdateMode == eSpreadsheetUpdateMode.Replace)
- {
- this.ClearAllData();
- }
- int i = JsonString.IndexOf("[i2category]", StringComparison.Ordinal);
- while (i > 0)
- {
- i += "[i2category]".Length;
- int num4 = JsonString.IndexOf("[/i2category]", i, StringComparison.Ordinal);
- string category = JsonString.Substring(i, num4 - i);
- num4 += "[/i2category]".Length;
- int num5 = JsonString.IndexOf("[/i2csv]", num4, StringComparison.Ordinal);
- string i2CSVstring = JsonString.Substring(num4, num5 - num4);
- i = JsonString.IndexOf("[i2category]", num5, StringComparison.Ordinal);
- this.Import_I2CSV(category, i2CSVstring, UpdateMode);
- if (UpdateMode == eSpreadsheetUpdateMode.Replace)
- {
- UpdateMode = eSpreadsheetUpdateMode.Merge;
- }
- }
- if (I2Utils.IsPlaying())
- {
- this.SaveLanguages(true, PersistentStorage.eFileType.Temporal);
- }
- result = empty;
- }
- }
- }
- }
- catch (Exception ex)
- {
- Debug.LogWarning(ex);
- result = ex.ToString();
- }
- return result;
- }
- public int GetLanguageIndex(string language, bool AllowDiscartingRegion = true, bool SkipDisabled = true)
- {
- int i = 0;
- int count = this.mLanguages.Count;
- while (i < count)
- {
- if ((!SkipDisabled || this.mLanguages[i].IsEnabled()) && string.Compare(this.mLanguages[i].Name, language, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return i;
- }
- i++;
- }
- if (AllowDiscartingRegion)
- {
- int num = -1;
- int num2 = 0;
- int j = 0;
- int count2 = this.mLanguages.Count;
- while (j < count2)
- {
- if (!SkipDisabled || this.mLanguages[j].IsEnabled())
- {
- int commonWordInLanguageNames = LanguageSource.GetCommonWordInLanguageNames(this.mLanguages[j].Name, language);
- if (commonWordInLanguageNames > num2)
- {
- num2 = commonWordInLanguageNames;
- num = j;
- }
- }
- j++;
- }
- if (num >= 0)
- {
- return num;
- }
- }
- return -1;
- }
- public LanguageData GetLanguageData(string language, bool AllowDiscartingRegion = true)
- {
- int languageIndex = this.GetLanguageIndex(language, AllowDiscartingRegion, false);
- return (languageIndex >= 0) ? this.mLanguages[languageIndex] : null;
- }
- public bool IsCurrentLanguage(int languageIndex)
- {
- return LocalizationManager.CurrentLanguage == this.mLanguages[languageIndex].Name;
- }
- public int GetLanguageIndexFromCode(string Code, bool exactMatch = true)
- {
- int i = 0;
- int count = this.mLanguages.Count;
- while (i < count)
- {
- if (string.Compare(this.mLanguages[i].Code, Code, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return i;
- }
- i++;
- }
- if (!exactMatch)
- {
- int j = 0;
- int count2 = this.mLanguages.Count;
- while (j < count2)
- {
- if (string.Compare(this.mLanguages[j].Code, 0, Code, 0, 2, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return j;
- }
- j++;
- }
- }
- return -1;
- }
- public static int GetCommonWordInLanguageNames(string Language1, string Language2)
- {
- if (string.IsNullOrEmpty(Language1) || string.IsNullOrEmpty(Language2))
- {
- return 0;
- }
- char[] separator = "( )-/\\".ToCharArray();
- string[] array = Language1.ToLower().Split(separator);
- string[] array2 = Language2.ToLower().Split(separator);
- int num = 0;
- foreach (string value in array)
- {
- if (!string.IsNullOrEmpty(value) && array2.Contains(value))
- {
- num++;
- }
- }
- foreach (string value2 in array2)
- {
- if (!string.IsNullOrEmpty(value2) && array.Contains(value2))
- {
- num++;
- }
- }
- return num;
- }
- public static bool AreTheSameLanguage(string Language1, string Language2)
- {
- Language1 = LanguageSource.GetLanguageWithoutRegion(Language1);
- Language2 = LanguageSource.GetLanguageWithoutRegion(Language2);
- return string.Compare(Language1, Language2, StringComparison.OrdinalIgnoreCase) == 0;
- }
- public static string GetLanguageWithoutRegion(string Language)
- {
- int num = Language.IndexOfAny("(/\\[,{".ToCharArray());
- if (num < 0)
- {
- return Language;
- }
- return Language.Substring(0, num).Trim();
- }
- public void AddLanguage(string LanguageName)
- {
- this.AddLanguage(LanguageName, GoogleLanguages.GetLanguageCode(LanguageName, false));
- }
- public void AddLanguage(string LanguageName, string LanguageCode)
- {
- if (this.GetLanguageIndex(LanguageName, false, true) >= 0)
- {
- return;
- }
- LanguageData languageData = new LanguageData();
- languageData.Name = LanguageName;
- languageData.Code = LanguageCode;
- this.mLanguages.Add(languageData);
- int count = this.mLanguages.Count;
- int i = 0;
- int count2 = this.mTerms.Count;
- while (i < count2)
- {
- Array.Resize<string>(ref this.mTerms[i].Languages, count);
- Array.Resize<byte>(ref this.mTerms[i].Flags, count);
- i++;
- }
- }
- public void RemoveLanguage(string LanguageName)
- {
- int languageIndex = this.GetLanguageIndex(LanguageName, false, false);
- if (languageIndex < 0)
- {
- return;
- }
- int count = this.mLanguages.Count;
- int i = 0;
- int count2 = this.mTerms.Count;
- while (i < count2)
- {
- for (int j = languageIndex + 1; j < count; j++)
- {
- this.mTerms[i].Languages[j - 1] = this.mTerms[i].Languages[j];
- this.mTerms[i].Flags[j - 1] = this.mTerms[i].Flags[j];
- }
- Array.Resize<string>(ref this.mTerms[i].Languages, count - 1);
- Array.Resize<byte>(ref this.mTerms[i].Flags, count - 1);
- i++;
- }
- this.mLanguages.RemoveAt(languageIndex);
- }
- public List<string> GetLanguages(bool skipDisabled = true)
- {
- List<string> list = new List<string>();
- int i = 0;
- int count = this.mLanguages.Count;
- while (i < count)
- {
- if (!skipDisabled || this.mLanguages[i].IsEnabled())
- {
- list.Add(this.mLanguages[i].Name);
- }
- i++;
- }
- return list;
- }
- public List<string> GetLanguagesCode(bool allowRegions = true, bool skipDisabled = true)
- {
- List<string> list = new List<string>();
- int i = 0;
- int count = this.mLanguages.Count;
- while (i < count)
- {
- if (!skipDisabled || this.mLanguages[i].IsEnabled())
- {
- string text = this.mLanguages[i].Code;
- if (!allowRegions && text != null && text.Length > 2)
- {
- text = text.Substring(0, 2);
- }
- if (!string.IsNullOrEmpty(text) && !list.Contains(text))
- {
- list.Add(text);
- }
- }
- i++;
- }
- return list;
- }
- public bool IsLanguageEnabled(string Language)
- {
- int languageIndex = this.GetLanguageIndex(Language, false, true);
- return languageIndex >= 0 && this.mLanguages[languageIndex].IsEnabled();
- }
- public void EnableLanguage(string Language, bool bEnabled)
- {
- int languageIndex = this.GetLanguageIndex(Language, false, true);
- if (languageIndex >= 0)
- {
- this.mLanguages[languageIndex].SetEnabled(bEnabled);
- }
- }
- private string GetSavedLanguageFileName(int languageIndex)
- {
- if (languageIndex < 0)
- {
- return null;
- }
- return string.Concat(new string[]
- {
- "LangSource_",
- this.GetSourcePlayerPrefName(),
- "_",
- this.mLanguages[languageIndex].Name,
- ".loc"
- });
- }
- public void LoadLanguage(int languageIndex, bool UnloadOtherLanguages, bool useFallback, bool onlyCurrentSpecialization, bool forceLoad)
- {
- if (!PersistentStorage.CanAccessFiles())
- {
- return;
- }
- if (languageIndex >= 0 && (forceLoad || !this.mLanguages[languageIndex].IsLoaded()))
- {
- string savedLanguageFileName = this.GetSavedLanguageFileName(languageIndex);
- string text = PersistentStorage.LoadFile(PersistentStorage.eFileType.Temporal, savedLanguageFileName, false);
- if (!string.IsNullOrEmpty(text))
- {
- this.Import_Language_from_Cache(languageIndex, text, useFallback, onlyCurrentSpecialization);
- this.mLanguages[languageIndex].SetLoaded(true);
- }
- }
- if (UnloadOtherLanguages && I2Utils.IsPlaying())
- {
- for (int i = 0; i < this.mLanguages.Count; i++)
- {
- if (i != languageIndex)
- {
- this.UnloadLanguage(i);
- }
- }
- }
- }
- public void LoadAllLanguages(bool forceLoad = false)
- {
- for (int i = 0; i < this.mLanguages.Count; i++)
- {
- this.LoadLanguage(i, false, false, false, forceLoad);
- }
- }
- public void UnloadLanguage(int languageIndex)
- {
- if (!PersistentStorage.CanAccessFiles())
- {
- return;
- }
- if (!I2Utils.IsPlaying() || !this.mLanguages[languageIndex].IsLoaded() || !this.mLanguages[languageIndex].CanBeUnloaded() || this.IsCurrentLanguage(languageIndex) || !PersistentStorage.HasFile(PersistentStorage.eFileType.Temporal, this.GetSavedLanguageFileName(languageIndex), true))
- {
- return;
- }
- foreach (TermData termData in this.mTerms)
- {
- termData.Languages[languageIndex] = null;
- }
- this.mLanguages[languageIndex].SetLoaded(false);
- }
- public void SaveLanguages(bool unloadAll, PersistentStorage.eFileType fileLocation = PersistentStorage.eFileType.Temporal)
- {
- if (!PersistentStorage.CanAccessFiles())
- {
- return;
- }
- for (int i = 0; i < this.mLanguages.Count; i++)
- {
- string text = this.Export_Language_to_Cache(i, true);
- if (!string.IsNullOrEmpty(text))
- {
- PersistentStorage.SaveFile(PersistentStorage.eFileType.Temporal, this.GetSavedLanguageFileName(i), text, true);
- }
- }
- if (unloadAll)
- {
- for (int j = 0; j < this.mLanguages.Count; j++)
- {
- if (unloadAll && !this.IsCurrentLanguage(j))
- {
- this.UnloadLanguage(j);
- }
- }
- }
- }
- public List<string> GetCategories(bool OnlyMainCategory = false, List<string> Categories = null)
- {
- if (Categories == null)
- {
- Categories = new List<string>();
- }
- foreach (TermData termData in this.mTerms)
- {
- string categoryFromFullTerm = LanguageSource.GetCategoryFromFullTerm(termData.Term, OnlyMainCategory);
- if (!Categories.Contains(categoryFromFullTerm))
- {
- Categories.Add(categoryFromFullTerm);
- }
- }
- Categories.Sort();
- return Categories;
- }
- public static string GetKeyFromFullTerm(string FullTerm, bool OnlyMainCategory = false)
- {
- int num = (!OnlyMainCategory) ? FullTerm.LastIndexOfAny(LanguageSource.CategorySeparators) : FullTerm.IndexOfAny(LanguageSource.CategorySeparators);
- return (num >= 0) ? FullTerm.Substring(num + 1) : FullTerm;
- }
- public static string GetCategoryFromFullTerm(string FullTerm, bool OnlyMainCategory = false)
- {
- int num = (!OnlyMainCategory) ? FullTerm.LastIndexOfAny(LanguageSource.CategorySeparators) : FullTerm.IndexOfAny(LanguageSource.CategorySeparators);
- return (num >= 0) ? FullTerm.Substring(0, num) : LanguageSource.EmptyCategory;
- }
- public static void DeserializeFullTerm(string FullTerm, out string Key, out string Category, bool OnlyMainCategory = false)
- {
- int num = (!OnlyMainCategory) ? FullTerm.LastIndexOfAny(LanguageSource.CategorySeparators) : FullTerm.IndexOfAny(LanguageSource.CategorySeparators);
- if (num < 0)
- {
- Category = LanguageSource.EmptyCategory;
- Key = FullTerm;
- }
- else
- {
- Category = FullTerm.Substring(0, num);
- Key = FullTerm.Substring(num + 1);
- }
- }
- public void UpdateDictionary(bool force = false)
- {
- if (!force && this.mDictionary != null && this.mDictionary.Count == this.mTerms.Count)
- {
- return;
- }
- StringComparer stringComparer = (!this.CaseInsensitiveTerms) ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
- if (this.mDictionary.Comparer != stringComparer)
- {
- this.mDictionary = new Dictionary<string, TermData>(stringComparer);
- }
- else
- {
- this.mDictionary.Clear();
- }
- int i = 0;
- int count = this.mTerms.Count;
- while (i < count)
- {
- TermData termData = this.mTerms[i];
- LanguageSource.ValidateFullTerm(ref termData.Term);
- this.mDictionary[termData.Term] = this.mTerms[i];
- this.mTerms[i].Validate();
- i++;
- }
- if (I2Utils.IsPlaying())
- {
- this.SaveLanguages(true, PersistentStorage.eFileType.Temporal);
- }
- }
- public string GetTranslation(string term, string overrideLanguage = null, string overrideSpecialization = null, bool skipDisabled = false, bool allowCategoryMistmatch = false)
- {
- string result;
- if (this.TryGetTranslation(term, out result, overrideLanguage, overrideSpecialization, skipDisabled, allowCategoryMistmatch))
- {
- return result;
- }
- return string.Empty;
- }
- public bool TryGetTranslation(string term, out string Translation, string overrideLanguage = null, string overrideSpecialization = null, bool skipDisabled = false, bool allowCategoryMistmatch = false)
- {
- int languageIndex = this.GetLanguageIndex((overrideLanguage != null) ? overrideLanguage : LocalizationManager.CurrentLanguage, true, false);
- if (languageIndex >= 0 && (!skipDisabled || this.mLanguages[languageIndex].IsEnabled()))
- {
- TermData termData = this.GetTermData(term, allowCategoryMistmatch);
- if (termData != null)
- {
- Translation = termData.GetTranslation(languageIndex, overrideSpecialization);
- if (Translation == "---")
- {
- Translation = string.Empty;
- return true;
- }
- if (!string.IsNullOrEmpty(Translation))
- {
- return true;
- }
- Translation = null;
- }
- if (this.OnMissingTranslation == LanguageSource.MissingTranslationAction.ShowWarning)
- {
- Translation = string.Format("<!-Missing Translation [{0}]-!>", term);
- return true;
- }
- if (this.OnMissingTranslation == LanguageSource.MissingTranslationAction.Fallback && termData != null)
- {
- return this.TryGetFallbackTranslation(termData, out Translation, languageIndex, overrideSpecialization, skipDisabled);
- }
- if (this.OnMissingTranslation == LanguageSource.MissingTranslationAction.Empty)
- {
- Translation = string.Empty;
- return true;
- }
- }
- Translation = null;
- return false;
- }
- private bool TryGetFallbackTranslation(TermData termData, out string Translation, int langIndex, string overrideSpecialization = null, bool skipDisabled = false)
- {
- string text = this.mLanguages[langIndex].Code;
- if (!string.IsNullOrEmpty(text))
- {
- if (text.Contains('-'))
- {
- text = text.Substring(0, text.IndexOf('-'));
- }
- for (int i = 0; i < this.mLanguages.Count; i++)
- {
- if (i != langIndex && this.mLanguages[i].Code.StartsWith(text) && (!skipDisabled || this.mLanguages[i].IsEnabled()))
- {
- Translation = termData.GetTranslation(i, overrideSpecialization);
- if (!string.IsNullOrEmpty(Translation))
- {
- return true;
- }
- }
- }
- }
- for (int j = 0; j < this.mLanguages.Count; j++)
- {
- if (j != langIndex && (!skipDisabled || this.mLanguages[j].IsEnabled()) && (text == null || !this.mLanguages[j].Code.StartsWith(text)))
- {
- Translation = termData.GetTranslation(j, overrideSpecialization);
- if (!string.IsNullOrEmpty(Translation))
- {
- return true;
- }
- }
- }
- Translation = null;
- return false;
- }
- public TermData AddTerm(string term)
- {
- return this.AddTerm(term, eTermType.Text, true);
- }
- public TermData GetTermData(string term, bool allowCategoryMistmatch = false)
- {
- if (string.IsNullOrEmpty(term))
- {
- return null;
- }
- if (this.mDictionary.Count == 0)
- {
- this.UpdateDictionary(false);
- }
- TermData result;
- if (this.mDictionary.TryGetValue(term, out result))
- {
- return result;
- }
- TermData termData = null;
- if (allowCategoryMistmatch)
- {
- string keyFromFullTerm = LanguageSource.GetKeyFromFullTerm(term, false);
- foreach (KeyValuePair<string, TermData> keyValuePair in this.mDictionary)
- {
- if (keyValuePair.Value.IsTerm(keyFromFullTerm, true))
- {
- if (termData != null)
- {
- return null;
- }
- termData = keyValuePair.Value;
- }
- }
- return termData;
- }
- return termData;
- }
- public bool ContainsTerm(string term)
- {
- return this.GetTermData(term, false) != null;
- }
- public List<string> GetTermsList(string Category = null)
- {
- if (this.mDictionary.Count != this.mTerms.Count)
- {
- this.UpdateDictionary(false);
- }
- if (string.IsNullOrEmpty(Category))
- {
- return new List<string>(this.mDictionary.Keys);
- }
- List<string> list = new List<string>();
- for (int i = 0; i < this.mTerms.Count; i++)
- {
- TermData termData = this.mTerms[i];
- if (LanguageSource.GetCategoryFromFullTerm(termData.Term, false) == Category)
- {
- list.Add(termData.Term);
- }
- }
- return list;
- }
- public TermData AddTerm(string NewTerm, eTermType termType, bool SaveSource = true)
- {
- LanguageSource.ValidateFullTerm(ref NewTerm);
- NewTerm = NewTerm.Trim();
- if (this.mLanguages.Count == 0)
- {
- this.AddLanguage("English", "en");
- }
- TermData termData = this.GetTermData(NewTerm, false);
- if (termData == null)
- {
- termData = new TermData();
- termData.Term = NewTerm;
- termData.TermType = termType;
- termData.Languages = new string[this.mLanguages.Count];
- termData.Flags = new byte[this.mLanguages.Count];
- this.mTerms.Add(termData);
- this.mDictionary.Add(NewTerm, termData);
- }
- return termData;
- }
- public void RemoveTerm(string term)
- {
- int i = 0;
- int count = this.mTerms.Count;
- while (i < count)
- {
- if (this.mTerms[i].Term == term)
- {
- this.mTerms.RemoveAt(i);
- this.mDictionary.Remove(term);
- return;
- }
- i++;
- }
- }
- public static void ValidateFullTerm(ref string Term)
- {
- Term = Term.Replace('\\', '/');
- Term = Term.Trim();
- if (Term.StartsWith(LanguageSource.EmptyCategory, StringComparison.Ordinal) && Term.Length > LanguageSource.EmptyCategory.Length && Term[LanguageSource.EmptyCategory.Length] == '/')
- {
- Term = Term.Substring(LanguageSource.EmptyCategory.Length + 1);
- }
- Term = I2Utils.RemoveNonASCII(Term, true);
- }
- public bool NeverDestroy;
- public bool UserAgreesToHaveItOnTheScene;
- public bool UserAgreesToHaveItInsideThePluginsFolder;
- [NonSerialized]
- public bool mIsGlobalSource;
- public List<UnityEngine.Object> Assets = new List<UnityEngine.Object>();
- [NonSerialized]
- public Dictionary<string, UnityEngine.Object> mAssetDictionary = new Dictionary<string, UnityEngine.Object>(StringComparer.Ordinal);
- public string Google_WebServiceURL;
- public string Google_SpreadsheetKey;
- public string Google_SpreadsheetName;
- public string Google_LastUpdatedVersion;
- public LanguageSource.eGoogleUpdateFrequency GoogleUpdateFrequency = LanguageSource.eGoogleUpdateFrequency.Weekly;
- public LanguageSource.eGoogleUpdateFrequency GoogleInEditorCheckFrequency = LanguageSource.eGoogleUpdateFrequency.Daily;
- public float GoogleUpdateDelay = 5f;
- public List<LanguageData> mLanguages = new List<LanguageData>();
- public bool IgnoreDeviceLanguage;
- public static string EmptyCategory = "Default";
- public static char[] CategorySeparators = "/\\".ToCharArray();
- public List<TermData> mTerms = new List<TermData>();
- public bool CaseInsensitiveTerms;
- [NonSerialized]
- public Dictionary<string, TermData> mDictionary = new Dictionary<string, TermData>(StringComparer.Ordinal);
- public LanguageSource.MissingTranslationAction OnMissingTranslation = LanguageSource.MissingTranslationAction.Fallback;
- public string mTerm_AppName;
- public enum eGoogleUpdateFrequency
- {
- Always,
- Never,
- Daily,
- Weekly,
- Monthly,
- OnlyOnce
- }
- public enum MissingTranslationAction
- {
- Empty,
- Fallback,
- ShowWarning
- }
- }
- }
|