This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
LocalizationManager.cs
198 lines (168 loc) · 6.26 KB
/
LocalizationManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.ResourceManagement.AsyncOperations;
public class LocalizationManager : MonoBehaviour
{
// alphabetized for sorting to enum index check
public enum SupportedLanguages
{
ChineseSimplified,
Dutch,
English,
French,
German,
Hindi,
Italian,
Japanese,
Korean,
Portuguese,
Russian,
Spanish
}
public SupportedLanguages CurrentLocalizedLanguage;
const string k_ReasonUxTable = "ReasonsUX";
const string k_InitializeKey = "INIT";
const string k_MotionKey = "MOTION";
const string k_LightKey = "LIGHT";
const string k_FeaturesKey = "FEATURES";
const string k_UnsupportedKey = "UNSUPPORTED";
const string k_NoneKey = "NONE";
const string k_MoveDeviceKey = "MOVE_DEVICE";
const string k_TapToPlaceKey = "TAP_TO_PLACE";
const string k_BodyKey = "FIND_BODY";
const string k_FaceKey = "FIND_FACE";
const string k_ImageKey = "FIND_IMAGE";
const string k_ObjectKey = "FIND_OBJECT";
public string localizedInit;
public string localizedMotion;
public string localizedLight;
public string localizedFeatures;
public string localizedUnsupported;
public string localizedNone;
public string localizedMoveDevice;
public string localizedTapToPlace;
public string localizedBody;
public string localizedFace;
public string localizedImage;
public string localizedObject;
bool m_ReasonsComplete = false;
public bool localizationComplete => m_ReasonsComplete;
[SerializeField]
TMP_FontAsset m_SimplifiedChineseFont;
public TMP_FontAsset simplifiedChineseFont
{
get => m_SimplifiedChineseFont;
set => m_SimplifiedChineseFont = value;
}
[SerializeField]
TMP_FontAsset m_JapaneseFont;
public TMP_FontAsset japaneseFont
{
get => m_JapaneseFont;
set => m_JapaneseFont = value;
}
[SerializeField]
TMP_FontAsset m_KoreanFont;
public TMP_FontAsset koreanFont
{
get => m_KoreanFont;
set => m_KoreanFont = value;
}
[SerializeField]
TMP_FontAsset m_HindiFont;
public TMP_FontAsset hindiFont
{
get => m_HindiFont;
set => m_HindiFont = value;
}
[SerializeField]
TMP_Text m_InstructionText;
public TMP_Text instructionText
{
get => m_InstructionText;
set => m_InstructionText = value;
}
[SerializeField]
TMP_Text m_ReasonText;
public TMP_Text reasonText
{
get => m_ReasonText;
set => m_ReasonText = value;
}
const int k_MaxAutoSizeSC = 70;
IEnumerator Start()
{
bool m_LocalizeAnimation = false;
bool m_LocalizeReasons = false;
if (TryGetComponent(out ARUXAnimationManager m_AnimationManager))
{
m_LocalizeAnimation = m_AnimationManager.localizeText;
}
if (TryGetComponent(out ARUXReasonsManager m_ReasonsManager))
{
m_LocalizeReasons = m_ReasonsManager.localizeText;
}
if (m_LocalizeAnimation || m_LocalizeReasons)
{
yield return LocalizationSettings.InitializationOperation;
LocalizationSettings.AvailableLocales.Locales.Sort();
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[(int)CurrentLocalizedLanguage];
SwapFonts(CurrentLocalizedLanguage);
LocalizationSettings.StringDatabase.GetTableAsync(k_ReasonUxTable).Completed += OnCompletedReasonsUX;
}
}
void OnCompletedReasonsUX(AsyncOperationHandle<StringTable> obj)
{
if (obj.Status == AsyncOperationStatus.Succeeded)
{
var reasonsTable = obj.Result;
localizedInit = reasonsTable.GetEntry(k_InitializeKey).GetLocalizedString();
localizedMotion = reasonsTable.GetEntry(k_MotionKey).GetLocalizedString();
localizedLight = reasonsTable.GetEntry(k_LightKey).GetLocalizedString();
localizedFeatures = reasonsTable.GetEntry(k_FeaturesKey).GetLocalizedString();
localizedUnsupported = reasonsTable.GetEntry(k_UnsupportedKey).GetLocalizedString();
localizedNone = reasonsTable.GetEntry(k_NoneKey).GetLocalizedString();
localizedMoveDevice = reasonsTable.GetEntry(k_MoveDeviceKey).GetLocalizedString();
localizedTapToPlace = reasonsTable.GetEntry(k_TapToPlaceKey).GetLocalizedString();
localizedBody = reasonsTable.GetEntry(k_BodyKey).GetLocalizedString();
localizedFace = reasonsTable.GetEntry(k_FaceKey).GetLocalizedString();
localizedImage = reasonsTable.GetEntry(k_ImageKey).GetLocalizedString();
localizedObject = reasonsTable.GetEntry(k_ObjectKey).GetLocalizedString();
m_ReasonsComplete = true;
}
}
void SwapFonts(SupportedLanguages selectedLanguage)
{
TMP_FontAsset m_FontToSet = null;
// swap fonts for Simplified Chinese, Japanese, Korean, Tamil, Hindi and Telugu
switch (selectedLanguage)
{
case SupportedLanguages.ChineseSimplified:
m_FontToSet = m_SimplifiedChineseFont;
// custom size adjustment for legibility
m_InstructionText.fontSizeMax = k_MaxAutoSizeSC;
m_ReasonText.fontSizeMax = k_MaxAutoSizeSC;
break;
case SupportedLanguages.Japanese:
m_FontToSet = m_JapaneseFont;
break;
case SupportedLanguages.Korean:
m_FontToSet = m_KoreanFont;
break;
case SupportedLanguages.Hindi:
m_FontToSet = m_HindiFont;
break;
}
if (m_FontToSet != null)
{
m_InstructionText.font = m_FontToSet;
m_ReasonText.font = m_FontToSet;
}
}
}