void OnGUI_NewOrExistingTerm() { if (mKeyToExplore == null) { mKeyToExplore = string.Empty; } GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.2f); GUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Height(1)); GUI.backgroundColor = Color.white; GUILayout.Space(5); GUILayout.Label("Replace By:"); GUILayout.EndVertical(); //--[ Create Term ]------------------------ GUILayout.BeginHorizontal(); mKeyToExplore = GUILayout.TextField(mKeyToExplore, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true)); if (GUILayout.Button("Create", "toolbarbutton", GUILayout.Width(60))) { LanguageSource.ValidateFullTerm(ref mKeyToExplore); EditorApplication.update += ReplaceSelectedTerms; } GUILayout.EndHorizontal(); //--[ Existing Term ]------------------------ int Index = 0; List <string> Terms = mLanguageSource.GetTermsList(); for (int i = 0, imax = Terms.Count; i < imax; ++i) { if (Terms[i].ToLower().Contains(mKeyToExplore.ToLower())) { Index = i; break; } } GUILayout.BeginHorizontal(); int NewIndex = EditorGUILayout.Popup(Index, Terms.ToArray(), EditorStyles.toolbarPopup, GUILayout.ExpandWidth(true)); if (NewIndex != Index) { SelectTerm(Terms [NewIndex]); ClearErrors(); } if (GUILayout.Button("Use", "toolbarbutton", GUILayout.Width(60))) { SelectTerm(Terms[NewIndex]); EditorApplication.update += ReplaceSelectedTerms; } GUILayout.EndHorizontal(); }
void SwapLanguages(int iFirst, int iSecond) { serializedObject.ApplyModifiedProperties(); LanguageSource Source = mLanguageSource; SwapValues(Source.mLanguages, iFirst, iSecond); foreach (TermData termData in Source.mTerms) { SwapValues(termData.Languages, iFirst, iSecond); SwapValues(termData.Flags, iFirst, iSecond); } serializedObject.Update(); }
private static void RegisterSourceInResources() { string[] globalSources = GlobalSources; foreach (string name in globalSources) { GameObject asset = ResourceManager.pInstance.GetAsset <GameObject>(name); LanguageSource languageSource = asset ? asset.GetComponent <LanguageSource>() : null; if ((bool)languageSource && !Sources.Contains(languageSource)) { AddSource(languageSource); } } }
private static void TranslateTerm(string Key, TermData termdata, LanguageSource source, int i) { string sourceText = null; string sourceLangCode = null; FindTranslationSource(Key, termdata, source.mLanguages[i].Code, null, out sourceText, out sourceLangCode); var term = termdata; var specialization = GUI_SelectedSpecialization; var langIdx = i; Translate(sourceText, ref termdata, source.mLanguages[i].Code, (translation, error) => { term.SetTranslation(langIdx, translation, specialization); }, specialization); }
void TranslateAllToLanguage(string lanName) { if (!GoogleTranslation.CanTranslate()) { ShowError("WebService is not set correctly or needs to be reinstalled"); return; } ClearErrors(); int LanIndex = mLanguageSource.GetLanguageIndex(lanName); string code = mLanguageSource.mLanguages [LanIndex].Code; string googleCode = GoogleLanguages.GetGoogleLanguageCode(code); if (string.IsNullOrEmpty(googleCode)) { ShowError("Language '" + code + "' is not supported by google translate"); return; } mTranslationTerms.Clear(); mTranslationRequests.Clear(); foreach (var termData in mLanguageSource.mTerms) { if (!string.IsNullOrEmpty((GUI_SelectedInputType == 0 ? termData.Languages : termData.Languages_Touch)[LanIndex])) { continue; } string sourceCode, sourceText; FindTranslationSource(LanguageSource.GetKeyFromFullTerm(termData.Term), termData, code, out sourceText, out sourceCode); mTranslationTerms.Add(termData.Term); GoogleTranslation.CreateQueries(sourceText, sourceCode, googleCode, mTranslationRequests); // can split plurals into several queries } if (mTranslationRequests.Count == 0) { StopConnectionWWW(); return; } mConnection_WWW = null; mConnection_Text = "Translating"; if (mTranslationRequests.Count > 1) { mConnection_Text += " (" + mTranslationRequests.Count + ")"; } mConnection_Callback = null; //EditorApplication.update += CheckForConnection; GoogleTranslation.Translate(mTranslationRequests, OnLanguageTranslated); }
void OnEnable() { var newSource = target as LanguageSource; bool ForceParse = (mLanguageSource != newSource); mLanguageSource = newSource; if (!LocalizationManager.Sources.Contains(mLanguageSource)) { LocalizationManager.UpdateSources(); } mProp_Assets = serializedObject.FindProperty("Assets"); mProp_Languages = serializedObject.FindProperty("mLanguages"); mProp_Google_WebServiceURL = serializedObject.FindProperty("Google_WebServiceURL"); mProp_GoogleUpdateFrequency = serializedObject.FindProperty("GoogleUpdateFrequency"); mProp_GoogleUpdateDelay = serializedObject.FindProperty("GoogleUpdateDelay"); mProp_Google_SpreadsheetKey = serializedObject.FindProperty("Google_SpreadsheetKey"); mProp_Google_SpreadsheetName = serializedObject.FindProperty("Google_SpreadsheetName"); mProp_CaseInsensitiveTerms = serializedObject.FindProperty("CaseInsensitiveTerms"); mProp_Spreadsheet_LocalFileName = serializedObject.FindProperty("Spreadsheet_LocalFileName"); mProp_Spreadsheet_LocalCSVSeparator = serializedObject.FindProperty("Spreadsheet_LocalCSVSeparator"); mProp_Spreadsheet_LocalCSVEncoding = serializedObject.FindProperty("Spreadsheet_LocalCSVEncoding"); mProp_OnMissingTranslation = serializedObject.FindProperty("OnMissingTranslation"); mProp_AppNameTerm = serializedObject.FindProperty("mTerm_AppName"); mProp_IgnoreDeviceLanguage = serializedObject.FindProperty("IgnoreDeviceLanguage"); if (!mIsParsing) { if (string.IsNullOrEmpty(mLanguageSource.Google_SpreadsheetKey)) { mSpreadsheetMode = eSpreadsheetMode.Local; } else { mSpreadsheetMode = eSpreadsheetMode.Google; } mCurrentViewMode = (mLanguageSource.mLanguages.Count > 0 ? eViewMode.Keys : eViewMode.Languages); UpdateSelectedKeys(); if (ForceParse || mParsedTerms.Count < mLanguageSource.mTerms.Count) { mSelectedCategories.Clear(); ParseTerms(true); } } ScheduleUpdateTermsToShowInList(); LoadSelectedCategories(); //UpgradeManager.EnablePlugins(); }
private static void RegisterSourceInResources() { // Find the Source that its on the Resources Folder foreach (string SourceName in GlobalSources) { GameObject Prefab = (ResourceManager.pInstance.GetAsset <GameObject>(SourceName)); LanguageSource GlobalSource = (Prefab ? Prefab.GetComponent <LanguageSource>() : null); if (GlobalSource && !Sources.Contains(GlobalSource)) { AddSource(GlobalSource); } } }
public override void OnInspectorGUI() { string[] Languages; LanguageSource source = setLan.mSource; if (source == null) { LocalizationManager.UpdateSources(); Languages = LocalizationManager.GetAllLanguages().ToArray(); System.Array.Sort(Languages); } else { Languages = source.GetLanguages().ToArray(); System.Array.Sort(Languages); } int index = System.Array.IndexOf(Languages, mProp_Language.stringValue); GUI.changed = false; index = EditorGUILayout.Popup("Language", index, Languages); if (GUI.changed) { if (index < 0 || index >= Languages.Length) { mProp_Language.stringValue = string.Empty; } else { mProp_Language.stringValue = Languages[index]; } GUI.changed = false; serializedObject.ApplyModifiedProperties(); } GUILayout.Space(5); if (setLan.mSource == null) { GUI.contentColor = Color.Lerp(Color.gray, Color.yellow, 0.1f); } source = EditorGUILayout.ObjectField("Language Source:", source, typeof(LanguageSource), true) as LanguageSource; GUI.contentColor = Color.white; if (GUI.changed) { setLan.mSource = source; } serializedObject.ApplyModifiedProperties(); }
internal bool ManagerHasASimilarSource() { int i = 0; for (int count = LocalizationManager.Sources.Count; i < count; i++) { LanguageSource languageSource = LocalizationManager.Sources[i]; if (languageSource != null && languageSource.IsEqualTo(this) && languageSource != this) { return(true); } } return(false); }
public static ParsedTerm GetParsedTerm(string Term) { ParsedTerm data; if (!mParsedTerms.TryGetValue(Term, out data)) { data = new ParsedTerm(); data.Usage = 0; LanguageSource.DeserializeFullTerm(Term, out data.Term, out data.Category); mParsedCategories[data.Category] = 1; mParsedTerms[Term] = data; } return(data); }
bool TermHasAllTranslations(LanguageSource source, TermData data) { if (source == null) { source = LocalizationManager.Sources[0]; } for (int i = 0, imax = data.Languages.Length; i < imax; ++i) { if (string.IsNullOrEmpty(data.Languages[i]) && string.IsNullOrEmpty(data.Languages_Touch[i]) && source.mLanguages[i].IsEnabled()) { return(false); } } return(true); }
List <string> ScriptTool_GetSelectedTermsInCategory(string Category) { List <string> list = new List <string>(); foreach (string FullKey in mSelectedKeys) { string categ = LanguageSource.GetCategoryFromFullTerm(FullKey); if (categ == Category && ShouldShowTerm(FullKey)) { list.Add(LanguageSource.GetKeyFromFullTerm(FullKey)); } } return(list); }
public static string GetWebServiceURL(LanguageSource source = null) { if (source != null && !string.IsNullOrEmpty(source.Google_WebServiceURL)) { return(source.Google_WebServiceURL); } for (int i = 0; i < Sources.Count; i++) { if (Sources[i] != null && !string.IsNullOrEmpty(Sources[i].Google_WebServiceURL)) { return(Sources[i].Google_WebServiceURL); } } return(string.Empty); }
internal static void AddSource(LanguageSource Source) { if (Sources.Contains(Source)) { return; } Sources.Add(Source); #if !UNITY_EDITOR Source.Import_Google(); #endif if (Source.mDictionary.Count == 0) { Source.UpdateDictionary(true); } }
void OnGUI_CategorizedTerm(string Term) { GUILayout.BeginHorizontal(); string sKey, sCategory; LanguageSource.DeserializeFullTerm(Term, out sKey, out sCategory); if (!string.IsNullOrEmpty(sCategory)) { GUI.color = Color.gray; GUILayout.Label(sCategory + "/"); GUI.color = Color.white; } GUILayout.Label(sKey); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
void Import_CSV(string FileName, eSpreadsheetUpdateMode UpdateMode) { LanguageSource source = (LanguageSource)target; string CSVstring = LocalizationReader.ReadCSVfile(FileName); char Separator = mProp_Spreadsheet_LocalCSVSeparator.stringValue.Length > 0 ? mProp_Spreadsheet_LocalCSVSeparator.stringValue[0] : ','; string sError = source.Import_CSV(string.Empty, CSVstring, UpdateMode, Separator); if (!string.IsNullOrEmpty(sError)) { ShowError(sError); } LocalizationEditor.mSelectedCategories = source.GetCategories(); mShouldDetectStoreIntegration = true; }
public static void FreeUnusedLanguages() { LanguageSource languageSource = LocalizationManager.Sources[0]; int languageIndex = languageSource.GetLanguageIndex(LocalizationManager.CurrentLanguage); 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] = (termData.Languages_Touch[j] = null); } } } }
static void OnGUI_Keys_Languages(string Key, ref TermData termdata, Localize localizeCmp, bool IsPrimaryKey, LanguageSource source) { //--[ Languages ]--------------------------- GUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Height(1)); OnGUI_Keys_LanguageTranslations(Key, localizeCmp, IsPrimaryKey, ref termdata, source); if (termdata.TermType == eTermType.Text) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (TestButton(eTest_ActionType.Button_Term_TranslateAll, "Translate All", "Button", GUILayout.Width(85))) { ClearErrors(); string mainText = localizeCmp == null?LanguageSource.GetKeyFromFullTerm(Key) : localizeCmp.GetMainTargetsText(); for (int i = 0; i < source.mLanguages.Count; ++i) { if (string.IsNullOrEmpty(termdata.GetTranslation(i)) && source.mLanguages[i].IsEnabled()) { var languages = (GUI_SelectedInputType == 0 ? termdata.Languages : termdata.Languages_Touch); var languagesOther = (GUI_SelectedInputType == 0 ? termdata.Languages_Touch : termdata.Languages); var langIdx = i; Translate(mainText, ref termdata, source.mLanguages[i].Code, (translation, error) => { if (error != null) { ShowError(error); } else if (translation != null) { languages[langIdx] = translation; languagesOther[langIdx] = null; } }); } } GUI.FocusControl(string.Empty); } GUILayout.EndHorizontal(); OnGUI_TranslatingMessage(); } GUILayout.EndVertical(); }
static ParsedTerm AddParsedTerm(string FullTerm, string TermKey, string Category, int Usage) { if (TermKey == null) { LanguageSource.DeserializeFullTerm(FullTerm, out TermKey, out Category); } var data = new ParsedTerm(); data.Usage = Usage; data.FullTerm = FullTerm; data.Term = TermKey; data.Category = Category; mParsedTerms[FullTerm] = data; return(data); }
void Export_Google(eSpreadsheetUpdateMode UpdateMode) { StopConnectionWWW(); LanguageSource source = ((LanguageSource)target); mConnection_WWW = source.Export_Google_CreateWWWcall(UpdateMode); if (mConnection_WWW == null) { OnExported_Google(string.Empty, "WebPlayer can't contact Google"); } else { mConnection_Callback = OnExported_Google; EditorApplication.update += CheckForConnection; mConnection_Text = "Uploading spreadsheet"; //mConnection_TimeOut = Time.realtimeSinceStartup + 10; } }
public static TermData GetTermData(string term, out LanguageSource source) { InitializeIfNeeded(); TermData data; for (int i = 0, imax = Sources.Count; i < imax; ++i) { data = Sources[i].GetTermData(term); if (data != null) { source = Sources[i]; return(data); } } source = null; return(null); }
void OnGUI_Source() { GUILayout.BeginHorizontal(); LanguageSource currentSource = mLocalize.Source; if (currentSource == null) { currentSource = LocalizationManager.GetSourceContaining(mLocalize.Term); } if (GUILayout.Button("Open Source", EditorStyles.toolbarButton, GUILayout.Width(100))) { Selection.activeObject = currentSource; string sTerm, sSecondary; mLocalize.GetFinalTerms(out sTerm, out sSecondary); if (GUI_SelectedTerm == 1) { sTerm = sSecondary; } LocalizationEditor.mKeyToExplore = sTerm; } GUILayout.Space(2); GUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginChangeCheck(); if (!mLocalize.Source) { GUI.contentColor = Color.Lerp(Color.gray, Color.yellow, 0.1f); } LanguageSource NewSource = EditorGUILayout.ObjectField(currentSource, typeof(LanguageSource), true) as LanguageSource; GUI.contentColor = Color.white; if (EditorGUI.EndChangeCheck()) { mLocalize.Source = NewSource; } GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); }
void OnEnable() { var newSource = target as LanguageSource; bool ForceParse = (mLanguageSource != newSource); mLanguageSource = newSource; if (!LocalizationManager.Sources.Contains(mLanguageSource)) { LocalizationManager.UpdateSources(); } mProp_Assets = serializedObject.FindProperty("Assets"); mProp_Languages = serializedObject.FindProperty("mLanguages"); mProp_Google_WebServiceURL = serializedObject.FindProperty("Google_WebServiceURL"); mProp_GoogleUpdateFrequency = serializedObject.FindProperty("GoogleUpdateFrequency"); mProp_Google_SpreadsheetKey = serializedObject.FindProperty("Google_SpreadsheetKey"); mProp_Google_SpreadsheetName = serializedObject.FindProperty("Google_SpreadsheetName"); mProp_CaseInsensitiveTerms = serializedObject.FindProperty("CaseInsensitiveTerms"); mProp_Spreadsheet_LocalFileName = serializedObject.FindProperty("Spreadsheet_LocalFileName"); mProp_Spreadsheet_LocalCSVSeparator = serializedObject.FindProperty("Spreadsheet_LocalCSVSeparator"); if (!mIsParsing) { if (string.IsNullOrEmpty(mLanguageSource.Google_SpreadsheetKey)) { mSpreadsheetMode = eSpreadsheetMode.Local; } else { mSpreadsheetMode = eSpreadsheetMode.Google; } mCurrentViewMode = (mLanguageSource.mLanguages.Count > 0 ? eViewMode.Keys : eViewMode.Languages); UpdateSelectedKeys(); if (ForceParse || mParsedTerms.Count < mLanguageSource.mTerms.Count) { ParseTerms(true); } } //UpgradeManager.EnablePlugins(); }
void Google_OnNewSpreadsheet(string Result, string Error) { if (!string.IsNullOrEmpty(Error)) { ShowError("Unable to access google"); return; } if (Result == "Wrong Password") { ShowError(Result); return; } try { var data = SimpleJSON.JSON.Parse(Result).AsObject; string name = data["name"]; string key = data["id"]; serializedObject.Update(); mProp_Google_SpreadsheetKey.stringValue = key; mProp_Google_SpreadsheetName.stringValue = name; serializedObject.ApplyModifiedProperties(); mGoogleSpreadsheets[name] = key; LanguageSource source = (LanguageSource)target; if (source.mTerms.Count > 0 || source.mLanguages.Count > 0) { Export_Google(eSpreadsheetUpdateMode.Replace); } else if (EditorPrefs.GetBool("I2Loc OpenDataSourceAfterExport", true)) { OpenGoogleSpreadsheet(key); } } catch (Exception e) { ShowError(e.Message); } }
void OnGUI_KeysList_AddKey() { GUILayout.BeginHorizontal(); GUI.color = Color.Lerp(Color.gray, Color.white, 0.5f); bool bWasEnabled = (mTermsList_NewTerm != null); bool bEnabled = !GUILayout.Toggle(!bWasEnabled, "+", EditorStyles.toolbarButton, GUILayout.Width(30)); GUI.color = Color.white; if (bWasEnabled && !bEnabled) { mTermsList_NewTerm = null; } if (!bWasEnabled && bEnabled) { mTermsList_NewTerm = string.Empty; } if (bEnabled) { GUILayout.BeginHorizontal(EditorStyles.toolbar); mTermsList_NewTerm = EditorGUILayout.TextField(mTermsList_NewTerm, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); LanguageSource.ValidateFullTerm(ref mTermsList_NewTerm); if (string.IsNullOrEmpty(mTermsList_NewTerm) || mLanguageSource.ContainsTerm(mTermsList_NewTerm)) { GUI.enabled = false; } if (GUILayout.Button("Create Key", "toolbarbutton", GUILayout.ExpandWidth(false))) { AddTerm(mTermsList_NewTerm); SelectTerm(mTermsList_NewTerm); ClearErrors(); mTermsList_NewTerm = null; SetAllTerms_When_InferredTerms_IsInSource(); } GUI.enabled = true; } GUILayout.EndHorizontal(); }
private static void TranslateTerm(string Key, TermData termdata, LanguageSource source, int i) { string sourceText = null; string sourceLangCode = null; FindTranslationSource(Key, termdata, source.mLanguages[i].Code, null, out sourceText, out sourceLangCode); var term = termdata; var specialization = GUI_SelectedSpecialization; var langIdx = i; var i2source = source; Translate(sourceText, ref termdata, source.mLanguages[i].Code, (translation, error) => { term.SetTranslation(langIdx, translation, specialization); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(i2source); #endif }, specialization); }
public static void RemoveParsedTerm(string Term) { mParsedTerms.Remove(Term); string category, key; LanguageSource.DeserializeFullTerm(Term, out key, out category); int usage; if (mParsedCategories.TryGetValue(category, out usage)) { if (usage <= 1) { mParsedCategories.Remove(category); } else { mParsedCategories[category] = usage - 1; } } }
void Import_CSV(string FileName, eSpreadsheetUpdateMode UpdateMode) { LanguageSource source = (LanguageSource)target; var encoding = System.Text.Encoding.GetEncoding(mProp_Spreadsheet_LocalCSVEncoding.stringValue); if (encoding == null) { encoding = System.Text.Encoding.UTF8; } string CSVstring = LocalizationReader.ReadCSVfile(FileName, encoding); char Separator = mProp_Spreadsheet_LocalCSVSeparator.stringValue.Length > 0 ? mProp_Spreadsheet_LocalCSVSeparator.stringValue[0] : ','; string sError = source.Import_CSV(string.Empty, CSVstring, UpdateMode, Separator); if (!string.IsNullOrEmpty(sError)) { ShowError(sError); } mSelectedCategories = source.GetCategories(); }
internal static void AddSource(LanguageSource Source) { if (Sources.Contains(Source)) { return; } Sources.Add(Source); if (Source.HasGoogleSpreadsheet() && Source.GoogleUpdateFrequency != LanguageSource.eGoogleUpdateFrequency.Never) { #if !UNITY_EDITOR Source.Import_Google_FromCache(); bool justCheck = false; #else bool justCheck = true; #endif if (Source.GoogleUpdateDelay > 0) { CoroutineManager.Start(Delayed_Import_Google(Source, Source.GoogleUpdateDelay, justCheck)); } else { Source.Import_Google(false, justCheck); } } //if (force) { for (int i = 0; i < Source.mLanguages.Count(); ++i) { Source.mLanguages[i].SetLoaded(true); } } if (Source.mDictionary.Count == 0) { Source.UpdateDictionary(true); } }
void TranslateAllToLanguage(string lanName) { if (!GoogleTranslation.CanTranslate()) { ShowError("WebService is not set correctly or needs to be reinstalled"); return; } int LanIndex = mLanguageSource.GetLanguageIndex(lanName); string code = mLanguageSource.mLanguages [LanIndex].Code; mTranslationRequests.Clear(); foreach (var termData in mLanguageSource.mTerms) { if (!string.IsNullOrEmpty((GUI_SelectedInputType == 0 ? termData.Languages : termData.Languages_Touch)[LanIndex])) { continue; } string sourceCode, sourceText; FindTranslationSource(LanguageSource.GetKeyFromFullTerm(termData.Term), termData, code, out sourceText, out sourceCode); mTranslationRequests.Add(new TranslationRequest() { Term = termData.Term, Text = sourceText, LanguageCode = sourceCode, TargetLanguagesCode = new string[] { code } }); } mConnection_WWW = GoogleTranslation.GetTranslationWWW(mTranslationRequests); mConnection_Text = "Translating"; if (mTranslationRequests.Count > 1) { mConnection_Text += " (" + mTranslationRequests.Count + ")"; } mConnection_Callback = OnLanguageTranslated; EditorApplication.update += CheckForConnection; }