A game about forced loneliness, made by TACStudios
1using System;
2using UnityEditor.UIElements;
3using UnityEngine.UIElements;
4
5namespace UnityEditor.Rendering.Utilities
6{
7 // Temporary helper class duplicated from GraphicsSettingsUtils.cs while better UXML localization support is not available.
8 internal class LocalizationHelper
9 {
10 static void Localize(VisualElement visualElement, Func<VisualElement, string> get, Action<VisualElement, string> set)
11 {
12 var extractedText = get.Invoke(visualElement);
13 if (string.IsNullOrWhiteSpace(extractedText))
14 return;
15
16 var localizedString = L10n.Tr(extractedText);
17 set.Invoke(visualElement, localizedString);
18 }
19
20 internal static void LocalizeTooltip(VisualElement visualElement)
21 {
22 Localize(visualElement, e => e.tooltip, (e, s) => e.tooltip = s);
23 }
24
25 internal static void LocalizeText(Label label)
26 {
27 Localize(label, e => ((Label)e).text, (e, s) => ((Label)e).text = s);
28 }
29
30 internal static void LocalizePropertyField(PropertyField propertyField)
31 {
32 Localize(propertyField, e => ((PropertyField)e).label, (e, s) => ((PropertyField)e).label = s);
33 }
34
35 internal static void LocalizeVisualTree(VisualElement root)
36 {
37 root.Query<VisualElement>().ForEach(LocalizeTooltip);
38 root.Query<PropertyField>().ForEach(LocalizePropertyField);
39 root.Query<Label>().ForEach(label =>
40 {
41 if (label.ClassListContains("unity-object-field-display__label"))
42 return;
43 LocalizeText(label);
44 });
45 }
46 }
47}