Skip to content

Commit f7e8b12

Browse files
committed
WIP: Add localization for MeshSimplifierOptions
1 parent 5d7e34d commit f7e8b12

File tree

11 files changed

+152
-1
lines changed

11 files changed

+152
-1
lines changed

Editor/Localization/Locales.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.

Editor/Localization/Locales/en.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"Language: en\n"
4+
5+
msgid "MeshSimplifierOptions:PreserveBorderEdges:label"
6+
msgstr "Preserve Border Edges"
7+
8+
msgid "MeshSimplifierOptions:PreserveBorderEdges:tooltip"
9+
msgstr "If you want to suppress hole generation during simplification, enable this option."
10+
11+
msgid "MeshSimplifierOptions:PreserveSurfaceCurvature:label"
12+
msgstr "Preserve Surface Curvature"
13+
14+
msgid "MeshSimplifierOptions:EnableSmartLink:label"
15+
msgstr "Enable Smart Link"
16+
17+
msgid "locale:en"
18+
msgstr "English"

Editor/Localization/Locales/en.po.meta

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

Editor/Localization/Locales/ja.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"Language: ja\n"
4+
5+
msgid "MeshSimplifierOptions:PreserveBorderEdges:label"
6+
msgstr "端の露出したポリゴンを保持"
7+
8+
msgid "MeshSimplifierOptions:PreserveBorderEdges:tooltip"
9+
msgstr "軽量化後のメッシュに穴が目立つとき、有効化してみてください。"
10+
11+
msgid "MeshSimplifierOptions:PreserveSurfaceCurvature:label"
12+
msgstr "曲面を保持"
13+
14+
msgid "MeshSimplifierOptions:EnableSmartLink:label"
15+
msgstr "近傍点をマージ候補に含める"
16+
17+
msgid "locale:ja"
18+
msgstr "日本語"

Editor/Localization/Locales/ja.po.meta

Lines changed: 7 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+
#nullable enable
2+
namespace Meshia.MeshSimplification.Editor.Localization
3+
{
4+
using CustomLocalization4EditorExtension;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using UnityEngine.UIElements;
9+
10+
internal static class LocalizationProvider
11+
{
12+
private const string DefaultLocale = "en";
13+
14+
[AssemblyCL4EELocalization]
15+
public static Localization Localization { get; } = new("ca7beb49d3e85244e803080472c014c2", DefaultLocale);
16+
static Dictionary<string, string> LocaleCodeToName { get; } = new()
17+
{
18+
{ "en", "English" },
19+
{ "ja", "“ú–{Œê" }
20+
};
21+
static Dictionary<string, string> LocaleNameToCode { get; } = LocaleCodeToName.ToDictionary(keyValue => keyValue.Value, keyValue => keyValue.Key);
22+
public static void LocalizeProperties<T>(VisualElement root)
23+
{
24+
var typeName = typeof(T).Name;
25+
root.Query().OfType<BindableElement>().Where(bindableElement => !string.IsNullOrEmpty(bindableElement.bindingPath))
26+
.ForEach(bindableElement =>
27+
{
28+
if (Localization.TryTr($"{typeName}:{bindableElement.bindingPath}:label") is { } translatedLabel)
29+
{
30+
switch (bindableElement)
31+
{
32+
case Toggle toggle:
33+
{
34+
toggle.label = translatedLabel;
35+
}
36+
break;
37+
case FloatField floatField:
38+
{
39+
floatField.label = translatedLabel;
40+
}
41+
break;
42+
case Slider slider:
43+
{
44+
slider.label = translatedLabel;
45+
}
46+
break;
47+
}
48+
}
49+
if (Localization.TryTr($"{typeName}:{bindableElement.bindingPath}:tooltip") is { } translatedTooltip)
50+
{
51+
bindableElement.tooltip = translatedTooltip;
52+
}
53+
});
54+
}
55+
public static DropdownField CreateLanguagePicker()
56+
{
57+
var choices = LocaleNameToCode.Keys.OrderBy(name => name).ToList();
58+
DropdownField languagePicker = new(choices, LocaleCodeToName[Localization.CurrentLocaleCode ?? DefaultLocale]);
59+
languagePicker.RegisterValueChangedCallback(changeEvent =>
60+
{
61+
Localization.CurrentLocaleCode = LocaleNameToCode[changeEvent.newValue];
62+
});
63+
return languagePicker;
64+
}
65+
}
66+
67+
}

Editor/Localization/LocalizationProvider.cs.meta

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

Editor/MeshSimplifierOptionsDrawer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#nullable enable
2+
using CustomLocalization4EditorExtension;
23
using Meshia.MeshSimplification;
4+
using Meshia.MeshSimplification.Editor.Localization;
35
using UnityEditor;
46
using UnityEditor.UIElements;
57
using UnityEngine;
@@ -16,7 +18,16 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
1618
var root = visualTreeAsset.CloneTree();
1719

1820
root.BindProperty(property);
21+
22+
var languagePicker = LocalizationProvider.CreateLanguagePicker();
23+
root.Q<VisualElement>("LanguagePickerContainer").Add(languagePicker);
24+
25+
languagePicker.RegisterValueChangedCallback(evt =>
26+
{
27+
LocalizationProvider.LocalizeProperties<MeshSimplifierOptions>(root);
28+
});
1929
var resetOptionsButton = root.Q<Button>("ResetOptionsButton");
30+
LocalizationProvider.LocalizeProperties<MeshSimplifierOptions>(root);
2031
resetOptionsButton.clicked += () =>
2132
{
2233
property.boxedValue = MeshSimplifierOptions.Default;

Editor/MeshSimplifierOptionsDrawer.uxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
2+
<ui:VisualElement name="LanguagePickerContainer" style="flex-grow: 1;" />
23
<ui:Toggle label="Preserve Border Edges" binding-path="PreserveBorderEdges" />
34
<ui:Toggle label="Preserve Surface Curvature" binding-path="PreserveSurfaceCurvature" />
45
<ui:Toggle label="Use Barycentric Coordinate Interpolation" binding-path="UseBarycentricCoordinateInterpolation" />
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using CustomLocalization4EditorExtension;
12
using System.Runtime.CompilerServices;
23

34
[assembly: InternalsVisibleTo("Meshia.MeshSimplification.Editor")]
45
[assembly: InternalsVisibleTo("Meshia.MeshSimplification.Ndmf.Runtime")]
5-
[assembly: InternalsVisibleTo("Meshia.MeshSimplification.Ndmf.Editor")]
6+
[assembly: InternalsVisibleTo("Meshia.MeshSimplification.Ndmf.Editor")]
7+
8+
[assembly: RedirectCL4EEInstance("Meshia.MeshSimplification.Editor")]

0 commit comments

Comments
 (0)