MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnLocalizationChanged

Method OnLocalizationChanged

Source/Engine/Localization/Localization.cpp:216–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216void LocalizationService::OnLocalizationChanged()
217{
218 PROFILE_CPU();
219 PROFILE_MEM(Localization);
220
221 Instance.LocalizedStringTables.Clear();
222 Instance.FallbackStringTables.Clear();
223 const StringView en(TEXT("en"));
224
225 // Collect all localization tables into mapping locale -> tables
226 auto& settings = *LocalizationSettings::Get();
227 Dictionary<String, Array<AssetReference<LocalizedStringTable>, InlinedAllocation<32>>> tables;
228 for (auto& e : settings.LocalizedStringTables)
229 {
230 auto table = e.Get();
231 if (table && !table->WaitForLoaded())
232 {
233 tables[table->Locale].Add(table);
234 }
235 }
236
237 // Pick localization tables for a current language
238 auto* table = tables.TryGet(Instance.CurrentLanguage.GetName());
239 if (!table)
240 {
241 // Try using parent culture (eg. en if en-GB is missing)
242 const CultureInfo parentLanguage(Instance.CurrentLanguage.GetParentLCID());
243 if (parentLanguage.GetName().HasChars())
244 table = tables.TryGet(parentLanguage.GetName());
245 if (!table)
246 {
247 // Fallback to Default
248 table = tables.TryGet(settings.DefaultFallbackLanguage);
249 if (!table)
250 {
251 // Fallback to English
252 table = tables.TryGet(en);
253 }
254 }
255 }
256
257 // Apply localization table
258 if (table)
259 {
260 String locale;
261 for (auto& e : tables)
262 {
263 if (&e.Value == table)
264 {
265 locale = e.Key;
266 break;
267 }
268 }
269 LOG(Info, "Using localization for {0}", locale);
270 Instance.LocalizedStringTables.Add(table->Get(), table->Count());
271 if (locale != settings.DefaultFallbackLanguage || locale != en)
272 {
273 // Cache fallback language tables to support additional text resolving in case of missing entries in the current language

Callers 5

ApplyMethod · 0.45
InitMethod · 0.45
SetCurrentCultureMethod · 0.45
SetCurrentLanguageMethod · 0.45

Calls 14

localeFunction · 0.85
WaitForLoadedMethod · 0.80
GetParentLCIDMethod · 0.80
GetFunction · 0.50
ClearMethod · 0.45
GetMethod · 0.45
AddMethod · 0.45
TryGetMethod · 0.45
GetNameMethod · 0.45
HasCharsMethod · 0.45
CountMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected