コード例 #1
0
        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)
                {
                    GUI.changed = false;
                    string CtrName = "TranslatedText" + i;
                    GUI.SetNextControlName(CtrName);

                    bool autoTranslated = false;// termdata.IsAutoTranslated(i, GUI_SelectedInputType == 1);

                    Translation = EditorGUILayout.TextArea(Translation, LocalizationEditor.Style_WrapTextField, GUILayout.Width(Screen.width - 260 - (autoTranslated ? 20 : 0)));
                    if (GUI.changed)
                    {
                        if (GUI_SelectedInputType == 0)
                        {
                            termdata.Languages[i] = Translation;
                            //termdata.Flags[i] &= byte.MaxValue ^ (byte)TranslationFlag.AutoTranslated_Normal;
                        }
                        else
                        {
                            termdata.Languages_Touch[i] = Translation;
                            //termdata.Flags[i] &= byte.MaxValue ^ (byte)TranslationFlag.AutoTranslated_Touch;
                        }
                        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 (GUILayout.Button("Translate", EditorStyles.toolbarButton, GUILayout.Width(80)))
                    {
                        string mainText = localizeCmp == null?LanguageSource.GetKeyFromFullTerm(Key) : localizeCmp.GetMainTargetsText();

                        if (GUI_SelectedInputType == 0)
                        {
                            Translate(mainText, ref termdata, ref termdata.Languages[i], source.mLanguages[i].Code);
                            //termdata.Flags[i] |= (byte)TranslationFlag.AutoTranslated_Normal;
                        }
                        else
                        {
                            Translate(mainText, ref termdata, ref termdata.Languages_Touch[i], source.mLanguages[i].Code);
                            //termdata.Flags[i] |= (byte)TranslationFlag.AutoTranslated_Touch;
                        }
                        GUI.FocusControl(string.Empty);
                    }
                }
                else
                {
                    string MultiSpriteName = string.Empty;

                    if (termdata.TermType == eTermType.Sprite && Translation.EndsWith("]"))                     // Handle sprites of type (Multiple):   "SpritePath[SpriteName]"
                    {
                        int idx = Translation.LastIndexOf("[");
                        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);
                    }

                    System.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 DFGUI
                    case eTermType.dfFont: ObjType = typeof(dfFont); break;

                    case eTermType.dfAtlas: ObjType = typeof(dfAtlas); break;
#endif

#if TK2D
                    case eTermType.TK2dFont: ObjType = typeof(tk2dFont); break;

                    case eTermType.TK2dCollection: ObjType = typeof(tk2dSpriteCollection); break;
#endif

#if TextMeshPro_Pre53
                    case eTermType.TextMeshPFont: ObjType = typeof(TMPro.TextMeshProFont); break;
#elif 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("AS TextArea", GUILayout.Height(1));
                        GUILayout.Space(2);

                        GUI.backgroundColor = Color.white;
                    }

                    Object NewObj = EditorGUILayout.ObjectField(Obj, ObjType, true, GUILayout.ExpandWidth(true));
                    if (Obj != NewObj && NewObj != null)
                    {
                        string 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;
            }
        }
コード例 #2
0
ファイル: Localize.cs プロジェクト: bornafana/Paralyzed
        public void OnLocalize(bool Force = false)
        {
            if (!Force && (!enabled || gameObject == null || !gameObject.activeInHierarchy))
            {
                return;
            }

            if (string.IsNullOrEmpty(LocalizationManager.CurrentLanguage))
            {
                return;
            }

            if (!AlwaysForceLocalize && !Force && !HasCallback() && LastLocalizedLanguage == LocalizationManager.CurrentLanguage)
            {
                return;
            }
            LastLocalizedLanguage = LocalizationManager.CurrentLanguage;

            // These are the terms actually used (will be mTerm/mSecondaryTerm or will get them from the objects if those are missing. e.g. Labels' text and font name)
            if (string.IsNullOrEmpty(FinalTerm) || string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                GetFinalTerms(out FinalTerm, out FinalSecondaryTerm);
            }


            bool hasCallback = I2Utils.IsPlaying() && HasCallback();

            if (!hasCallback && string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                return;
            }

            CallBackTerm          = FinalTerm;
            CallBackSecondaryTerm = FinalSecondaryTerm;
            MainTranslation       = (string.IsNullOrEmpty(FinalTerm) || FinalTerm == "-") ? null : LocalizationManager.GetTranslation(FinalTerm, false);
            SecondaryTranslation  = (string.IsNullOrEmpty(FinalSecondaryTerm) || FinalSecondaryTerm == "-") ? null : LocalizationManager.GetTranslation(FinalSecondaryTerm, false);

            if (!hasCallback && /*string.IsNullOrEmpty (MainTranslation)*/ string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(SecondaryTranslation))
            {
                return;
            }

            CurrentLocalizeComponent = this;

            {
                LocalizeCallBack.Execute(this);                   // This allows scripts to modify the translations :  e.g. "Player {0} wins"  ->  "Player Red wins"
                LocalizeEvent.Invoke();
                LocalizationManager.ApplyLocalizationParams(ref MainTranslation, gameObject, AllowLocalizedParameters);
            }

            if (!FindTarget())
            {
                return;
            }
            bool applyRTL = LocalizationManager.IsRight2Left && !IgnoreRTL;

            if (MainTranslation != null)
            {
                switch (PrimaryTermModifier)
                {
                case TermModification.ToUpper:      MainTranslation = MainTranslation.ToUpper(); break;

                case TermModification.ToLower:      MainTranslation = MainTranslation.ToLower(); break;

                case TermModification.ToUpperFirst: MainTranslation = GoogleTranslation.UppercaseFirst(MainTranslation); break;

                case TermModification.ToTitle:      MainTranslation = GoogleTranslation.TitleCase(MainTranslation); break;
                }
                if (!string.IsNullOrEmpty(TermPrefix))
                {
                    MainTranslation = applyRTL ? MainTranslation + TermPrefix : TermPrefix + MainTranslation;
                }
                if (!string.IsNullOrEmpty(TermSuffix))
                {
                    MainTranslation = applyRTL ? TermSuffix + MainTranslation : MainTranslation + TermSuffix;
                }

                if (AddSpacesToJoinedLanguages && LocalizationManager.HasJoinedWords && !string.IsNullOrEmpty(MainTranslation))
                {
                    var sb = new System.Text.StringBuilder();
                    sb.Append(MainTranslation[0]);
                    for (int i = 1, imax = MainTranslation.Length; i < imax; ++i)
                    {
                        sb.Append(' ');
                        sb.Append(MainTranslation[i]);
                    }

                    MainTranslation = sb.ToString();
                }
                if (applyRTL && mLocalizeTarget.AllowMainTermToBeRTL() && !string.IsNullOrEmpty(MainTranslation))
                {
                    MainTranslation = LocalizationManager.ApplyRTLfix(MainTranslation, MaxCharactersInRTL, IgnoreNumbersInRTL);
                }
            }

            if (SecondaryTranslation != null)
            {
                switch (SecondaryTermModifier)
                {
                case TermModification.ToUpper:      SecondaryTranslation = SecondaryTranslation.ToUpper(); break;

                case TermModification.ToLower:      SecondaryTranslation = SecondaryTranslation.ToLower(); break;

                case TermModification.ToUpperFirst: SecondaryTranslation = GoogleTranslation.UppercaseFirst(SecondaryTranslation); break;

                case TermModification.ToTitle:      SecondaryTranslation = GoogleTranslation.TitleCase(SecondaryTranslation); break;
                }
                if (applyRTL && mLocalizeTarget.AllowSecondTermToBeRTL() && !string.IsNullOrEmpty(SecondaryTranslation))
                {
                    SecondaryTranslation = LocalizationManager.ApplyRTLfix(SecondaryTranslation);
                }
            }

            if (LocalizationManager.HighlightLocalizedTargets)
            {
                MainTranslation = "LOC:" + FinalTerm;
            }

            mLocalizeTarget.DoLocalize(this, MainTranslation, SecondaryTranslation);

            CurrentLocalizeComponent = null;
        }
コード例 #3
0
 public override eTermType GetSecondaryTermType(Localize cmp)
 {
     return(eTermType.Font);
 }
コード例 #4
0
 public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
 {
     primaryTerm   = cmp.name;
     secondaryTerm = null;
 }
コード例 #5
0
        public override void OnInspectorGUI()
        {
            Undo.RecordObject(target, "Localize");

            GUI.backgroundColor = Color.Lerp(Color.black, Color.gray, 1);
            GUILayout.BeginVertical(GUIStyle_Background, GUILayout.Height(1));
            GUI.backgroundColor = Color.white;

            if (GUILayout.Button("Localize", GUIStyle_Header))
            {
                //Application.OpenURL(HelpURL_Documentation);
            }
            GUILayout.Space(-10);

            LocalizationManager.UpdateSources();

            if (LocalizationManager.Sources.Count == 0)
            {
                EditorGUILayout.HelpBox("Unable to find a Language Source.", MessageType.Warning);
            }
            else
            {
                GUILayout.Space(10);
                OnGUI_Target();
                GUILayout.Space(10);
                OnGUI_Terms();

                //if (mGUI_ShowTems || mGUI_ShowReferences) GUILayout.Space(5);

                OnGUI_References();

                if (mLocalize.mGUI_ShowReferences || mLocalize.mGUI_ShowCallback)
                {
                    GUILayout.Space(10);
                }

                Localize loc = target as Localize;

                //--[ Localize Callback ]----------------------
                string HeaderTitle = "On Localize Call:";
                if (!mLocalize.mGUI_ShowCallback && loc.LocalizeCallBack.Target != null && !string.IsNullOrEmpty(loc.LocalizeCallBack.MethodName))
                {
                    HeaderTitle = string.Concat(HeaderTitle, " <b>", loc.LocalizeCallBack.Target.name, ".</b><i>", loc.LocalizeCallBack.MethodName, "</i>");
                }
                mLocalize.mGUI_ShowCallback = GUITools.DrawHeader(HeaderTitle, mLocalize.mGUI_ShowCallback);
                if (mLocalize.mGUI_ShowCallback)
                {
                    GUITools.BeginContents();
                    DrawEventCallBack(loc.LocalizeCallBack, loc);
                    GUITools.EndContents();
                }
            }
            OnGUI_Source();

            GUILayout.Space(10);

            GUITools.OnGUI_Footer("I2 Localization", LocalizationManager.GetVersion(), HelpURL_forum, HelpURL_Documentation, LocalizeInspector.HelpURL_AssetStore);

            GUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
コード例 #6
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm);
コード例 #7
0
 public override bool IsValid(Localize cmp)
 {
     return(true);
 }
 public override eTermType GetSecondaryTermType(Localize cmp)
 {
     return(eTermType.Material);
 }
 public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
 {
     primaryTerm   = mTarget.texture ? mTarget.texture.name : string.Empty;
     secondaryTerm = null;
 }
コード例 #10
0
ファイル: Localize.cs プロジェクト: Siran1994/HillsOfSteel
        public void OnLocalize(bool Force = false)
        {
            if ((!Force && (!base.enabled || base.gameObject == null || !base.gameObject.activeInHierarchy)) || string.IsNullOrEmpty(LocalizationManager.CurrentLanguage) || (!AlwaysForceLocalize && !Force && !LocalizeCallBack.HasCallback() && LastLocalizedLanguage == LocalizationManager.CurrentLanguage))
            {
                return;
            }
            LastLocalizedLanguage = LocalizationManager.CurrentLanguage;
            if (!HasTargetCache())
            {
                FindTarget();
            }
            if (!HasTargetCache())
            {
                return;
            }
            if (string.IsNullOrEmpty(FinalTerm) || string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                GetFinalTerms(out FinalTerm, out FinalSecondaryTerm);
            }
            bool flag = Application.isPlaying && LocalizeCallBack.HasCallback();

            if (!flag && string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                return;
            }
            CallBackTerm          = FinalTerm;
            CallBackSecondaryTerm = FinalSecondaryTerm;
            MainTranslation       = ((string.IsNullOrEmpty(FinalTerm) || FinalTerm == "-") ? null : LocalizationManager.GetTermTranslation(FinalTerm, FixForRTL: false));
            SecondaryTranslation  = ((string.IsNullOrEmpty(FinalSecondaryTerm) || FinalSecondaryTerm == "-") ? null : LocalizationManager.GetTermTranslation(FinalSecondaryTerm, FixForRTL: false));
            if (!flag && string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(SecondaryTranslation))
            {
                return;
            }
            CurrentLocalizeComponent = this;
            if (Application.isPlaying)
            {
                LocalizeCallBack.Execute(this);
                LocalizationManager.ApplyLocalizationParams(ref MainTranslation, base.gameObject);
            }
            bool flag2 = LocalizationManager.IsRight2Left && !IgnoreRTL;

            if (flag2)
            {
                if (AllowMainTermToBeRTL && !string.IsNullOrEmpty(MainTranslation))
                {
                    MainTranslation = LocalizationManager.ApplyRTLfix(MainTranslation, MaxCharactersInRTL, IgnoreNumbersInRTL);
                }
                if (AllowSecondTermToBeRTL && !string.IsNullOrEmpty(SecondaryTranslation))
                {
                    SecondaryTranslation = LocalizationManager.ApplyRTLfix(SecondaryTranslation);
                }
            }
            if (PrimaryTermModifier != 0)
            {
                MainTranslation = (MainTranslation ?? string.Empty);
            }
            switch (PrimaryTermModifier)
            {
            case TermModification.ToUpper:
                MainTranslation = MainTranslation.ToUpper();
                break;

            case TermModification.ToLower:
                MainTranslation = MainTranslation.ToLower();
                break;

            case TermModification.ToUpperFirst:
                MainTranslation = GoogleTranslation.UppercaseFirst(MainTranslation);
                break;

            case TermModification.ToTitle:
                MainTranslation = GoogleTranslation.TitleCase(MainTranslation);
                break;
            }
            if (SecondaryTermModifier != 0)
            {
                SecondaryTranslation = (SecondaryTranslation ?? string.Empty);
            }
            switch (SecondaryTermModifier)
            {
            case TermModification.ToUpper:
                SecondaryTranslation = SecondaryTranslation.ToUpper();
                break;

            case TermModification.ToLower:
                SecondaryTranslation = SecondaryTranslation.ToLower();
                break;

            case TermModification.ToUpperFirst:
                SecondaryTranslation = GoogleTranslation.UppercaseFirst(SecondaryTranslation);
                break;

            case TermModification.ToTitle:
                SecondaryTranslation = GoogleTranslation.TitleCase(SecondaryTranslation);
                break;
            }
            if (!string.IsNullOrEmpty(TermPrefix))
            {
                MainTranslation = (flag2 ? (MainTranslation + TermPrefix) : (TermPrefix + MainTranslation));
            }
            if (!string.IsNullOrEmpty(TermSuffix))
            {
                MainTranslation = (flag2 ? (TermSuffix + MainTranslation) : (MainTranslation + TermSuffix));
            }
            EventDoLocalize(MainTranslation, SecondaryTranslation);
            CurrentLocalizeComponent = null;
        }
コード例 #11
0
ファイル: Localize.cs プロジェクト: cozlind/BleedForFreedom
        public void OnLocalize(bool Force = false)
        {
            if (!Force && (!enabled || gameObject == null || !gameObject.activeInHierarchy))
            {
                return;
            }

            if (string.IsNullOrEmpty(LocalizationManager.CurrentLanguage))
            {
                return;
            }

            if (!Force && LastLocalizedLanguage == LocalizationManager.CurrentLanguage)
            {
                return;
            }
            LastLocalizedLanguage = LocalizationManager.CurrentLanguage;

            if (!HasTargetCache())
            {
                FindTarget();
            }

            if (!HasTargetCache())
            {
                return;
            }

            // This are the terms actually used (will be mTerm/mSecondaryTerm or will get them from the objects if those are missing. e.g. Labels' text and font name)
            if (string.IsNullOrEmpty(FinalTerm) || string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                GetFinalTerms(out FinalTerm, out FinalSecondaryTerm);
            }

            if (string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                return;
            }

            CallBackTerm          = FinalTerm;
            CallBackSecondaryTerm = FinalSecondaryTerm;
            MainTranslation       = LocalizationManager.GetTermTranslation(FinalTerm);
            SecondaryTranslation  = LocalizationManager.GetTermTranslation(FinalSecondaryTerm);

            if (string.IsNullOrEmpty(MainTranslation) && string.IsNullOrEmpty(SecondaryTranslation))
            {
                return;
            }

            CurrentLocalizeComponent = this;
            LocalizeCallBack.Execute(this);                // This allows scripts to modify the translations :  e.g. "Player {0} wins"  ->  "Player Red wins"

            if (LocalizationManager.IsRight2Left && !IgnoreRTL)
            {
                if (AllowMainTermToBeRTL && !string.IsNullOrEmpty(MainTranslation))
                {
                    MainTranslation = LocalizationManager.ApplyRTLfix(MainTranslation, MaxCharactersInRTL);
                }
                if (AllowSecondTermToBeRTL && !string.IsNullOrEmpty(SecondaryTranslation))
                {
                    SecondaryTranslation = LocalizationManager.ApplyRTLfix(SecondaryTranslation);
                }
            }
            switch (PrimaryTermModifier)
            {
            case TermModification.ToUpper: MainTranslation = MainTranslation.ToUpper(); break;

            case TermModification.ToLower: MainTranslation = MainTranslation.ToLower(); break;

            case TermModification.ToUpperFirst: MainTranslation = GoogleTranslation.UppercaseFirst(MainTranslation); break;

            case TermModification.ToTitle: MainTranslation = GoogleTranslation.TitleCase(MainTranslation); break;
            }
            switch (SecondaryTermModifier)
            {
            case TermModification.ToUpper: SecondaryTranslation = SecondaryTranslation.ToUpper();  break;

            case TermModification.ToLower: SecondaryTranslation = SecondaryTranslation.ToLower();  break;

            case TermModification.ToUpperFirst: SecondaryTranslation = GoogleTranslation.UppercaseFirst(SecondaryTranslation); break;

            case TermModification.ToTitle: SecondaryTranslation = GoogleTranslation.TitleCase(SecondaryTranslation); break;
            }
            EventDoLocalize(MainTranslation, SecondaryTranslation);
            CurrentLocalizeComponent = null;
        }
コード例 #12
0
        public static T GetTranslatedObjectByTermName <T>(string Term, Localize optionalLocComp = null) where T : Object
        {
            string translation = GetTranslation(Term, FixForRTL: false);

            return(GetTranslatedObject <T>(translation));
        }
コード例 #13
0
        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 = termdata.GetTranslation(i, GUI_SelectedSpecialization);
                if (Translation == null)
                {
                    Translation = 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())
                    {
                        termdata.SetTranslation(i, Translation, GUI_SelectedSpecialization);
                        EditorUtility.SetDirty(source);
                        forcePreview = true;
                    }

                    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_SelectedSpecialization==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)))
                        {
                            var termData = termdata;
                            var indx     = i;
                            var key      = Key;
                            GUITools.DelayedCall(() => TranslateTerm(key, termData, source, indx));
                            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);

                            mCurrentInspector.serializedObject.ApplyModifiedProperties();
                            foreach (var cmp in mCurrentInspector.serializedObject.targetObjects)
                            {
                                AddObjectPath(ref sPath, cmp as Localize, NewObj);
                            }
                            mCurrentInspector.serializedObject.ApplyModifiedProperties();

                            if (HasObjectInReferences(NewObj, localizeCmp))
                            {
                                sPath = NewObj.name;
                            }
                            else
                            if (termdata.TermType == eTermType.Sprite)
                            {
                                sPath += "[" + NewObj.name + "]";
                            }
                        }

                        termdata.SetTranslation(i, sPath, GUI_SelectedSpecialization);
                        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;
            }
        }
コード例 #14
0
        // this method shows the key description and the localization to each language
        public static TermData OnGUI_Keys_Languages(string Key, Localize localizeCmp, bool IsPrimaryKey = true)
        {
            if (Key == null)
            {
                Key = string.Empty;
            }

            TermData termdata = null;

            LanguageSource source = (localizeCmp == null ? mLanguageSource : localizeCmp.Source);

            if (source == null)
            {
                source = LocalizationManager.GetSourceContaining(Key, false);
            }

            if (source == null)
            {
                if (localizeCmp == null)
                {
                    source = LocalizationManager.Sources[0];
                }
                else
                {
                    source = LocalizationManager.GetSourceContaining(IsPrimaryKey ? localizeCmp.SecondaryTerm : localizeCmp.Term, true);
                }
            }


            if (string.IsNullOrEmpty(Key))
            {
                EditorGUILayout.HelpBox("Select a Term to Localize", MessageType.Info);
                return(null);
            }
            else
            {
                termdata = source.GetTermData(Key);
                if (termdata == null && localizeCmp != null)
                {
                    var realSource = LocalizationManager.GetSourceContaining(Key, false);
                    if (realSource != null)
                    {
                        termdata = realSource.GetTermData(Key);
                        source   = realSource;
                    }
                }
                if (termdata == null)
                {
                    if (Key == "-")
                    {
                        return(null);
                    }
                    EditorGUILayout.HelpBox(string.Format("Key '{0}' is not Localized or it is in a different Language Source", Key), MessageType.Error);
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Add Term to Source"))
                    {
                        var termType = eTermType.Text;
                        if (localizeCmp != null && localizeCmp.mLocalizeTarget != null)
                        {
                            termType = IsPrimaryKey ? localizeCmp.mLocalizeTarget.GetPrimaryTermType(localizeCmp)
                                                    : localizeCmp.mLocalizeTarget.GetSecondaryTermType(localizeCmp);
                        }

                        AddTerm(Key, true, termType);
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    return(null);
                }
            }

            //--[ Type ]----------------------------------
            if (localizeCmp == null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Type:", GUILayout.ExpandWidth(false));
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termdata.TermType, GUILayout.ExpandWidth(true));
                if (termdata.TermType != NewType)
                {
                    termdata.TermType = NewType;
                }
                GUILayout.EndHorizontal();
            }


            //--[ Description ]---------------------------

            mKeysDesc_AllowEdit = GUILayout.Toggle(mKeysDesc_AllowEdit, "Description", EditorStyles.foldout, GUILayout.ExpandWidth(true));

            if (mKeysDesc_AllowEdit)
            {
                string NewDesc = EditorGUILayout.TextArea(termdata.Description, Style_WrapTextField);
                if (NewDesc != termdata.Description)
                {
                    termdata.Description = NewDesc;
                    EditorUtility.SetDirty(source);
                }
            }
            else
            {
                EditorGUILayout.HelpBox(string.IsNullOrEmpty(termdata.Description) ? "No description" : termdata.Description, MessageType.Info);
            }

            OnGUI_Keys_Language_SpecializationsBar(termdata);

            OnGUI_Keys_Languages(Key, ref termdata, localizeCmp, IsPrimaryKey, source);
            return(termdata);
        }
コード例 #15
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public override ILocalizeTarget Clone(Localize cmp)
 {
     return(this.MemberwiseClone() as ILocalizeTarget);
 }
コード例 #16
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract ILocalizeTarget Clone(Localize cmp);
コード例 #17
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract bool FindTarget(Localize cmp);
コード例 #18
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract bool CanLocalize(Localize cmp);
コード例 #19
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation);
コード例 #20
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public abstract bool HasTarget(Localize cmp);
コード例 #21
0
 public override eTermType GetPrimaryTermType(Localize cmp)
 {
     return(eTermType.GameObject);
 }
コード例 #22
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public override bool CanLocalize(Localize cmp)
 {
     return(cmp.GetComponent <T>() != null);
 }
コード例 #23
0
 public override bool CanLocalize(Localize cmp)
 {
     return(true);
 }
コード例 #24
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public override bool FindTarget(Localize cmp)
 {
     cmp.mTarget = (cmp.mTarget as T) ?? cmp.GetComponent <T>();
     return(cmp.mTarget != null);
 }
コード例 #25
0
 public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
 {
     primaryTerm   = mTarget ? mTarget.text : null;
     secondaryTerm = (mTarget.font != null ? mTarget.font.name : string.Empty);
 }
コード例 #26
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public T GetTarget(Localize cmp)
 {
     return(cmp.mTarget as T);
 }
コード例 #27
0
 public override eTermType GetPrimaryTermType(Localize cmp)
 {
     return(eTermType.Text);
 }
コード例 #28
0
ファイル: ILocalizeTarget.cs プロジェクト: hbali/teacher-app
 public override bool HasTarget(Localize cmp)
 {
     return(GetTarget(cmp) != null);
 }
コード例 #29
0
        public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
        {
            var mTarget = GetTarget(cmp);

            //--[ Localize Font Object ]----------
            {
                TMPro.TMP_FontAsset newFont = cmp.GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);

                if (newFont != null)
                {
                    if (mTarget.font != newFont)
                    {
                        mTarget.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = cmp.GetSecondaryTranslatedObj <Material>(ref mainTranslation, ref secondaryTranslation);
                    if (newMat != null && mTarget.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget.font.name, StringComparison.Ordinal))
                        {
                            newFont = GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
                            if (newFont != null)
                            {
                                mTarget.font = newFont;
                            }
                        }

                        mTarget.fontSharedMaterial /* fontMaterial*/ = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                mAlignmentWasRTL     = LocalizationManager.IsRight2Left;
                InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out mAlignment_LTR, out mAlignment_RTL);
            }
            else
            {
                TMPro.TextAlignmentOptions alignRTL, alignLTR;
                InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out alignLTR, out alignRTL);

                if ((mAlignmentWasRTL && mAlignment_RTL != alignRTL) ||
                    (!mAlignmentWasRTL && mAlignment_LTR != alignLTR))
                {
                    mAlignment_LTR = alignLTR;
                    mAlignment_RTL = alignRTL;
                }
                mAlignmentWasRTL = LocalizationManager.IsRight2Left;
            }

            if (mainTranslation != null && mTarget.text != mainTranslation)
            {
                if (cmp.CorrectAlignmentForRTL)
                {
                    mTarget.alignment         = (LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR);
                    mTarget.isRightToLeftText = LocalizationManager.IsRight2Left;
                    if (LocalizationManager.IsRight2Left)
                    {
                        mainTranslation = LocalizationManager.ReverseText(mainTranslation);
                    }
                }

                mTarget.text = mainTranslation;
            }
        }
コード例 #30
0
        // this method shows the key description and the localization to each language
        public static void OnGUI_Keys_Languages(string Key, Localize localizeCmp, bool IsPrimaryKey = true)
        {
            if (Key == null)
            {
                Key = string.Empty;
            }

            TermData termdata = null;

            LanguageSource source = (localizeCmp == null ? mLanguageSource : localizeCmp.Source);

            if (source == null)
            {
                source = LocalizationManager.GetSourceContaining(Key, false);
            }

            if (source == null)
            {
                if (localizeCmp == null)
                {
                    source = LocalizationManager.Sources[0];
                }
                else
                {
                    source = LocalizationManager.GetSourceContaining(IsPrimaryKey ? localizeCmp.SecondaryTerm : localizeCmp.Term, true);
                }
            }


            if (string.IsNullOrEmpty(Key))
            {
                EditorGUILayout.HelpBox("Select a Term to Localize", UnityEditor.MessageType.Info);
                return;
            }
            else
            {
                termdata = source.GetTermData(Key);
                if (termdata == null && localizeCmp != null)
                {
                    var realSource = LocalizationManager.GetSourceContaining(Key, false);
                    if (realSource != null)
                    {
                        termdata = realSource.GetTermData(Key);
                        source   = realSource;
                    }
                }
                if (termdata == null)
                {
                    if (Key == "-")
                    {
                        return;
                    }
                    EditorGUILayout.HelpBox(string.Format("Key '{0}' is not Localized or it is in a different Language Source", Key), UnityEditor.MessageType.Error);
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Add Term to Source"))
                    {
                        source.AddTerm(Key, eTermType.Text);
                        AddParsedTerm(Key, null, null, 1);
                        SetAllTerms_When_InferredTerms_IsInSource();
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();

                    return;
                }
            }

            //--[ Type ]----------------------------------
            if (localizeCmp == null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Type:", GUILayout.ExpandWidth(false));
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termdata.TermType, GUILayout.ExpandWidth(true));
                if (termdata.TermType != NewType)
                {
                    termdata.TermType = NewType;
                }
                GUILayout.EndHorizontal();
            }


            //--[ Description ]---------------------------

            mKeysDesc_AllowEdit = GUILayout.Toggle(mKeysDesc_AllowEdit, "Description", EditorStyles.foldout, GUILayout.ExpandWidth(true));

            if (mKeysDesc_AllowEdit)
            {
                string NewDesc = EditorGUILayout.TextArea(termdata.Description, LocalizationEditor.Style_WrapTextField);
                if (NewDesc != termdata.Description)
                {
                    termdata.Description = NewDesc;
                    EditorUtility.SetDirty(source);
                }
            }
            else
            {
                EditorGUILayout.HelpBox(string.IsNullOrEmpty(termdata.Description) ? "No description" : termdata.Description, UnityEditor.MessageType.Info);
            }

            OnGUI_Keys_Language_SpecializationsBar();

            //--[ Languages ]---------------------------
            GUILayout.BeginVertical("AS TextArea", GUILayout.Height(1));

            OnGUI_Keys_LanguageTranslations(Key, localizeCmp, IsPrimaryKey, ref termdata, source);

            if (termdata.TermType == eTermType.Text)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Translate All", GUILayout.Width(85)))
                {
                    string mainText = localizeCmp == null?LanguageSource.GetKeyFromFullTerm(Key) : localizeCmp.GetMainTargetsText();

                    for (int i = 0; i < source.mLanguages.Count; ++i)
                    {
                        if (string.IsNullOrEmpty(termdata.Languages[i]) && source.mLanguages[i].IsEnabled())
                        {
                            if (GUI_SelectedInputType == 0)
                            {
                                Translate(mainText, ref termdata, ref termdata.Languages[i], source.mLanguages[i].Code);
                                //termdata.Flags[i] |= (byte)TranslationFlag.AutoTranslated_Normal;
                            }
                            else
                            {
                                Translate(mainText, ref termdata, ref termdata.Languages_Touch[i], source.mLanguages[i].Code);
                                //termdata.Flags[i] |= (byte)TranslationFlag.AutoTranslated_Touch;
                            }
                        }
                    }
                    GUI.FocusControl(string.Empty);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }