1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- 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 = ',', LanguageSource.CsvSetTranslationPrevDelegate callBackSetTranslationPrev = null)
- {
- List<string[]> csv = LocalizationReader.ReadCSV(CSVstring, Separator);
- return this.Import_CSV(Category, csv, UpdateMode, callBackSetTranslationPrev);
- }
- public string Import_I2CSV(string Category, string I2CSVstring, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace, LanguageSource.CsvSetTranslationPrevDelegate callBackSetTranslationPrev = null)
- {
- List<string[]> csv = LocalizationReader.ReadI2CSV(I2CSVstring);
- return this.Import_CSV(Category, csv, UpdateMode, callBackSetTranslationPrev);
- }
- public string Import_CSV(string Category, List<string[]> CSV, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace, LanguageSource.CsvSetTranslationPrevDelegate callBackSetTranslationPrev = null)
- {
- List<string[]> list = new List<string[]>(CSV);
- CSV.Clear();
- foreach (string[] array in list)
- {
- if (0 < array.Length && !string.IsNullOrEmpty(array[0]))
- {
- CSV.Add(array);
- }
- }
- string[] array2 = 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 (array2.Length > 1 && this.ArrayContains(array2[0], texts))
- {
- if (UpdateMode == eSpreadsheetUpdateMode.Replace)
- {
- this.ClearAllData();
- }
- if (array2.Length > 2)
- {
- if (this.ArrayContains(array2[1], texts2))
- {
- num2 = 1;
- num = 2;
- }
- if (this.ArrayContains(array2[1], texts3))
- {
- num3 = 1;
- num = 2;
- }
- }
- if (array2.Length > 3)
- {
- if (this.ArrayContains(array2[2], texts2))
- {
- num2 = 2;
- num = 3;
- }
- if (this.ArrayContains(array2[2], texts3))
- {
- num3 = 2;
- num = 3;
- }
- }
- int num4 = Mathf.Max(array2.Length - num, 0);
- int[] array3 = new int[num4];
- for (int i = 0; i < num4; i++)
- {
- if (string.IsNullOrEmpty(array2[i + num]))
- {
- array3[i] = -1;
- }
- else
- {
- string text = array2[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;
- }
- array3[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)
- {
- array2 = CSV[k];
- string text4 = (!string.IsNullOrEmpty(Category)) ? (Category + "/" + array2[0]) : array2[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_506;
- }
- if (num2 > 0)
- {
- termData2.TermType = LanguageSource.GetTermType(array2[num2]);
- }
- if (num3 > 0)
- {
- termData2.Description = array2[num3];
- }
- int num7 = 0;
- while (num7 < array3.Length && num7 < array2.Length - num)
- {
- if (!string.IsNullOrEmpty(array2[num7 + num]))
- {
- int num8 = array3[num7];
- if (num8 >= 0)
- {
- string text6 = array2[num7 + num];
- if (text6 == "-")
- {
- text6 = string.Empty;
- }
- else if (text6 == string.Empty)
- {
- text6 = null;
- }
- if (callBackSetTranslationPrev != null)
- {
- string term = termData2.Term;
- callBackSetTranslationPrev(this.mLanguages[num8], ref term, ref text6, ref text5);
- termData2.Term = term;
- }
- termData2.SetTranslation(num8, text6, text5);
- }
- }
- num7++;
- }
- }
- IL_506:
- 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;
- }
- }
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- 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)
- {
- UnityEngine.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);
- UnityEngine.Debug.Log("Done Google Sync");
- }
- else
- {
- if (this.Event_OnSourceUpdateFromGoogle != null)
- {
- this.Event_OnSourceUpdateFromGoogle(this, false, www.error);
- }
- UnityEngine.Debug.Log("Done Google Sync: source was up-to-date");
- }
- yield break;
- }
- }
- if (this.Event_OnSourceUpdateFromGoogle != null)
- {
- this.Event_OnSourceUpdateFromGoogle(this, false, www.error);
- }
- UnityEngine.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, null);
- if (UpdateMode == eSpreadsheetUpdateMode.Replace)
- {
- UpdateMode = eSpreadsheetUpdateMode.Merge;
- }
- }
- if (I2Utils.IsPlaying())
- {
- this.SaveLanguages(true, PersistentStorage.eFileType.Temporal);
- }
- result = empty;
- }
- }
- }
- }
- catch (Exception ex)
- {
- UnityEngine.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 delegate void CsvSetTranslationPrevDelegate(LanguageData setTargetLanguage, ref string termKey, ref string setTranslation, ref string setSpecialization);
- public enum eGoogleUpdateFrequency
- {
- Always,
- Never,
- Daily,
- Weekly,
- Monthly,
- OnlyOnce
- }
- public enum MissingTranslationAction
- {
- Empty,
- Fallback,
- ShowWarning
- }
- }
- }
|