Пример #1
0
        static void OnGUI_Keys_Language_SpecializationsBar(TermData termData)
        {
            var activeSpecializations = termData.GetAllSpecializations();

            GUILayout.BeginHorizontal();

            var TabStyle = new GUIStyle(GUI.skin.FindStyle("dragtab"));

            TabStyle.fixedHeight = 0;

            //var ss = GUI.skin.FindStyle("TL tab left");
            var TabOpenStyle = new GUIStyle(GUI.skin.FindStyle("dragtab"));

            TabOpenStyle.margin.right = -1;
            var TabCloseStyle = new GUIStyle(EditorStyles.label);

            //var TabCloseStyle = new GUIStyle(GUI.skin.FindStyle("TL tab right"));
            TabCloseStyle.margin.left  = -1;
            TabCloseStyle.padding.left = 4;

            //-- Specialization Tabs -----

            var prevSpecialization = "Any";

            foreach (var specialization in SpecializationManager.Singleton.mSpecializations)
            {
                if (!activeSpecializations.Contains(specialization) && specialization != GUI_SelectedSpecialization)
                {
                    continue;
                }

                bool isActive     = (specialization == GUI_SelectedSpecialization);
                var  labelContent = new GUIContent(specialization, "Specialization of the main translation (i.e. variants that show only on specific platforms or devices)\nThis allows using 'tap' instead of 'click' for touch devices.");

                if (isActive && specialization != "Any")
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Toggle(isActive, labelContent, TabStyle, GUILayout.Height(25), GUILayout.ExpandWidth(false));
                    //GUILayout.Label(labelContent, TabOpenStyle);
                    if (GUILayout.Button("x", TabCloseStyle, GUILayout.Width(15)))
                    {
                        termData.RemoveSpecialization(specialization);
                        GUI_SelectedSpecialization = prevSpecialization;
                        GUI.FocusControl(null);
                    }
                    GUILayout.EndHorizontal();
                }
                else
                if (GUILayout.Toggle(isActive, labelContent, TabStyle, GUILayout.Height(25), GUILayout.ExpandWidth(false)) && !isActive)
                {
                    GUI_SelectedSpecialization = specialization;
                    GUI.FocusControl(null);
                }
            }


            //-- Add new Specialization -----
            int newIndex = EditorGUILayout.Popup(-1, SpecializationManager.Singleton.mSpecializations, "DropDown", GUILayout.Width(20));

            if (newIndex >= 0)
            {
                GUI_SelectedSpecialization = SpecializationManager.Singleton.mSpecializations[newIndex];
            }

            GUILayout.FlexibleSpace();


            GUI_ShowDisabledLanguagesTranslation = GUILayout.Toggle(GUI_ShowDisabledLanguagesTranslation, new GUIContent("L", "Show Disabled Languages"), "Button", GUILayout.ExpandWidth(false));
            GUILayout.EndHorizontal();
            GUILayout.Space(-3);
        }
Пример #2
0
        static void OnGUI_Keys_LanguageTranslations(string Key, Localize localizeCmp, bool IsPrimaryKey, ref TermData termdata, LanguageSourceData 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, editMode: true);
                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.owner);
                        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.owner);
                    }

                    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;
            }
        }
Пример #3
0
        bool OnGUI_SelectKey(ref string Term, bool Inherited)            // Inherited==true means that the mTerm is empty and we are using the Label.text instead
        {
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();

            bool bChanged = false;

            mAllowEditKeyName = GUILayout.Toggle(mAllowEditKeyName, "Term:", EditorStyles.foldout, GUILayout.ExpandWidth(false));
            if (bChanged && mAllowEditKeyName)
            {
                mNewKeyName = Term;
            }

            bChanged = false;

            if (mTermsArray == null || System.Array.IndexOf(mTermsArray, Term) < 0)
            {
                UpdateTermsList(Term);
            }

            if (Inherited)
            {
                GUI.contentColor = Color.yellow * 0.8f;
            }

            int Index = System.Array.IndexOf(mTermsArray, Term);

            GUI.changed = false;

            int newIndex = EditorGUILayout.Popup(Index, mTermsArray);

            GUI.contentColor = Color.white;
            if (/*newIndex != Index && newIndex>=0*/ GUI.changed)
            {
                GUI.changed = false;
                mTermsArray [mTermsArray.Length - 1] = string.Empty;
                mNewKeyName = Term = mTermsArray[newIndex];
                if (GUI_SelectedTerm == 0)
                {
                    mLocalize.SetTerm(mNewKeyName);
                }
                else
                {
                    mLocalize.SetTerm(null, mNewKeyName);
                }
                mAllowEditKeyName = false;
                bChanged          = true;
            }
            LanguageSource source   = LocalizationManager.GetSourceContaining(Term);
            TermData       termData = source.GetTermData(Term);

            if (termData != null)
            {
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termData.TermType, GUILayout.Width(90));
                if (termData.TermType != NewType)
                {
                    termData.TermType = NewType;
                }
            }

            GUILayout.EndHorizontal();

            if (mAllowEditKeyName)
            {
                GUILayout.BeginHorizontal(GUILayout.Height(1));
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (mNewKeyName == null)
                {
                    mNewKeyName = string.Empty;
                }

                GUI.changed = false;
                mNewKeyName = EditorGUILayout.TextField(mNewKeyName, new GUIStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true));
                if (GUI.changed)
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    GUI.changed = false;
                }

                if (GUILayout.Button(string.Empty, string.IsNullOrEmpty(mNewKeyName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth(false)))
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    mNewKeyName = string.Empty;
                }

                GUILayout.EndHorizontal();

                string ValidatedName = mNewKeyName;
                LanguageSource.ValidateFullTerm(ref ValidatedName);

                bool CanUseNewName = (source.GetTermData(ValidatedName) == null);
                GUI.enabled = (!string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName = ValidatedName;
                    Term        = mNewKeyName;
                    mTermsArray = null;                         // this recreates that terms array

                    LanguageSource Source = null;
                                        #if UNITY_EDITOR
                    if (mLocalize.Source != null)
                    {
                        Source = mLocalize.Source;
                    }
                                        #endif

                    if (Source == null)
                    {
                        Source = LocalizationManager.Sources[0];
                    }

                    Source.AddTerm(mNewKeyName, eTermType.Text);
                    mAllowEditKeyName          = false;
                    bChanged                   = true;
                    GUIUtility.keyboardControl = 0;
                }
                GUI.enabled = (termData != null && !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button(new GUIContent("Rename", "Renames the term in the source and updates every object using it in the current scene"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName       = ValidatedName;
                    Term              = mNewKeyName;
                    mTermsArray       = null;                 // this recreates that terms array
                    mAllowEditKeyName = false;
                    bChanged          = true;
                    LocalizationEditor.TermReplacements = new Dictionary <string, string>();
                    LocalizationEditor.TermReplacements[termData.Term] = mNewKeyName;
                    termData.Term = mNewKeyName;
                    source.UpdateDictionary(true);
                    LocalizationEditor.ReplaceTermsInCurrentScene();
                    GUIUtility.keyboardControl = 0;
                    EditorApplication.update  += LocalizationEditor.DoParseTermsInCurrentScene;
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                bChanged |= OnGUI_SelectKey_PreviewTerms(ref Term);
            }

            GUILayout.Space(5);
            return(bChanged);
        }
Пример #4
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;

            LanguageSourceData source = mLanguageSource;

            if (localizeCmp != null && localizeCmp.Source != null)
            {
                source = localizeCmp.Source.mSource;
            }

            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.owner);
                }
            }
            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);
        }
Пример #5
0
        void OnGUI_KeyHeader(string sKey, string sCategory, string FullKey, int nUses, float YPosMin)
        {
            //--[ Toggle ]---------------------
            GUI.Box(new Rect(2, YPosMin + 2, 18, mRowSize), "", "Toolbar");
            OnGUI_SelectableToogleListItem(new Rect(2, YPosMin + 3, 15, mRowSize), FullKey, ref mSelectedKeys, "OL Toggle");

            bool bEnabled = mSelectedKeys.Contains(FullKey);

            //--[ Number of Objects using this key ]---------------------
            if (nUses >= 0)
            {
                if (nUses == 0)
                {
                    GUI.color = Color.Lerp(Color.gray, Color.white, 0.5f);
                    GUI.Label(new Rect(20, YPosMin + 2, 30, mRowSize), nUses.ToString(), "toolbarbutton");
                }
                else
                {
                    if (GUI.Button(new Rect(20, YPosMin + 2, 30, mRowSize), nUses.ToString(), "toolbarbutton"))
                    {
                        List <string> selection = new List <string>(mSelectedKeys);
                        if (!selection.Contains(FullKey))
                        {
                            selection.Add(FullKey);
                        }

                        List <GameObject> selGOs = new List <GameObject>();
                        for (int i = 0; i < selection.Count; ++i)
                        {
                            selGOs.AddRange(FindObjectsUsingKey(selection[i]));
                        }


                        if (selGOs.Count > 0)
                        {
                            Selection.objects = selGOs.ToArray();
                        }
                        else
                        {
                            ShowWarning("The selected Terms are not used in this Scene. Try opening other scenes");
                        }
                    }
                }
            }
            else
            {
                GUI.color = Color.Lerp(Color.red, Color.white, 0.6f);
                if (GUI.Button(new Rect(20, YPosMin + 2, 30, mRowSize), "", "toolbarbutton"))
                {
                    mCurrentToolsMode = eToolsMode.Parse;
                    mCurrentViewMode  = eViewMode.Tools;
                }
            }
            GUI.color = Color.white;

            TermData termData      = ShowTerm_termData != null ? ShowTerm_termData : mLanguageSource.GetTermData(FullKey);
            bool     bKeyIsMissing = (termData == null);
            float    MinX          = 50;

            if (bKeyIsMissing)
            {
                Rect rect = new Rect(50, YPosMin + 2, mRowSize, mRowSize + 2);
                GUI.DrawTexture(rect, GUI.skin.GetStyle("CN EntryWarn").normal.background);
                GUI.Label(rect, new GUIContent("", "This term is used in the scene, but its not localized in the Language Source"));
                MinX += rect.width;
            }
            else
            {
                MinX += 3;
            }

            float listWidth = Mathf.Max(Screen.width, mTermList_MaxWidth);
            Rect  rectKey   = new Rect(MinX, YPosMin + 2, listWidth - MinX, mRowSize);

            if (mKeyToExplore == FullKey)
            {
                GUI.backgroundColor = Color.Lerp(Color.blue, Color.white, 0.8f);
                if (GUI.Button(rectKey, new GUIContent(sKey, EditorStyles.foldout.onNormal.background), EditorStyles.textArea))
                {
                    mKeyToExplore = string.Empty;
                    ClearErrors();
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                GUIStyle LabelStyle = EditorStyles.label;
                if (!bKeyIsMissing && !TermHasAllTranslations(mLanguageSource, termData))
                {
                    LabelStyle           = new GUIStyle(EditorStyles.label);
                    LabelStyle.fontStyle = FontStyle.Italic;
                    GUI.color            = Color.Lerp(Color.white, Color.yellow, 0.5f);
                }
                if (!bEnabled)
                {
                    GUI.contentColor = Color.Lerp(Color.gray, Color.white, 0.3f);
                }
                if (GUI.Button(rectKey, sKey, LabelStyle))
                {
                    SelectTerm(FullKey);
                    ClearErrors();
                }
                if (!bEnabled)
                {
                    GUI.contentColor = Color.white;
                }
                GUI.color = Color.white;
            }
            //--[ Category ]--------------------------
            if (sCategory != LanguageSource.EmptyCategory)
            {
                if (mKeyToExplore == FullKey)
                {
                    rectKey.x     = listWidth - 100 - 38;
                    rectKey.width = 100;
                    if (GUI.Button(rectKey, sCategory, EditorStyles.toolbarButton))
                    {
                        OpenTool_ChangeCategoryOfSelectedTerms();
                    }
                }
                else
                {
                    GUIStyle stl = new GUIStyle(EditorStyles.miniLabel);
                    stl.alignment = TextAnchor.MiddleRight;
                    rectKey.width = 100;                    //EditorStyles.miniLabel.CalcSize(new GUIContent(sCategory)).x;
                    rectKey.x     = listWidth - rectKey.width - 38 - 13;

                    if (GUI.Button(rectKey, sCategory, stl))
                    {
                        SelectTerm(FullKey);
                        ClearErrors();
                    }
                }
            }
        }
        public string Import_CSV(string Category, List <string[]> CSV, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
        {
            string[] Tokens = CSV[0];

            int LanguagesStartIdx = 1;
            int TypeColumnIdx     = -1;
            int DescColumnIdx     = -1;

            var ValidColumnName_Key  = new string[] { "Key" };
            var ValidColumnName_Type = new string[] { "Type" };
            var ValidColumnName_Desc = new string[] { "Desc", "Description" };

            if (Tokens.Length > 1 && ArrayContains(Tokens[0], ValidColumnName_Key))
            {
                if (UpdateMode == eSpreadsheetUpdateMode.Replace)
                {
                    ClearAllData();
                }

                if (Tokens.Length > 2)
                {
                    if (ArrayContains(Tokens[1], ValidColumnName_Type))
                    {
                        TypeColumnIdx     = 1;
                        LanguagesStartIdx = 2;
                    }
                    if (ArrayContains(Tokens[1], ValidColumnName_Desc))
                    {
                        DescColumnIdx     = 1;
                        LanguagesStartIdx = 2;
                    }
                }
                if (Tokens.Length > 3)
                {
                    if (ArrayContains(Tokens[2], ValidColumnName_Type))
                    {
                        TypeColumnIdx     = 2;
                        LanguagesStartIdx = 3;
                    }
                    if (ArrayContains(Tokens[2], ValidColumnName_Desc))
                    {
                        DescColumnIdx     = 2;
                        LanguagesStartIdx = 3;
                    }
                }
            }
            else
            {
                return("Bad Spreadsheet Format.\nFirst columns should be 'Key', 'Type' and 'Desc'");
            }

            int nLanguages = Mathf.Max(Tokens.Length - LanguagesStartIdx, 0);

            int[] LanIndices = new int[nLanguages];
            for (int i = 0; i < nLanguages; ++i)
            {
                string LanName, LanCode;
                GoogleLanguages.UnPackCodeFromLanguageName(Tokens[i + LanguagesStartIdx], out LanName, out LanCode);

                int LanIdx = -1;
                if (!string.IsNullOrEmpty(LanCode))
                {
                    LanIdx = GetLanguageIndexFromCode(LanCode);
                }
                else
                {
                    LanIdx = GetLanguageIndex(LanName);
                }

                if (LanIdx < 0)
                {
                    LanguageData lanData = new LanguageData();
                    lanData.Name = LanName;
                    lanData.Code = LanCode;
                    mLanguages.Add(lanData);
                    LanIdx = mLanguages.Count - 1;
                }
                LanIndices[i] = LanIdx;
            }

            //--[ Update the Languages array in the existing terms]-----
            nLanguages = mLanguages.Count;
            for (int i = 0, imax = mTerms.Count; i < imax; ++i)
            {
                TermData termData = mTerms[i];
                if (termData.Languages.Length < nLanguages)
                {
                    Array.Resize(ref termData.Languages, nLanguages);
                    Array.Resize(ref termData.Languages_Touch, nLanguages);
                    Array.Resize(ref termData.Flags, nLanguages);
                }
            }

            //--[ Keys ]--------------

            for (int i = 1, imax = CSV.Count; i < imax; ++i)
            {
                Tokens = CSV[i];
                string sKey    = string.IsNullOrEmpty(Category) ? Tokens[0] : string.Concat(Category, "/", Tokens[0]);
                bool   isTouch = false;
                if (sKey.EndsWith("[touch]"))
                {
                    sKey    = sKey.Remove(sKey.Length - "[touch]".Length);
                    isTouch = true;
                }
                LanguageSource.ValidateFullTerm(ref sKey);
                if (string.IsNullOrEmpty(sKey))
                {
                    continue;
                }

                TermData termData = GetTermData(sKey);

                // Check to see if its a new term
                if (termData == null)
                {
                    termData      = new TermData();
                    termData.Term = sKey;

                    termData.Languages       = new string[mLanguages.Count];
                    termData.Languages_Touch = new string[mLanguages.Count];
                    termData.Flags           = new byte[mLanguages.Count];
                    for (int j = 0; j < mLanguages.Count; ++j)
                    {
                        termData.Languages[j] = termData.Languages_Touch[j] = string.Empty;
                    }

                    mTerms.Add(termData);
                    mDictionary.Add(sKey, termData);
                }
                else
                // This term already exist
                if (UpdateMode == eSpreadsheetUpdateMode.AddNewTerms)
                {
                    continue;
                }

                if (TypeColumnIdx > 0)
                {
                    termData.TermType = GetTermType(Tokens[TypeColumnIdx]);
                }

                if (DescColumnIdx > 0)
                {
                    termData.Description = Tokens[DescColumnIdx];
                }

                for (int j = 0; j < LanIndices.Length && j < Tokens.Length - LanguagesStartIdx; ++j)
                {
                    if (!string.IsNullOrEmpty(Tokens[j + LanguagesStartIdx]))                   // Only change the translation if there is a new value
                    {
                        var value  = Tokens[j + LanguagesStartIdx];
                        var isAuto = value.StartsWith("[i2auto]");
                        if (isAuto)
                        {
                            value = value.Substring("[isauto]".Length);
                            if (value.StartsWith("\"") && value.EndsWith("\""))
                            {
                                value = value.Substring(1, value.Length - 2);
                            }
                        }

                        //if (value=="-")
                        //	value = string.Empty;

                        var lanIdx = LanIndices[j];
                        if (isTouch)
                        {
                            termData.Languages_Touch[lanIdx] = value;
                            if (isAuto)
                            {
                                termData.Flags[lanIdx] |= (byte)TranslationFlag.AutoTranslated_Touch;
                            }
                            else
                            {
                                termData.Flags[lanIdx] &= byte.MaxValue ^ ((byte)TranslationFlag.AutoTranslated_Touch);
                            }
                        }
                        else
                        {
                            termData.Languages[lanIdx] = value;
                            if (isAuto)
                            {
                                termData.Flags[lanIdx] |= (byte)TranslationFlag.AutoTranslated_Normal;
                            }
                            else
                            {
                                termData.Flags[lanIdx] &= byte.MaxValue ^ ((byte)TranslationFlag.AutoTranslated_Normal);
                            }
                        }
                    }
                }
            }

            return(string.Empty);
        }
Пример #7
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.Sources[0];
            }


            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)
                {
                    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);
                        GetParsedTerm(Key);
                        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 ? Key : localizeCmp.GetMainTargetsText();

                    for (int i = 0; i < source.mLanguages.Count; ++i)
                    {
                        if (string.IsNullOrEmpty(termdata.Languages[i]))
                        {
                            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();
        }
Пример #8
0
 private static void AppendI2Term(StringBuilder Builder, int nLanguages, string Term, TermData termData, string postfix, string[] aLanguages, string[] aSecLanguages, char Separator, byte FlagBitMask, byte SecFlagBitMask)
 {
     Builder.Append(Term);
     Builder.Append(postfix);
     Builder.Append("[*]");
     Builder.Append(termData.TermType.ToString());
     Builder.Append("[*]");
     Builder.Append(termData.Description);
     for (int i = 0; i < Mathf.Min(nLanguages, aLanguages.Length); i++)
     {
         Builder.Append("[*]");
         string value = aLanguages[i];
         if (string.IsNullOrEmpty(value) && aSecLanguages != null)
         {
             value = aSecLanguages[i];
         }
         Builder.Append(value);
     }
 }
        public static bool ShouldShowTerm(string Term, string Category, int nUses, ParsedTerm parsedTerm = null)
        {
            if (!string.IsNullOrEmpty(Category) && !mSelectedCategories.Contains(Category))
            {
                return(false);
            }
            if (Term == "-")
            {
                return(false);
            }


            var fullTerm = Term;

            if (!string.IsNullOrEmpty(Category) && Category != LanguageSource.EmptyCategory)
            {
                fullTerm = Category + "/" + Term;
            }

            if (parsedTerm != null && parsedTerm.termData != null)
            {
                ShowTerm_termData = parsedTerm.termData;
            }
            else
            {
                ShowTerm_termData = mLanguageSource.GetTermData(fullTerm);
                if (parsedTerm != null)
                {
                    parsedTerm.termData = ShowTerm_termData;
                }
            }


            var  filter         = KeyList_Filter.Trim();
            bool useTranslation = filter.StartsWith("f ", System.StringComparison.OrdinalIgnoreCase);

            if (useTranslation)
            {
                if (ShowTerm_termData == null)
                {
                    return(false);
                }

                filter = filter.Substring(2).Trim();
                if (!string.IsNullOrEmpty(filter))
                {
                    bool hasFilter = false;
                    for (int i = 0; i < ShowTerm_termData.Languages.Length; ++i)
                    {
                        if (!string.IsNullOrEmpty(ShowTerm_termData.Languages[i]) && StringContainsFilter(ShowTerm_termData.Languages[i], filter))
                        {
                            hasFilter = true;
                            break;
                        }
                    }
                    if (!hasFilter)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                bool onlyCategory = filter.StartsWith("c ", System.StringComparison.OrdinalIgnoreCase);
                if (onlyCategory)
                {
                    filter = filter.Substring(2).Trim();
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    bool matchesCategory = StringContainsFilter(Category, filter);
                    bool matchesName     = !onlyCategory && StringContainsFilter(Term, filter);

                    if (!matchesCategory && !matchesName)
                    {
                        return(false);
                    }
                }
            }


            bool bIsMissing = ShowTerm_termData == null;

            if (nUses < 0)
            {
                return(true);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) > 0 && bIsMissing)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing) == 0 && bIsMissing)
            {
                return(false);
            }

            if ((mFlagsViewKeys & (int)eFlagsViewKeys.Used) > 0 && nUses > 0)
            {
                return(true);
            }
            if ((mFlagsViewKeys & (int)eFlagsViewKeys.NotUsed) > 0 && nUses == 0)
            {
                return(true);
            }

            return(false);
        }
        void ReplaceSelectedTerms()
        {
            EditorApplication.update -= ReplaceSelectedTerms;
            if (string.IsNullOrEmpty(mKeyToExplore))
            {
                return;
            }

            mIsParsing = true;
            string sNewKey = mKeyToExplore;

            //--[ Create new Term ]-----------------------
            if (mLanguageSource.GetTermData(sNewKey) == null)
            {
                TermData termData = AddTerm(sNewKey);

                //--[ Copy the values from any existing term if the target is a new term
                TermData oldTerm = null;
                for (int i = 0, imax = mSelectedKeys.Count; i < imax; ++i)
                {
                    oldTerm = mLanguageSource.GetTermData(mSelectedKeys[i]);
                    if (oldTerm != null)
                    {
                        break;
                    }
                }

                if (oldTerm != null)
                {
                    termData.TermType    = oldTerm.TermType;
                    termData.Description = oldTerm.Description;
                    System.Array.Copy(oldTerm.Languages, termData.Languages, oldTerm.Languages.Length);
                    System.Array.Copy(oldTerm.Languages_Touch, termData.Languages_Touch, oldTerm.Languages_Touch.Length);
                }
            }

            //--[ Delete the selected Terms from the source ]-----------------
            TermReplacements = new Dictionary <string, string>();
            for (int i = mSelectedKeys.Count - 1; i >= 0; --i)
            {
                string OldTerm = mSelectedKeys[i];
                if (OldTerm == sNewKey)
                {
                    continue;
                }

                TermReplacements[OldTerm] = mKeyToExplore;
                DeleteTerm(OldTerm);
            }
            ExecuteActionOnSelectedScenes(ReplaceTermsInCurrentScene);
            DoParseTermsInCurrentScene();

            //--[ Update Selected Categories ]-------------
            string mNewCategory = LanguageSource.GetCategoryFromFullTerm(sNewKey);

            if (mNewCategory == string.Empty)
            {
                mNewCategory = LanguageSource.EmptyCategory;
            }
            if (!mSelectedCategories.Contains(mNewCategory))
            {
                mSelectedCategories.Add(mNewCategory);
            }
            //RemoveUnusedCategoriesFromSelected();

            TermReplacements = null;
            mIsParsing       = false;
        }
        void AssignCategoryToSelectedTerms()
        {
            mIsParsing = true;

            EditorApplication.update -= AssignCategoryToSelectedTerms;

            mNewCategory = mNewCategory.Trim(LanguageSourceData.CategorySeparators);

            if (mNewCategory == LanguageSourceData.EmptyCategory)
            {
                mNewCategory = string.Empty;
            }

            TermReplacements = new Dictionary <string, string>(System.StringComparer.Ordinal);
            for (int i = mSelectedKeys.Count - 1; i >= 0; --i)
            {
                string sKey, sCategory;
                string OldTerm = mSelectedKeys[i];

                LanguageSourceData.DeserializeFullTerm(OldTerm, out sKey, out sCategory);
                if (!string.IsNullOrEmpty(mNewCategory))
                {
                    sKey = string.Concat(mNewCategory, "/", sKey);
                }

                if (OldTerm == sKey)
                {
                    continue;
                }

                TermReplacements[OldTerm] = sKey;
                if (!mLanguageSource.ContainsTerm(sKey))
                {
                    TermData termData = mLanguageSource.GetTermData(OldTerm);
                    if (termData != null)
                    {
                        termData.Term = sKey;
                    }
                    else
                    {
                        TermReplacements.Remove(OldTerm);
                    }
                    mLanguageSource.Editor_SetDirty();
                }
            }
            if (TermReplacements.Count <= 0)
            {
                ShowError("Unable to assign category: Terms were not found in the selected LanguageSource");
            }
            else
            {
                mLanguageSource.UpdateDictionary(true);
                ExecuteActionOnSelectedScenes(ReplaceTermsInCurrentScene);
                ParseTerms(true, false, true);

                if (string.IsNullOrEmpty(mNewCategory))
                {
                    mNewCategory = LanguageSourceData.EmptyCategory;
                }
                if (!mSelectedCategories.Contains(mNewCategory))
                {
                    mSelectedCategories.Add(mNewCategory);
                }
                //RemoveUnusedCategoriesFromSelected();
                ScheduleUpdateTermsToShowInList();
            }
            TermReplacements = null;
            mIsParsing       = false;
        }
Пример #12
0
        public string Import_CSV(string Category, List <string[]> CSV, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
        {
            string[] array = CSV[0];
            int      num   = 1;
            int      num2  = -1;
            int      num3  = -1;

            string[] texts = new string[1]
            {
                "Key"
            };
            string[] texts2 = new string[1]
            {
                "Type"
            };
            string[] texts3 = new string[2]
            {
                "Desc",
                "Description"
            };
            if (array.Length > 1 && ArrayContains(array[0], texts))
            {
                if (UpdateMode == eSpreadsheetUpdateMode.Replace)
                {
                    ClearAllData();
                }
                if (array.Length > 2)
                {
                    if (ArrayContains(array[1], texts2))
                    {
                        num2 = 1;
                        num  = 2;
                    }
                    if (ArrayContains(array[1], texts3))
                    {
                        num3 = 1;
                        num  = 2;
                    }
                }
                if (array.Length > 3)
                {
                    if (ArrayContains(array[2], texts2))
                    {
                        num2 = 2;
                        num  = 3;
                    }
                    if (ArrayContains(array[2], texts3))
                    {
                        num3 = 2;
                        num  = 3;
                    }
                }
                int   num4   = Mathf.Max(array.Length - num, 0);
                int[] array2 = new int[num4];
                for (int i = 0; i < num4; i++)
                {
                    if (string.IsNullOrEmpty(array[i + num]))
                    {
                        array2[i] = -1;
                        continue;
                    }
                    string text = array[i + num];
                    bool   flag = true;
                    if (text.StartsWith("$"))
                    {
                        flag = false;
                        text = text.Substring(1);
                    }
                    GoogleLanguages.UnPackCodeFromLanguageName(text, out string Language, out string code);
                    int num5 = -1;
                    num5 = (string.IsNullOrEmpty(code) ? GetLanguageIndex(Language) : GetLanguageIndexFromCode(code));
                    if (num5 < 0)
                    {
                        LanguageData languageData = new LanguageData();
                        languageData.Name  = Language;
                        languageData.Code  = code;
                        languageData.Flags = (byte)(0 | ((!flag) ? 1 : 0));
                        mLanguages.Add(languageData);
                        num5 = mLanguages.Count - 1;
                    }
                    array2[i] = num5;
                }
                num4 = mLanguages.Count;
                int j = 0;
                for (int count = mTerms.Count; j < count; j++)
                {
                    TermData termData = mTerms[j];
                    if (termData.Languages.Length < num4)
                    {
                        Array.Resize(ref termData.Languages, num4);
                        Array.Resize(ref termData.Languages_Touch, num4);
                        Array.Resize(ref termData.Flags, num4);
                    }
                }
                int k = 1;
                for (int count2 = CSV.Count; k < count2; k++)
                {
                    array = CSV[k];
                    string Term  = string.IsNullOrEmpty(Category) ? array[0] : (Category + "/" + array[0]);
                    bool   flag2 = false;
                    if (Term.EndsWith("[touch]"))
                    {
                        Term  = Term.Remove(Term.Length - "[touch]".Length);
                        flag2 = true;
                    }
                    ValidateFullTerm(ref Term);
                    if (string.IsNullOrEmpty(Term))
                    {
                        continue;
                    }
                    TermData termData2 = GetTermData(Term);
                    if (termData2 == null)
                    {
                        termData2                 = new TermData();
                        termData2.Term            = Term;
                        termData2.Languages       = new string[mLanguages.Count];
                        termData2.Languages_Touch = new string[mLanguages.Count];
                        termData2.Flags           = new byte[mLanguages.Count];
                        for (int l = 0; l < mLanguages.Count; l++)
                        {
                            termData2.Languages[l] = (termData2.Languages_Touch[l] = string.Empty);
                        }
                        mTerms.Add(termData2);
                        mDictionary.Add(Term, termData2);
                    }
                    else if (UpdateMode == eSpreadsheetUpdateMode.AddNewTerms)
                    {
                        continue;
                    }
                    if (num2 > 0)
                    {
                        termData2.TermType = GetTermType(array[num2]);
                    }
                    if (num3 > 0)
                    {
                        termData2.Description = array[num3];
                    }
                    for (int m = 0; m < array2.Length && m < array.Length - num; m++)
                    {
                        if (string.IsNullOrEmpty(array[m + num]))
                        {
                            continue;
                        }
                        int num6 = array2[m];
                        if (num6 >= 0)
                        {
                            string text2 = array[m + num];
                            if (flag2)
                            {
                                termData2.Languages_Touch[num6] = text2;
                                termData2.Flags[num6]          &= 253;
                            }
                            else
                            {
                                termData2.Languages[num6] = text2;
                                termData2.Flags[num6]    &= 254;
                            }
                        }
                    }
                }
                return(string.Empty);
            }
            return("Bad Spreadsheet Format.\nFirst columns should be 'Key', 'Type' and 'Desc'");
        }
Пример #13
0
 private static void AppendTerm(StringBuilder Builder, int nLanguages, string Term, TermData termData, string prefix, string[] aLanguages, string[] aSecLanguages, char Separator, byte FlagBitMask, byte SecFlagBitMask)
 {
     AppendString(Builder, Term, Separator);
     if (!string.IsNullOrEmpty(prefix))
     {
         Builder.Append(prefix);
     }
     Builder.Append(Separator);
     Builder.Append(termData.TermType.ToString());
     Builder.Append(Separator);
     AppendString(Builder, termData.Description, Separator);
     for (int i = 0; i < Mathf.Min(nLanguages, aLanguages.Length); i++)
     {
         Builder.Append(Separator);
         string text = aLanguages[i];
         if (string.IsNullOrEmpty(text) && aSecLanguages != null)
         {
             text = aSecLanguages[i];
         }
         AppendTranslation(Builder, text, Separator, string.Empty);
     }
     Builder.Append("\n");
 }
Пример #14
0
        void OnGUI_Terms()
        {
            if (mLocalize.mGUI_ShowTems = GUITools.DrawHeader("Terms", mLocalize.mGUI_ShowTems))
            {
                //--[ tabs: Main and Secondary Terms ]----------------
                int oldTab = GUI_SelectedTerm;
                if (mLocalize.mLocalizeTarget != null && mLocalize.mLocalizeTarget.CanUseSecondaryTerm())
                {
                    GUI_SelectedTerm = GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "Main", "Secondary" });
                }
                else
                {
                    GUI_SelectedTerm = 0;
                    GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "Main", "" });
                }

                GUITools.BeginContents();

                TermData termData = null;

                if (GUI_SelectedTerm == 0)
                {
                    termData = OnGUI_PrimaryTerm(oldTab != GUI_SelectedTerm);
                }
                else
                {
                    termData = OnGUI_SecondaryTerm(oldTab != GUI_SelectedTerm);
                }

                GUITools.EndContents();

                //--[ Modifier ]-------------
                if (mLocalize.Term != "-" && termData != null && termData.TermType == eTermType.Text)
                {
                    EditorGUI.BeginChangeCheck();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Prefix:");
                    EditorGUILayout.PropertyField(mProp_TermPrefix, GUITools.EmptyContent);
                    GUILayout.Label("Suffix:");
                    EditorGUILayout.PropertyField(mProp_TermSuffix, GUITools.EmptyContent);
                    GUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorApplication.delayCall += () =>
                        {
                            if (targets != null)
                            {
                                foreach (var t in targets)
                                {
                                    if ((t as Localize) != null)
                                    {
                                        (t as Localize).OnLocalize(true);
                                    }
                                }
                            }
                        };
                    }
                    EditorGUI.BeginChangeCheck();
                    int val = EditorGUILayout.Popup("Modifier", GUI_SelectedTerm == 0 ? (int)mLocalize.PrimaryTermModifier : (int)mLocalize.SecondaryTermModifier, System.Enum.GetNames(typeof(Localize.TermModification)));
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.FindProperty(GUI_SelectedTerm == 0 ? "PrimaryTermModifier" : "SecondaryTermModifier").enumValueIndex = val;
                        GUI.changed = false;
                    }
                }

                OnGUI_Options();
                //--[ OnAwake vs OnEnable ]-------------
                //GUILayout.BeginHorizontal();
                //mProp_LocalizeOnAwake.boolValue = GUILayout.Toggle(mProp_LocalizeOnAwake.boolValue, new GUIContent(" Pre-Localize on Awake", "Localizing on Awake could result in a lag when the level is loaded but faster later when objects are enabled. If false, it will Localize OnEnable, so will yield faster level load but could have a lag when screens are enabled"));
                //GUILayout.FlexibleSpace();
                //if (mLocalize.HasCallback())
                //{
                //    GUI.enabled = false;
                //    GUILayout.Toggle(true, new GUIContent(" Force Localize", "Enable this when the translations have parameters (e.g. Thew winner is {[WINNER}]) to prevent any optimization that could prevent updating the translation when the object is enabled"));
                //    GUI.enabled = true;
                //}
                //else
                //{
                //    mProp_AlwaysForceLocalize.boolValue = GUILayout.Toggle(mProp_AlwaysForceLocalize.boolValue, new GUIContent(" Force Localize", "Enable this when the translations have parameters (e.g. Thew winner is {[WINNER}]) to prevent any optimization that could prevent updating the translation when the object is enabled"));
                //}
                //GUILayout.EndHorizontal();

                //--[ Right To Left ]-------------
                if (!mLocalize.IgnoreRTL && mLocalize.Term != "-" && termData != null && termData.TermType == eTermType.Text)
                {
                    GUILayout.BeginVertical("Box");
                    //GUILayout.BeginHorizontal();
                    //    mProp_IgnoreRTL.boolValue = GUILayout.Toggle(mProp_IgnoreRTL.boolValue, new GUIContent(" Ignore Right To Left", "Arabic and other RTL languages require processing them so they render correctly, this toogle allows ignoring that processing (in case you are doing it manually during a callback)"));
                    //    GUILayout.FlexibleSpace();
                    //    mProp_SeparateWords.boolValue = GUILayout.Toggle(mProp_SeparateWords.boolValue, new GUIContent(" Separate Words", " Some languages (e.g. Chinese, Japanese and Thai) don't add spaces to their words (all characters are placed toguether), enabling this checkbox, will add spaces to all characters to allow wrapping long texts into multiple lines."));
                    //GUILayout.EndHorizontal();
                    {
                        mProp_MaxCharactersInRTL.intValue = EditorGUILayout.IntField(new GUIContent("Max line length", "If the language is Right To Left, long lines will be split at this length and the RTL fix will be applied to each line, this should be set to the maximum number of characters that fit in this text width. 0 disables the per line fix"), mProp_MaxCharactersInRTL.intValue);
                        GUILayout.BeginHorizontal();
                        mProp_CorrectAlignmentForRTL.boolValue = GUILayout.Toggle(mProp_CorrectAlignmentForRTL.boolValue, new GUIContent(" Adjust Alignment", "Right-align when Right-To-Left Language, and Left-Align otherwise"));
                        GUILayout.FlexibleSpace();
                        mProp_IgnoreNumbersInRTL.boolValue = GUILayout.Toggle(mProp_IgnoreNumbersInRTL.boolValue, new GUIContent(" Ignore Numbers", "Preserve numbers as latin characters instead of converting them"));
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.EndVertical();
                }


                ////GUILayout.EndHorizontal();
            }
        }
Пример #15
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)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(source.mLanguages[i].Name, GUILayout.Width(100));

                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 = 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 &&
                        (GUI.changed || (GUI.GetNameOfFocusedControl() == CtrName && IsSelect)))
                    {
                        if (IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.Term))
                        {
                            localizeCmp.Term = Key;
                            EditorUtility.SetDirty(localizeCmp);
                        }

                        if (!IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.SecondaryTerm))
                        {
                            localizeCmp.SecondaryTerm = Key;
                            EditorUtility.SetDirty(localizeCmp);
                        }

                        string PreviousLanguage = LocalizationManager.CurrentLanguage;
                        LocalizationManager.PreviewLanguage(source.mLanguages[i].Name);
                        localizeCmp.OnLocalize(true);
                        LocalizationManager.PreviewLanguage(PreviousLanguage);
                    }
                    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 ? 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;

#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

                    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)
                    {
                        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();
            }
        }
Пример #16
0
        bool OnGUI_SelectKey(ref string Term, bool Inherited)            // Inherited==true means that the mTerm is empty and we are using the Label.text instead
        {
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();

            GUI.changed       = false;
            mAllowEditKeyName = GUILayout.Toggle(mAllowEditKeyName, "Term:", EditorStyles.foldout, GUILayout.ExpandWidth(false));
            if (GUI.changed && mAllowEditKeyName)
            {
                mNewKeyName = Term;
                mTermsArray = null;
            }

            bool bChanged = false;

            if (mTermsArray == null || (Term != "-" && System.Array.IndexOf(mTermsArray, Term) < 0))
            {
                UpdateTermsList(Term);
            }

            if (Inherited)
            {
                GUI.contentColor = Color.Lerp(Color.gray, Color.yellow, 0.1f);
            }

            int Index = (Term == "-" || Term == "") ? mTermsArray.Length - 1 : System.Array.IndexOf(mTermsArray, Term);

            GUI.changed = false;

            int newIndex = EditorGUILayout.Popup(Index, mTermsArray);

            GUI.contentColor = Color.white;
            if (/*newIndex != Index && newIndex>=0*/ GUI.changed)
            {
                GUI.changed = false;
                if (mLocalize.Source != null && newIndex == mTermsArray.Length - 4)  //< show terms from all sources >
                {
                    mLocalize.Source = null;
                    mTermsArray      = null;
                }
                else
                if (newIndex == mTermsArray.Length - 2)  //<inferred from text>
                {
                    mNewKeyName = Term = string.Empty;
                }
                else
                if (newIndex == mTermsArray.Length - 1)  //<none>
                {
                    mNewKeyName = Term = "-";
                }
                else
                {
                    mNewKeyName = Term = mTermsArray[newIndex];
                }


                if (GUI_SelectedTerm == 0)
                {
                    mLocalize.SetTerm(mNewKeyName);
                }
                else
                {
                    mLocalize.SetTerm(null, mNewKeyName);
                }
                mAllowEditKeyName = false;
                bChanged          = true;
            }

            LanguageSourceData source   = LocalizationManager.GetSourceContaining(Term);
            TermData           termData = source.GetTermData(Term);

            if (termData != null)
            {
                if (Inherited)
                {
                    bChanged = true;                     // if the term its inferred and a matching term its found, then use that
                }
                eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termData.TermType, GUILayout.Width(90));
                if (termData.TermType != NewType)
                {
                    termData.TermType = NewType;
                }
            }

            GUILayout.EndHorizontal();

            if (mAllowEditKeyName)
            {
                GUILayout.BeginHorizontal(GUILayout.Height(1));
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (mNewKeyName == null)
                {
                    mNewKeyName = string.Empty;
                }

                GUI.changed = false;
                mNewKeyName = EditorGUILayout.TextField(mNewKeyName, new GUIStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true));
                if (GUI.changed)
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    GUI.changed = false;
                }

                if (GUILayout.Button(string.Empty, string.IsNullOrEmpty(mNewKeyName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth(false)))
                {
                    mTermsArray = null;                         // regenerate this array to apply filtering
                    mNewKeyName = string.Empty;
                }

                GUILayout.EndHorizontal();

                string ValidatedName = mNewKeyName;
                LanguageSourceData.ValidateFullTerm(ref ValidatedName);

                bool CanUseNewName = (source.GetTermData(ValidatedName) == null);
                GUI.enabled = (!string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button("Create", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName = ValidatedName;
                    mTermsArray = null;                         // this recreates that terms array

                    LanguageSourceData Source = null;
                                        #if UNITY_EDITOR
                    if (mLocalize.Source != null)
                    {
                        Source = mLocalize.Source.mSource;
                    }
                                        #endif

                    if (Source == null)
                    {
                        Source = LocalizationManager.Sources[0];
                    }
                    Term = mNewKeyName;
                    var data = Source.AddTerm(mNewKeyName, eTermType.Text, false);
                    if (data.Languages.Length > 0)
                    {
                        data.Languages[0] = mLocalize.GetMainTargetsText();
                    }
                    EditorUtility.SetDirty(Source.owner);
                    AssetDatabase.SaveAssets();
                    mAllowEditKeyName          = false;
                    bChanged                   = true;
                    GUIUtility.keyboardControl = 0;
                }
                GUI.enabled = (termData != null && !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName);
                if (GUILayout.Button(new GUIContent("Rename", "Renames the term in the source and updates every object using it in the current scene"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    mNewKeyName       = ValidatedName;
                    Term              = mNewKeyName;
                    mTermsArray       = null;                 // this recreates that terms array
                    mAllowEditKeyName = false;
                    bChanged          = true;
                    LocalizationEditor.TermReplacements = new Dictionary <string, string>(System.StringComparer.Ordinal);
                    LocalizationEditor.TermReplacements[termData.Term] = mNewKeyName;
                    termData.Term = mNewKeyName;
                    source.UpdateDictionary(true);
                    LocalizationEditor.ReplaceTermsInCurrentScene();
                    GUIUtility.keyboardControl = 0;
                    EditorApplication.update  += LocalizationEditor.DoParseTermsInCurrentScene;
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                bChanged |= OnGUI_SelectKey_PreviewTerms(ref Term);
            }

            GUILayout.Space(5);
            return(bChanged);
        }
Пример #17
0
        public string Import_CSV(string Category, List <string[]> CSV, eSpreadsheetUpdateMode UpdateMode = eSpreadsheetUpdateMode.Replace)
        {
            string[] Tokens = CSV[0];

            int LanguagesStartIdx = 1;
            int TypeColumnIdx     = -1;
            int DescColumnIdx     = -1;

            var ValidColumnName_Key  = new string[] { "Key" };
            var ValidColumnName_Type = new string[] { "Type" };
            var ValidColumnName_Desc = new string[] { "Desc", "Description" };

            if (Tokens.Length > 1 && ArrayContains(Tokens[0], ValidColumnName_Key))
            {
                if (UpdateMode == eSpreadsheetUpdateMode.Replace)
                {
                    ClearAllData();
                }

                if (Tokens.Length > 2)
                {
                    if (ArrayContains(Tokens[1], ValidColumnName_Type))
                    {
                        TypeColumnIdx     = 1;
                        LanguagesStartIdx = 2;
                    }
                    if (ArrayContains(Tokens[1], ValidColumnName_Desc))
                    {
                        DescColumnIdx     = 1;
                        LanguagesStartIdx = 2;
                    }
                }
                if (Tokens.Length > 3)
                {
                    if (ArrayContains(Tokens[2], ValidColumnName_Type))
                    {
                        TypeColumnIdx     = 2;
                        LanguagesStartIdx = 3;
                    }
                    if (ArrayContains(Tokens[2], ValidColumnName_Desc))
                    {
                        DescColumnIdx     = 2;
                        LanguagesStartIdx = 3;
                    }
                }
            }
            else
            {
                return("Bad Spreadsheet Format.\nFirst columns should be 'Key', 'Type' and 'Desc'");
            }

            int nLanguages = Mathf.Max(Tokens.Length - LanguagesStartIdx, 0);

            int[] LanIndices = new int[nLanguages];
            for (int i = 0; i < nLanguages; ++i)
            {
                if (string.IsNullOrEmpty(Tokens[i + LanguagesStartIdx]))
                {
                    LanIndices [i] = -1;
                    continue;
                }

                string langToken = Tokens[i + LanguagesStartIdx];

                string LanName, LanCode;
                bool   isLangEnabled = true;
                if (langToken.StartsWith("$"))
                {
                    isLangEnabled = false;
                    langToken     = langToken.Substring(1);
                }
                GoogleLanguages.UnPackCodeFromLanguageName(langToken, out LanName, out LanCode);

                int LanIdx = -1;
                if (!string.IsNullOrEmpty(LanCode))
                {
                    LanIdx = GetLanguageIndexFromCode(LanCode);
                }
                else
                {
                    LanIdx = GetLanguageIndex(LanName, SkipDisabled: false);
                }

                if (LanIdx < 0)
                {
                    LanguageData lanData = new LanguageData();
                    lanData.Name  = LanName;
                    lanData.Code  = LanCode;
                    lanData.Flags = (byte)(0 | (isLangEnabled?0:(int)eLanguageDataFlags.DISABLED));
                    mLanguages.Add(lanData);
                    LanIdx = mLanguages.Count - 1;
                }
                LanIndices[i] = LanIdx;
            }

            //--[ Update the Languages array in the existing terms]-----
            nLanguages = mLanguages.Count;
            for (int i = 0, imax = mTerms.Count; i < imax; ++i)
            {
                TermData termData = mTerms[i];
                if (termData.Languages.Length < nLanguages)
                {
                    Array.Resize(ref termData.Languages, nLanguages);
                    Array.Resize(ref termData.Flags, nLanguages);
                }
            }

            //--[ Keys ]--------------

            for (int i = 1, imax = CSV.Count; i < imax; ++i)
            {
                Tokens = CSV[i];
                string sKey = string.IsNullOrEmpty(Category) ? Tokens[0] : string.Concat(Category, "/", Tokens[0]);

                string specialization = null;
                if (sKey.EndsWith("]"))
                {
                    int idx = sKey.LastIndexOf('[');
                    if (idx > 0)
                    {
                        specialization = sKey.Substring(idx + 1, sKey.Length - idx - 2);
                        if (specialization == "touch")
                        {
                            specialization = "Touch";
                        }
                        sKey = sKey.Remove(idx);
                    }
                }
                ValidateFullTerm(ref sKey);
                if (string.IsNullOrEmpty(sKey))
                {
                    continue;
                }

                TermData termData = GetTermData(sKey);

                // Check to see if its a new term
                if (termData == null)
                {
                    termData      = new TermData();
                    termData.Term = sKey;

                    termData.Languages = new string[mLanguages.Count];
                    termData.Flags     = new byte[mLanguages.Count];
                    for (int j = 0; j < mLanguages.Count; ++j)
                    {
                        termData.Languages[j] = string.Empty;
                    }

                    mTerms.Add(termData);
                    mDictionary.Add(sKey, termData);
                }
                else
                // This term already exist
                if (UpdateMode == eSpreadsheetUpdateMode.AddNewTerms)
                {
                    continue;
                }

                if (TypeColumnIdx > 0)
                {
                    termData.TermType = GetTermType(Tokens[TypeColumnIdx]);
                }

                if (DescColumnIdx > 0)
                {
                    termData.Description = Tokens[DescColumnIdx];
                }

                for (int j = 0; j < LanIndices.Length && j < Tokens.Length - LanguagesStartIdx; ++j)
                {
                    if (!string.IsNullOrEmpty(Tokens[j + LanguagesStartIdx]))   // Only change the translation if there is a new value
                    {
                        var lanIdx = LanIndices[j];
                        if (lanIdx < 0)
                        {
                            continue;
                        }
                        var value = Tokens[j + LanguagesStartIdx];

                        if (value == "-")
                        {
                            value = string.Empty;
                        }
                        else
                        if (value == "")
                        {
                            value = null;
                        }

                        termData.SetTranslation(lanIdx, value, specialization);
                    }
                }
            }

            return(string.Empty);
        }