Skip to content

Commit f688184

Browse files
committed
fix:
1 parent 41673b7 commit f688184

File tree

63 files changed

+4651
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4651
-0
lines changed

Assets/PackageLocale/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/PackageLocale/Editor/Icons.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1.29 KB
Loading

Assets/PackageLocale/Editor/Icons/translate.png.meta

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#if UNITY_EDITOR
2+
using SimpleLocalization.Runtime;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace OPAGames.SimpleLocalization.Editor
7+
{
8+
[InitializeOnLoad]
9+
public static class LocalizationEditorHelper
10+
{
11+
static LocalizationEditorHelper()
12+
{
13+
EditorApplication.playModeStateChanged += ApplyLanguageBeforePlay;
14+
}
15+
16+
private static void ApplyLanguageBeforePlay(PlayModeStateChange state)
17+
{
18+
if (state != PlayModeStateChange.EnteredPlayMode) return;
19+
var forceLanguage = EditorPrefs.GetBool("FineLocalization_UseEditorLanguage", false);
20+
if (!forceLanguage) return;
21+
var lang = EditorPrefs.GetString("FineLocalization_SelectedLanguage", "en-us");
22+
LocalizationManager.Language = lang;
23+
Debug.Log($"[Fine Localization] Force Language To: {lang} in Editor.");
24+
}
25+
}
26+
}
27+
#endif

Assets/PackageLocale/Editor/LocalizationEditorHelper.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/PackageLocale/Editor/Menu.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using SimpleLocalization.Runtime;
5+
using UnityEditor;
6+
using UnityEditor.Overlays;
7+
using UnityEngine;
8+
using UnityEngine.UIElements;
9+
10+
namespace OPAGames.SimpleLocalization.Editor.Menu
11+
{
12+
[Overlay(typeof(SceneView), "Fine Localization", true), Icon("Assets/SimpleLocalization/Editor/Icons/translate.png")]
13+
public class LocalizationOverlay : Overlay
14+
{
15+
private Texture icon { get; set; }
16+
private Texture2D _icon;
17+
18+
public override VisualElement CreatePanelContent()
19+
{
20+
var root = new VisualElement();
21+
22+
if (LocalizationManager.Dictionary.Count == 0)
23+
LocalizationManager.Read();
24+
25+
var langs = new List<string>(LocalizationManager.Dictionary.Keys
26+
.Where(k => !string.Equals(k, "KEY", StringComparison.OrdinalIgnoreCase)));
27+
var popupField = new PopupField<string>("Idioma", langs, LocalizationManager.Language);
28+
29+
popupField.style.minWidth = 160;
30+
root.Add(popupField);
31+
32+
var useEditorLanguage = EditorPrefs.GetBool("FineLocalization_UseEditorLanguage", false);
33+
popupField.SetEnabled(useEditorLanguage);
34+
35+
var toggle = new Toggle("Forçar linguagem do Editor") { value = useEditorLanguage };
36+
toggle.RegisterValueChangedCallback(evt =>
37+
{
38+
EditorPrefs.SetBool("FineLocalization_UseEditorLanguage", evt.newValue);
39+
popupField.SetEnabled(evt.newValue);
40+
});
41+
42+
root.Insert(0, toggle);
43+
44+
popupField.RegisterValueChangedCallback(evt =>
45+
{
46+
LocalizationManager.Language = evt.newValue;
47+
EditorPrefs.SetString("FineLocalization_SelectedLanguage", evt.newValue);
48+
});
49+
50+
return root;
51+
}
52+
53+
public override void OnCreated()
54+
{
55+
_icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/SimpleLocalization/Editor/Icons/translate.png");
56+
57+
if (_icon != null)
58+
{
59+
icon = _icon;
60+
}
61+
else
62+
{
63+
Debug.LogWarning("[Fine Localization] Ícone não encontrado.");
64+
}
65+
}
66+
}
67+
}

Assets/PackageLocale/Editor/Menu/LocalizationOverlay.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using SimpleLocalization.Runtime;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace SimpleLocalization.Scripts.Editor.Menu
6+
{
7+
public class LocalizationSettingsWindow : EditorWindow
8+
{
9+
[MenuItem("Tools/SimpleLocalization/Settings")]
10+
public static void ShowWindow()
11+
{
12+
GetWindow<LocalizationSettingsWindow>("Localization Settings");
13+
}
14+
15+
private void OnGUI()
16+
{
17+
GUILayout.Label("Configuração de Linguagem", EditorStyles.boldLabel);
18+
19+
if (LocalizationManager.Dictionary.Count == 0)
20+
LocalizationManager.Read();
21+
22+
var langs = new System.Collections.Generic.List<string>(LocalizationManager.Dictionary.Keys);
23+
var index = langs.IndexOf(LocalizationManager.Language);
24+
var newIndex = EditorGUILayout.Popup("Idioma atual", index, langs.ToArray());
25+
26+
if (newIndex != index)
27+
LocalizationManager.Language = langs[newIndex];
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)