public void ApplyDownloadedDataFromGoogle() { if (string.IsNullOrEmpty(mDelayedGoogleData)) { return; } var errorMsg = Import_Google_Result(mDelayedGoogleData, eSpreadsheetUpdateMode.Replace, true); if (string.IsNullOrEmpty(errorMsg)) { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, true, ""); } LocalizationManager.LocalizeAll(true); Debug.Log("Done Google Sync"); } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, ""); } Debug.Log("Done Google Sync: source was up-to-date"); } }
public void Awake() { LocalizationManager.AddSource(this); UpdateDictionary(); UpdateAssetDictionary(); LocalizationManager.LocalizeAll(true); }
IEnumerator Import_Google_Coroutine() { WWW www = Import_Google_CreateWWWcall(); if (www == null) { yield break; } while (!www.isDone) { yield return(null); } //Debug.Log ("Google Result: " + www.text); if (string.IsNullOrEmpty(www.error) && www.text != "\"\"") { PlayerPrefs.SetString("I2Source_" + Google_SpreadsheetKey, www.text); PlayerPrefs.Save(); Import_Google_Result(www.text, eSpreadsheetUpdateMode.Replace); if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this); } LocalizationManager.LocalizeAll(); Debug.Log("Done Google Sync '" + www.text + "'"); } else { Debug.Log("Language Source was up-to-date with Google Spreadsheet"); } }
void OnDisable() { if (mLocalize == null) { return; } //#if TextMeshPro //string previous = null; //if (!Application.isPlaying && !string.IsNullOrEmpty(mLocalize.TMP_previewLanguage)) //{ // previous = LocalizationManager.CurrentLanguage; // LocalizationManager.PreviewLanguage( mLocalize.TMP_previewLanguage ); //} //#endif //mLocalize.OnLocalize(); LocalizationManager.LocalizeAll(); //#if TextMeshPro //if (!string.IsNullOrEmpty(previous)) //{ // LocalizationManager.PreviewLanguage(previous); // mLocalize.TMP_previewLanguage = null; //} //#endif }
void OnDisable() { if (mLocalize == null) { return; } #if TextMeshPro || TextMeshPro_Pre53 string previous = null; if (!Application.isPlaying && !string.IsNullOrEmpty(mLocalize.TMP_previewLanguage)) { previous = LocalizationManager.CurrentLanguage; LocalizationManager.PreviewLanguage(mLocalize.TMP_previewLanguage); } #endif //mLocalize.OnLocalize(); LocalizationManager.LocalizeAll(); #if TextMeshPro || TextMeshPro_Pre53 if (!string.IsNullOrEmpty(previous)) { LocalizationManager.PreviewLanguage(previous); mLocalize.TMP_previewLanguage = null; } #endif }
void Awake() { #if UNITY_EDITOR if (UnityEditor.BuildPipeline.isBuildingPlayer) { return; } #endif NeverDestroy = false; if (NeverDestroy) { if (ManagerHasASimilarSource()) { Destroy(this); return; } else { if (Application.isPlaying) { DontDestroyOnLoad(gameObject); } } } LocalizationManager.AddSource(this); UpdateDictionary(); UpdateAssetDictionary(); LocalizationManager.LocalizeAll(true); }
//[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] //public void AutoStart() //{ // if (_AutoRegister) // DoAutoRegister(); //} public void DoAutoRegister() { if (!LocalizationManager.ParamManagers.Contains(this)) { LocalizationManager.ParamManagers.Add(this); LocalizationManager.LocalizeAll(true); } }
public virtual void OnEnable() { if (!LocalizationManager.ParamManagers.Contains(this)) { LocalizationManager.ParamManagers.Add(this); LocalizationManager.LocalizeAll(Force: true); } }
IEnumerator Import_Google_Coroutine() { WWW www = Import_Google_CreateWWWcall(); if (www == null) { yield break; } while (!www.isDone) { yield return(null); } //Debug.Log ("Google Result: " + www.text); bool notError = string.IsNullOrEmpty(www.error); string wwwText = null; if (notError) { var bytes = www.bytes; wwwText = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); //www.text } if (notError && !string.IsNullOrEmpty(wwwText) && wwwText != "\"\"") { var errorMsg = Import_Google_Result(wwwText, eSpreadsheetUpdateMode.Replace, true); if (string.IsNullOrEmpty(errorMsg)) { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, true, www.error); } LocalizationManager.LocalizeAll(true); Debug.Log("Done Google Sync"); } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Done Google Sync: source was up-to-date"); } } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Language Source was up-to-date with Google Spreadsheet"); } }
private IEnumerator Import_Google_Coroutine() { WWW www = Import_Google_CreateWWWcall(); if (www == null) { yield break; } while (!www.isDone) { yield return(null); } bool num = string.IsNullOrEmpty(www.error); string text = null; if (num) { byte[] bytes = www.bytes; text = Encoding.UTF8.GetString(bytes, 0, bytes.Length); } if (num && !string.IsNullOrEmpty(text) && text != "\"\"") { if (string.IsNullOrEmpty(Import_Google_Result(text, eSpreadsheetUpdateMode.Replace, saveInPlayerPrefs: true))) { if (this.Event_OnSourceUpdateFromGoogle != null) { this.Event_OnSourceUpdateFromGoogle(this, arg2: true, www.error); } LocalizationManager.LocalizeAll(Force: true); UnityEngine.Debug.Log("Done Google Sync"); } else { if (this.Event_OnSourceUpdateFromGoogle != null) { this.Event_OnSourceUpdateFromGoogle(this, arg2: false, www.error); } UnityEngine.Debug.Log("Done Google Sync: source was up-to-date"); } } else { if (this.Event_OnSourceUpdateFromGoogle != null) { this.Event_OnSourceUpdateFromGoogle(this, arg2: false, www.error); } UnityEngine.Debug.Log("Language Source was up-to-date with Google Spreadsheet"); } }
IEnumerator Import_Google_Coroutine() { WWW www = Import_Google_CreateWWWcall(); if (www == null) { yield break; } while (!www.isDone) { yield return(null); } //Debug.Log ("Google Result: " + www.text); if (string.IsNullOrEmpty(www.error) && www.text != "\"\"") { var errorMsg = Import_Google_Result(www.text, eSpreadsheetUpdateMode.Replace, true); if (string.IsNullOrEmpty(errorMsg)) { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, true, www.error); } LocalizationManager.LocalizeAll(true); Debug.Log("Done Google Sync"); } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Done Google Sync: source was up-to-date"); } } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Language Source was up-to-date with Google Spreadsheet"); } }
void OnDisable() { mLocalizeInspector = null; if (LocalizationEditor.mCurrentInspector == this) { LocalizationEditor.mCurrentInspector = null; } if (mLocalize == null) { return; } //#if TextMeshPro //string previous = null; //if (!Application.isPlaying && !string.IsNullOrEmpty(mLocalize.TMP_previewLanguage)) //{ // previous = LocalizationManager.CurrentLanguage; // LocalizationManager.PreviewLanguage( mLocalize.TMP_previewLanguage ); //} //#endif //mLocalize.OnLocalize(); // Revert the preview language // except when in TMPro and not changing to another GameObject (TMPro has a bug where any change causes the inspector to Disable and Enable) if (!mLocalize.mLocalizeTargetName.Contains("LocalizeTarget_TextMeshPro") || Selection.activeGameObject == null || !Selection.gameObjects.Contains(mLocalize.gameObject)) { LocalizationManager.LocalizeAll(); } //#if TextMeshPro //if (!string.IsNullOrEmpty(previous)) //{ // LocalizationManager.PreviewLanguage(previous); // mLocalize.TMP_previewLanguage = null; //} //#endif RemoveUnusedReferences(mLocalize); }
void Awake() { NeverDestroy = false; if (NeverDestroy) { if (ManagerHasASimilarSource()) { Destroy(this); return; } else { if (Application.isPlaying) { DontDestroyOnLoad(gameObject); } } } LocalizationManager.AddSource(this); UpdateDictionary(); UpdateAssetDictionary(); LocalizationManager.LocalizeAll(true); }
IEnumerator Import_Google_Coroutine(bool JustCheck) { WWW www = Import_Google_CreateWWWcall(false, JustCheck); if (www == null) { yield break; } while (!www.isDone) { yield return(null); } //Debug.Log ("Google Result: " + www.text); bool notError = string.IsNullOrEmpty(www.error); string wwwText = null; if (notError) { var bytes = www.bytes; wwwText = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); //www.text bool isEmpty = string.IsNullOrEmpty(wwwText) || wwwText == "\"\""; if (JustCheck) { if (!isEmpty) { 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 (!isEmpty) { var errorMsg = Import_Google_Result(wwwText, eSpreadsheetUpdateMode.Replace, true); if (string.IsNullOrEmpty(errorMsg)) { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, true, www.error); } LocalizationManager.LocalizeAll(true); Debug.Log("Done Google Sync"); } else { if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Done Google Sync: source was up-to-date"); } yield break; } } if (Event_OnSourceUpdateFromGoogle != null) { Event_OnSourceUpdateFromGoogle(this, false, www.error); } Debug.Log("Language Source was up-to-date with Google Spreadsheet"); }
public static void ToogleH() { LocalizationManager.HighlightLocalizedTargets = !LocalizationManager.HighlightLocalizedTargets; LocalizationManager.LocalizeAll(true); }
public static void CallLocalizeAll() { LocalizationManager.LocalizeAll(true); HandleUtility.Repaint(); }
static void OnGUI_Keys_LanguageTranslations(string Key, Localize localizeCmp, bool IsPrimaryKey, ref TermData termdata, LanguageSource source) { bool IsSelect = Event.current.type == EventType.MouseUp; for (int i = 0; i < source.mLanguages.Count; ++i) { bool forcePreview = false; bool isEnabledLanguage = source.mLanguages[i].IsEnabled(); if (!isEnabledLanguage) { if (!GUI_ShowDisabledLanguagesTranslation) { continue; } GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.35f); } GUILayout.BeginHorizontal(); if (GUILayout.Button(source.mLanguages[i].Name, EditorStyles.label, GUILayout.Width(100))) { forcePreview = true; } string Translation = (GUI_SelectedInputType == 0 ? termdata.Languages[i] : termdata.Languages_Touch[i]) ?? string.Empty; if (string.IsNullOrEmpty(Translation)) { Translation = (GUI_SelectedInputType == 1 ? termdata.Languages[i] : termdata.Languages_Touch[i]) ?? string.Empty; } if (termdata.Languages[i] != termdata.Languages_Touch[i] && !string.IsNullOrEmpty(termdata.Languages[i]) && !string.IsNullOrEmpty(termdata.Languages_Touch[i])) { GUI.contentColor = GUITools.LightYellow; } if (termdata.TermType == eTermType.Text || termdata.TermType == eTermType.Child) { EditorGUI.BeginChangeCheck(); string CtrName = "TranslatedText" + i; GUI.SetNextControlName(CtrName); EditPluralTranslations(ref Translation, i, source.mLanguages[i].Code); //Translation = EditorGUILayout.TextArea(Translation, Style_WrapTextField, GUILayout.Width(Screen.width - 260 - (autoTranslated ? 20 : 0))); if (EditorGUI.EndChangeCheck()) { if (GUI_SelectedInputType == 0) { termdata.Languages[i] = Translation; } else { termdata.Languages_Touch[i] = Translation; } EditorUtility.SetDirty(source); } if (localizeCmp != null && (forcePreview || GUI.changed || (GUI.GetNameOfFocusedControl() == CtrName && IsSelect))) { if (IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.Term)) { localizeCmp.mTerm = Key; } if (!IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.SecondaryTerm)) { localizeCmp.mTermSecondary = Key; } string PreviousLanguage = LocalizationManager.CurrentLanguage; LocalizationManager.PreviewLanguage(source.mLanguages[i].Name); if (forcePreview || IsSelect) { LocalizationManager.LocalizeAll(); } else { localizeCmp.OnLocalize(true); } LocalizationManager.PreviewLanguage(PreviousLanguage); EditorUtility.SetDirty(localizeCmp); } GUI.contentColor = Color.white; //if (autoTranslated) //{ // if (GUILayout.Button(new GUIContent("\u2713"/*"A"*/,"Translated by Google Translator\nClick the button to approve the translation"), EditorStyles.toolbarButton, GUILayout.Width(autoTranslated ? 20 : 0))) // { // termdata.Flags[i] &= (byte)(byte.MaxValue ^ (byte)(GUI_SelectedInputType==0 ? TranslationFlag.AutoTranslated_Normal : TranslationFlag.AutoTranslated_Touch)); // } //} if (termdata.TermType == eTermType.Text) { if (TestButtonArg(eTest_ActionType.Button_Term_Translate, i, new GUIContent("T", "Translate"), EditorStyles.toolbarButton, GUILayout.Width(20))) { string sourceText = null; string sourceLangCode = null; FindTranslationSource(Key, termdata, source.mLanguages[i].Code, out sourceText, out sourceLangCode); var languages = (GUI_SelectedInputType == 0 ? termdata.Languages : termdata.Languages_Touch); var langIdx = i; Translate(sourceText, ref termdata, source.mLanguages[i].Code, (translation, error) => { languages[langIdx] = translation; }); GUI.FocusControl(string.Empty); } } } else { string MultiSpriteName = string.Empty; if (termdata.TermType == eTermType.Sprite && Translation.EndsWith("]", StringComparison.Ordinal)) // Handle sprites of type (Multiple): "SpritePath[SpriteName]" { int idx = Translation.LastIndexOf("[", StringComparison.Ordinal); int len = Translation.Length - idx - 2; MultiSpriteName = Translation.Substring(idx + 1, len); Translation = Translation.Substring(0, idx); } Object Obj = null; // Try getting the asset from the References section if (localizeCmp != null) { Obj = localizeCmp.FindTranslatedObject <Object>(Translation); } if (Obj == null && source != null) { Obj = source.FindAsset(Translation); } // If it wasn't in the references, Load it from Resources if (Obj == null && localizeCmp == null) { Obj = ResourceManager.pInstance.LoadFromResources <Object>(Translation); } Type ObjType = typeof(Object); switch (termdata.TermType) { case eTermType.Font: ObjType = typeof(Font); break; case eTermType.Texture: ObjType = typeof(Texture); break; case eTermType.AudioClip: ObjType = typeof(AudioClip); break; case eTermType.GameObject: ObjType = typeof(GameObject); break; case eTermType.Sprite: ObjType = typeof(Sprite); break; case eTermType.Material: ObjType = typeof(Material); break; #if NGUI case eTermType.UIAtlas: ObjType = typeof(UIAtlas); break; case eTermType.UIFont: ObjType = typeof(UIFont); break; #endif #if TK2D case eTermType.TK2dFont: ObjType = typeof(tk2dFont); break; case eTermType.TK2dCollection: ObjType = typeof(tk2dSpriteCollection); break; #endif #if TextMeshPro case eTermType.TextMeshPFont: ObjType = typeof(TMPro.TMP_FontAsset); break; #endif #if SVG case eTermType.SVGAsset: ObjType = typeof(SVGImporter.SVGAsset); break; #endif case eTermType.Object: ObjType = typeof(Object); break; } if (Obj != null && !string.IsNullOrEmpty(MultiSpriteName)) { string sPath = AssetDatabase.GetAssetPath(Obj); Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(sPath); Obj = null; for (int j = 0, jmax = objs.Length; j < jmax; ++j) { if (objs[j].name.Equals(MultiSpriteName)) { Obj = objs[j]; break; } } } bool bShowTranslationLabel = (Obj == null && !string.IsNullOrEmpty(Translation)); if (bShowTranslationLabel) { GUI.backgroundColor = GUITools.DarkGray; GUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Height(1)); GUILayout.Space(2); GUI.backgroundColor = Color.white; } Object NewObj = EditorGUILayout.ObjectField(Obj, ObjType, true, GUILayout.ExpandWidth(true)); if (Obj != NewObj) { string sPath = null; if (NewObj != null) { sPath = AssetDatabase.GetAssetPath(NewObj); AddObjectPath(ref sPath, localizeCmp, NewObj); if (HasObjectInReferences(NewObj, localizeCmp)) { sPath = NewObj.name; } else if (termdata.TermType == eTermType.Sprite) { sPath += "[" + NewObj.name + "]"; } } if (GUI_SelectedInputType == 0) { termdata.Languages[i] = sPath; } else { termdata.Languages_Touch[i] = sPath; } EditorUtility.SetDirty(source); } if (bShowTranslationLabel) { GUILayout.BeginHorizontal(); GUI.color = Color.red; GUILayout.FlexibleSpace(); GUILayout.Label(Translation, EditorStyles.miniLabel); GUILayout.FlexibleSpace(); GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.EndVertical(); } } GUILayout.EndHorizontal(); GUI.color = Color.white; } }