private void DrawEntry(LeanPhrase.Entry entry, bool unexpected) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(entry.Language, EditorStyles.boldLabel); if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(55.0f)) == true) { Undo.RecordObject(Target, "Remove Translation"); Target.RemoveTranslation(entry.Language); Dirty(); } EditorGUILayout.EndHorizontal(); if (unexpected == true) { EditorGUILayout.HelpBox("Your LeanLocalization component doesn't define the " + entry.Language + " language.", MessageType.Warning); } Undo.RecordObject(Target, "Modified Translation"); EditorGUI.BeginChangeCheck(); switch (Target.Data) { case LeanPhrase.DataType.Text: if (entry.Language.ToLower().Equals("inversedarabic")) { if (!string.IsNullOrEmpty(entry.Text)) { fixedArabic = ArabicFixer.Fix(entry.Text, false, false); } } if (entry.Language.ToLower().Equals("arabic")) { if (!string.IsNullOrEmpty(fixedArabic)) { entry.Text = fixedArabic; } } entry.Text = EditorGUILayout.TextArea(entry.Text ?? "", GUILayout.MinHeight(40.0f)); break; case LeanPhrase.DataType.Object: entry.Object = EditorGUILayout.ObjectField(entry.Object, typeof(Object), true); break; case LeanPhrase.DataType.Sprite: entry.Object = EditorGUILayout.ObjectField(entry.Object, typeof(Sprite), true); break; } if (EditorGUI.EndChangeCheck() == true) { Dirty(); LeanLocalization.UpdateTranslations(); } EditorGUILayout.Separator(); }
private void DrawTranslation(LeanTranslation translation, bool unexpected) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(translation.Language, EditorStyles.boldLabel); if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(55.0f)) == true) { Undo.RecordObject(Target, "Remove Translation"); Target.RemoveTranslation(translation.Language); Dirty(); } EditorGUILayout.EndHorizontal(); if (unexpected == true) { EditorGUILayout.HelpBox("Your LeanLocalization component doesn't define the " + translation.Language + " language.", MessageType.Warning); } Undo.RecordObject(Target, "Modified Translation"); EditorGUI.BeginChangeCheck(); translation.Object = EditorGUILayout.ObjectField(translation.Object, typeof(Object), true); translation.Text = EditorGUILayout.TextArea(translation.Text ?? "", GUILayout.MinHeight(40.0f)); if (EditorGUI.EndChangeCheck() == true) { Dirty(); LeanLocalization.UpdateTranslations(); } EditorGUILayout.Separator(); }
public void LoadFromSource() { if (Source != null && string.IsNullOrEmpty(Language) == false) { for (var i = Entries.Count - 1; i >= 0; i--) // NOTE: Property { entryPool.Push(entries[i]); } entries.Clear(); // Split file into lines, and loop through them all var lines = Source.text.Split(newlineCharacters, System.StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < lines.Length; i++) { var line = lines[i]; var equalsIndex = line.IndexOf(Separator); // Only consider lines with the Separator character if (equalsIndex != -1) { var name = line.Substring(0, equalsIndex).Trim(); var text = line.Substring(equalsIndex + Separator.Length).Trim(); // Does this entry have a comment? if (string.IsNullOrEmpty(Comment) == false) { var commentIndex = text.LastIndexOf(Comment); if (commentIndex != -1) { text = text.Substring(0, commentIndex).Trim(); } } // Replace newline markers with actual newlines if (string.IsNullOrEmpty(NewLine) == false) { text = text.Replace(NewLine, System.Environment.NewLine); } var entry = entryPool.Count > 0 ? entryPool.Pop() : new Entry(); entry.Name = name; entry.Text = text; entries.Add(entry); } } // Update translations? if (LeanLocalization.CurrentLanguage == Language) { LeanLocalization.UpdateTranslations(); } } }
public void Clear() { if (entries != null) { entries.Clear(); // Update translations? if (LeanLocalization.CurrentLanguage == Language) { LeanLocalization.UpdateTranslations(); } } }
public void LoadFromSource() { if (Source != null && string.IsNullOrEmpty(Language) == false) { // Split file into lines, and loop through them all var lines = Source.text.Split(newlineCharacters, System.StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < lines.Length; i++) { var line = lines[i]; var equalsIndex = line.IndexOf(Separator); // Only consider lines with the Separator character if (equalsIndex != -1) { var title = line.Substring(0, equalsIndex).Trim(); var text = line.Substring(equalsIndex + Separator.Length).Trim(); // Does this entry have a comment? if (string.IsNullOrEmpty(Comment) == false) { var commentIndex = text.LastIndexOf(Comment); if (commentIndex != -1) { text = text.Substring(0, commentIndex).Trim(); } } // Replace newline markers with actual newlines if (string.IsNullOrEmpty(NewLine) == false) { text = text.Replace(NewLine, System.Environment.NewLine); } // Find or add the translation for this phrase LeanLocalization.AddTranslationToFirst(title, Language, text); } } // Update translations? if (LeanLocalization.CurrentLanguage == Language) { LeanLocalization.UpdateTranslations(); } } }
private void DrawEntry(LeanPhrase.Entry entry, bool unexpected) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(entry.Language, EditorStyles.boldLabel); if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(55.0f)) == true) { Undo.RecordObject(tgt, "Remove Translation"); tgt.RemoveTranslation(entry.Language); Dirty(); } EditorGUILayout.EndHorizontal(); if (unexpected == true) { EditorGUILayout.HelpBox("Your LeanLocalization component doesn't define the " + entry.Language + " language.", MessageType.Warning); } Undo.RecordObject(tgt, "Modified Translation"); EditorGUI.BeginChangeCheck(); switch (tgt.Data) { case LeanPhrase.DataType.Text: entry.Text = EditorGUILayout.TextArea(entry.Text ?? "", GUILayout.MinHeight(40.0f)); break; case LeanPhrase.DataType.Object: entry.Object = EditorGUILayout.ObjectField(entry.Object, typeof(Object), true); break; case LeanPhrase.DataType.Sprite: entry.Object = EditorGUILayout.ObjectField(entry.Object, typeof(Sprite), true); break; } if (EditorGUI.EndChangeCheck() == true) { Dirty(); LeanLocalization.UpdateTranslations(); } EditorGUILayout.Separator(); }
public void LoadFromSource() { if (Source != null && string.IsNullOrEmpty(Language) == false) { DoLoadFromSource(); // Update translations? foreach (var localization in LeanLocalization.Instances) { if (localization.CurrentLanguage == Language) { LeanLocalization.UpdateTranslations(); break; } } } }
public void Clear() { if (entries != null) { DoClear(); // Update translations? foreach (var localization in LeanLocalization.Instances) { if (localization.CurrentLanguage == Language) { LeanLocalization.UpdateTranslations(); break; } } } }
// Draw the whole inspector public override void OnInspectorGUI() { var localization = (LeanLocalization)target; Validate(localization); EditorGUILayout.Separator(); DrawCurrentLanguage(); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(serializedObject.FindProperty("DefaultLanguage")); EditorGUILayout.PropertyField(serializedObject.FindProperty("DetectLanguage")); EditorGUILayout.PropertyField(serializedObject.FindProperty("SaveLanguage")); EditorGUILayout.Separator(); DrawLanguages(localization); EditorGUILayout.Separator(); EditorGUILayout.Separator(); DrawCultures(localization); EditorGUILayout.Separator(); EditorGUILayout.Separator(); DrawPhrases(localization); EditorGUILayout.Separator(); // Update if dirty? if (serializedObject.ApplyModifiedProperties() == true || dirty == true) { dirty = false; LeanLocalization.UpdateTranslations(); SetDirty(localization); } }
public void LoadFromSource() { if (Source != null && string.IsNullOrEmpty(SourceLanguage) == false) { var localization = GetComponent <LeanLocalization>(); var lines = Source.text.Split(newlineCharacters, System.StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var equalsIndex = line.IndexOf('='); if (equalsIndex != -1) { var phraseName = line.Substring(0, equalsIndex).Trim(); var phraseTranslation = line.Substring(equalsIndex + 1).Trim(); // Replace line markers with actual newlines phraseTranslation = phraseTranslation.Replace(newlineString, System.Environment.NewLine); // Does this entry have a comment? var commentIndex = phraseTranslation.IndexOf("//"); if (commentIndex != -1) { phraseTranslation = phraseTranslation.Substring(0, commentIndex).Trim(); } // Find or add the translation for this phrase var translation = localization.AddTranslation(SourceLanguage, phraseName); // Set the translation text for this phrase translation.Text = phraseTranslation; } } // Update translations? if (LeanLocalization.CurrentLanguage == SourceLanguage) { LeanLocalization.UpdateTranslations(); } } }
public void LoadFromSource() { if (Source != null) { var target = Target; // Automatically get first LeanLocalization? if (target == null && LeanLocalization.AllLocalizations.Count > 0) { target = LeanLocalization.AllLocalizations[0]; } // Create a new LeanLocalization? if (target == null) { target = new GameObject("LeanLocalization").AddComponent <LeanLocalization>(); } // Split file by line and loop through them all var lines = Source.text.Split(newlineCharacters, System.StringSplitOptions.RemoveEmptyEntries); var updateLanguage = false; for (var i = 0; i < lines.Length; i++) { var line = lines[i]; var equalsIndex = line.IndexOf(Separator); if (equalsIndex != -1) { var lineLeft = line.Substring(0, equalsIndex).Trim(); var colonIndex = lineLeft.IndexOf(Language); if (colonIndex != -1) { var phraseName = lineLeft.Substring(0, colonIndex).Trim(); var languageName = lineLeft.Substring(colonIndex + Language.Length).Trim(); var phraseTranslation = line.Substring(equalsIndex + Separator.Length).Trim(); // Replace newline markers with actual newlines if (string.IsNullOrEmpty(NewLine) == false) { phraseTranslation = phraseTranslation.Replace(NewLine, System.Environment.NewLine); } // Does this entry have a comment? if (string.IsNullOrEmpty(Comment) == false) { var commentIndex = phraseTranslation.LastIndexOf(Comment); if (commentIndex != -1) { phraseTranslation = phraseTranslation.Substring(0, commentIndex).Trim(); } } // Find or add the translation for this phrase var translation = target.AddTranslation(languageName, phraseName); // Set the translation text for this phrase translation.Text = phraseTranslation; // Update translations later? if (LeanLocalization.CurrentLanguage == languageName) { updateLanguage = true; } } } } // Update translations? if (updateLanguage == true) { LeanLocalization.UpdateTranslations(); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var left = position; left.xMax -= 40; var right = position; right.xMin = left.xMax + 2; var color = GUI.color; var exists = LeanLocalization.CurrentTranslations.ContainsKey(property.stringValue); if (exists == false) { GUI.color = Color.red; } EditorGUI.PropertyField(left, property); GUI.color = color; if (GUI.Button(right, "List") == true) { var menu = new GenericMenu(); if (string.IsNullOrEmpty(property.stringValue) == false) { if (exists == true) { var translation = default(LeanTranslation); if (LeanLocalization.CurrentTranslations.TryGetValue(property.stringValue, out translation) == true) { foreach (var entry in translation.Entries) { var owner = entry.Owner; menu.AddItem(new GUIContent("Select/" + entry.Language), false, () => { Selection.activeObject = owner; EditorGUIUtility.PingObject(owner); }); } } } else { menu.AddItem(new GUIContent("Add: " + property.stringValue.Replace('/', '\\')), false, () => { var phrase = LeanLocalization.AddPhraseToFirst(property.stringValue); LeanLocalization.UpdateTranslations(); Selection.activeObject = phrase; EditorGUIUtility.PingObject(phrase); }); } menu.AddItem(GUIContent.none, false, null); } foreach (var translationName in LeanLocalization.CurrentTranslations.Keys) { menu.AddItem(new GUIContent(translationName), property.stringValue == translationName, () => { property.stringValue = translationName; property.serializedObject.ApplyModifiedProperties(); }); } if (menu.GetItemCount() > 0) { menu.DropDown(right); } else { Debug.LogWarning("Your scene doesn't contain any phrases, so the phrase name list couldn't be created."); } } }