Skip to content

Commit 9d980fb

Browse files
committed
Added language selection
1 parent 8ac2901 commit 9d980fb

File tree

13 files changed

+229
-6
lines changed

13 files changed

+229
-6
lines changed

Assets/AddressableAssetsData/AddressableAssetSettings.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ MonoBehaviour:
1515
m_DefaultGroup: e44b9e080d5ce064aa2fa777858a4f4d
1616
m_currentHash:
1717
serializedVersion: 2
18-
Hash: 00000000000000000000000000000000
18+
Hash: 176c8fbece2d7ca3cc835c9d3037f8d2
1919
m_OptimizeCatalogSize: 0
2020
m_BuildRemoteCatalog: 0
2121
m_CatalogRequestsTimeout: 0
@@ -60,6 +60,7 @@ MonoBehaviour:
6060
m_BuildAddressablesWithPlayerBuild: 0
6161
m_overridePlayerVersion: '[UnityEditor.PlayerSettings.bundleVersion]'
6262
m_GroupAssets:
63+
- {fileID: 11400000, guid: 076ecdf1095cf634b9d1ad0e46628cb9, type: 2}
6364
- {fileID: 11400000, guid: 1e8453572c1142e439fefd36fdc32edc, type: 2}
6465
- {fileID: 11400000, guid: 6ed67ed2b9fd82e4ea84b4d172aa92a1, type: 2}
6566
- {fileID: 11400000, guid: ef4f88f40627e5f4dbf786b246262c08, type: 2}

Assets/Localization/String Tables/Game Text Shared Data.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ MonoBehaviour:
135135
m_Key: BUTTON_PLAY_AGAIN
136136
m_Metadata:
137137
m_Items: []
138+
- m_Id: 36438190223360
139+
m_Key: LANGUAGE_ENGLISH
140+
m_Metadata:
141+
m_Items: []
142+
- m_Id: 36495383752704
143+
m_Key: LANGUAGE_ARABIC
144+
m_Metadata:
145+
m_Items: []
146+
- m_Id: 36529051430912
147+
m_Key: LANGUAGE_SPANISH
148+
m_Metadata:
149+
m_Items: []
150+
- m_Id: 36559753736192
151+
m_Key: LANGUAGE_JAPANESE
152+
m_Metadata:
153+
m_Items: []
154+
- m_Id: 36785994493952
155+
m_Key: SETTINGS_LANGUAGE
156+
m_Metadata:
157+
m_Items: []
138158
m_Metadata:
139159
m_Items: []
140160
m_KeyGenerator:

Assets/Localization/String Tables/Game Text_ar.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ MonoBehaviour:
141141
m_Localized: "\u0627\u0644\u0639\u0628 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649"
142142
m_Metadata:
143143
m_Items: []
144+
- m_Id: 36438190223360
145+
m_Localized: "\u0627\u0644\u0625\u0646\u062C\u0644\u064A\u0632\u064A\u0629"
146+
m_Metadata:
147+
m_Items: []
148+
- m_Id: 36495383752704
149+
m_Localized: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
150+
m_Metadata:
151+
m_Items: []
152+
- m_Id: 36529051430912
153+
m_Localized: "\u0627\u0644\u0625\u0633\u0628\u0627\u0646\u064A\u0629"
154+
m_Metadata:
155+
m_Items: []
156+
- m_Id: 36559753736192
157+
m_Localized: "\u0627\u0644\u064A\u0627\u0628\u0627\u0646\u064A\u0629"
158+
m_Metadata:
159+
m_Items: []
160+
- m_Id: 36785994493952
161+
m_Localized: "\u0627\u0644\u0644\u063A\u0629"
162+
m_Metadata:
163+
m_Items: []
144164
references:
145165
version: 2
146166
RefIds: []

Assets/Localization/String Tables/Game Text_en.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ MonoBehaviour:
138138
m_Localized: Gameplay
139139
m_Metadata:
140140
m_Items: []
141+
- m_Id: 36438190223360
142+
m_Localized: English
143+
m_Metadata:
144+
m_Items: []
145+
- m_Id: 36495383752704
146+
m_Localized: Arabic
147+
m_Metadata:
148+
m_Items: []
149+
- m_Id: 36529051430912
150+
m_Localized: Spanish
151+
m_Metadata:
152+
m_Items: []
153+
- m_Id: 36559753736192
154+
m_Localized: Japanese
155+
m_Metadata:
156+
m_Items: []
157+
- m_Id: 36785994493952
158+
m_Localized: Language
159+
m_Metadata:
160+
m_Items: []
141161
references:
142162
version: 2
143163
RefIds: []

Assets/Localization/String Tables/Game Text_es.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ MonoBehaviour:
138138
m_Localized: Jugar de Nuevo
139139
m_Metadata:
140140
m_Items: []
141+
- m_Id: 36438190223360
142+
m_Localized: "Ingl\xE9s"
143+
m_Metadata:
144+
m_Items: []
145+
- m_Id: 36495383752704
146+
m_Localized: "\xC1rabe"
147+
m_Metadata:
148+
m_Items: []
149+
- m_Id: 36529051430912
150+
m_Localized: "Espa\xF1ol"
151+
m_Metadata:
152+
m_Items: []
153+
- m_Id: 36559753736192
154+
m_Localized: "Japon\xE9s"
155+
m_Metadata:
156+
m_Items: []
157+
- m_Id: 36785994493952
158+
m_Localized: Idioma
159+
m_Metadata:
160+
m_Items: []
141161
references:
142162
version: 2
143163
RefIds: []

Assets/Localization/String Tables/Game Text_ja.asset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ MonoBehaviour:
138138
m_Localized: "\u3082\u3046\u4E00\u5EA6\u30D7\u30EC\u30A4"
139139
m_Metadata:
140140
m_Items: []
141+
- m_Id: 36438190223360
142+
m_Localized: "\u82F1\u8A9E"
143+
m_Metadata:
144+
m_Items: []
145+
- m_Id: 36495383752704
146+
m_Localized: "\u30A2\u30E9\u30D3\u30A2\u8A9E"
147+
m_Metadata:
148+
m_Items: []
149+
- m_Id: 36529051430912
150+
m_Localized: "\u30B9\u30DA\u30A4\u30F3\u8A9E"
151+
m_Metadata:
152+
m_Items: []
153+
- m_Id: 36559753736192
154+
m_Localized: "\u65E5\u672C\u8A9E"
155+
m_Metadata:
156+
m_Items: []
157+
- m_Id: 36785994493952
158+
m_Localized: "\u8A00\u8A9E"
159+
m_Metadata:
160+
m_Items: []
141161
references:
142162
version: 2
143163
RefIds: []

Assets/Resources/UITk/MainView.uxml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@
115115
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17491977990144)"/>
116116
</Bindings>
117117
</ui:Toggle>
118+
<UnityEngine.Localization.LanguageSelection table-name="Game Text">
119+
<Bindings>
120+
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(36785994493952)"/>
121+
</Bindings>
122+
</UnityEngine.Localization.LanguageSelection>
118123
<ui:Label class="settings-header-label">
119124
<Bindings>
120125
<UnityEngine.Localization.LocalizedString property="text" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17616599150592)"/>
@@ -180,7 +185,20 @@
180185
</ui:VisualElement>
181186
</ui:VisualElement>
182187
<sr:AccessibleVisualElement name="resultScreen" class="lsp-popup" style="display: none;">
183-
<ui:Label name="resultLabel" style="-unity-text-align: middle-center;"/>
188+
<ui:Label name="resultLabel" style="-unity-text-align: middle-center;">
189+
<Bindings>
190+
<UnityEngine.Localization.LocalizedString property="text" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(45343066714112)">
191+
<variables>
192+
<UnityEngine.Localization.LocalVariable name="orderedWordCount">
193+
<UnityEngine.Localization.SmartFormat.PersistentVariables.IntVariable/>
194+
</UnityEngine.Localization.LocalVariable>
195+
<UnityEngine.Localization.LocalVariable name="totalWordCount">
196+
<UnityEngine.Localization.SmartFormat.PersistentVariables.IntVariable/>
197+
</UnityEngine.Localization.LocalVariable>
198+
</variables>
199+
</UnityEngine.Localization.LocalizedString>
200+
</Bindings>
201+
</ui:Label>
184202
<ui:VisualElement name="resultButtonContainer" style="flex-grow: 1; flex-direction: row; margin-top: 10px; align-items: center;">
185203
<ui:Button name="resultMainMenuButton">
186204
<Bindings>

Assets/Scripts/Gameplay/Gameplay.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ public void StartGame()
140140
reorderedWordCount = 0;
141141
state = State.Playing;
142142

143-
localizedWordDatabase.AssetChanged += _ => RebuildWords();
143+
localizedWordDatabase.AssetChanged += _ =>
144+
{
145+
RebuildWords();
146+
m_CurrentWordIndex--;
147+
SetCurrentWordIndex(m_CurrentWordIndex + 1);
148+
};
144149

145150
RebuildWords();
146151
ShowNextWord();
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System.Collections.Generic;
2+
using UnityEngine.Localization.Pseudo;
3+
using UnityEngine.Localization.Settings;
4+
using UnityEngine.UIElements;
5+
6+
namespace UnityEngine.Localization
7+
{
8+
[UxmlElement]
9+
public partial class LanguageSelection : PopupField<Locale>
10+
{
11+
[UxmlAttribute]
12+
public string tableName;
13+
14+
[UxmlAttribute]
15+
public bool showPseudoLocales;
16+
17+
public LanguageSelection()
18+
{
19+
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
20+
}
21+
22+
void OnAttachToPanel(AttachToPanelEvent evt)
23+
{
24+
formatListItemCallback = FormatLocaleName;
25+
formatSelectedValueCallback = FormatLocaleName;
26+
27+
if (LocalizationSettings.InitializationOperation.IsDone)
28+
SetupLocalization();
29+
else
30+
LocalizationSettings.InitializationOperation.Completed += (s) => SetupLocalization();
31+
32+
RegisterCallback<ChangeEvent<Locale>>(evt =>
33+
{
34+
LocalizationSettings.SelectedLocale = evt.newValue;
35+
});
36+
37+
LocalizationSettings.SelectedLocaleChanged += (s) => SetValueWithoutNotify(LocalizationSettings.SelectedLocale);
38+
}
39+
40+
void SetupLocalization()
41+
{
42+
var choices = new List<Locale>();
43+
foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
44+
{
45+
if (locale is PseudoLocale)
46+
{
47+
if (showPseudoLocales)
48+
{
49+
choices.Add(locale);
50+
}
51+
}
52+
else
53+
{
54+
choices.Add(locale);
55+
}
56+
}
57+
58+
this.choices = choices;
59+
60+
// Schedule to avoid the rentering update method exception when called from addressables event.
61+
schedule.Execute(() => SetValueWithoutNotify(LocalizationSettings.SelectedLocale));
62+
}
63+
64+
string FormatLocaleName(Locale locale)
65+
{
66+
if (locale == null)
67+
return "None";
68+
if (string.IsNullOrEmpty(tableName))
69+
return locale.LocaleName;
70+
return LocalizationSettings.StringDatabase.GetLocalizedString(tableName, "LANGUAGE_" + locale.LocaleName.ToUpper());
71+
}
72+
}
73+
}

Assets/Scripts/Localization/LanguageSelection.cs.meta

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

0 commit comments

Comments
 (0)