logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Namespace Serenity.Localization.Infrastructure.Services

    Classes

    SerenityFallbackLocalizationService

    Plain-C# ILocalizationService implementation used when Serenity is running in SerenityAssetLoadingMode.ResourcesOnly — typically WebGL builds that ship without an Addressables catalog and therefore cannot run Unity Localization's table / locale registry (which is Addressables-backed and triggers WaitForCompletion on sync access).

    Slice AA: this service now actually translates. At construction it loads every TextAsset the WebGL Resources exporter emitted under the Serenity.Localization.Infrastructure.Services.SerenityFallbackLocalizationService.LocalizationResourcesRoot Resources folder (one JSON per StringTableCollection per locale, shape SerenityFallbackLocalizationService.StringTableJson) and builds an in-memory map of locale → (key → value). TryTranslate(string, out string) looks the key up using the current game language. If the exporter wasn't run, or the consumer has no Unity Localization tables at all, the load is a no-op and TryTranslate returns false for every key — falling back to whatever text was already on the TMP component (which is the raw key, identical to the pre-Slice-AA behaviour).

    This service deliberately does not:

    • Reference UnityEngine.Localization.Settings.LocalizationSettings, any locale, any string table, or any LocalizeStringEvent.
    • Touch UnityEngine.AddressableAssets.Addressables.
    • Throw for missing locales / tables / keys. Callers always get a safe value.
    • Spam the log on every key request — it logs once at construction.

    SerenityFallbackLocalizationService.StringTableJson

    JSON-serialisable shape of one exported (table, locale) pair. Parallel Keys/Values arrays rather than a Dictionary<string,string> because Unity's JsonUtility cannot round-trip generic dictionaries. The exporter writes the same shape on the editor side — the contract between the two is this class.

    UnityLocalizationService

    Unity MonoBehaviour implementation of the localization service that manages game and voice language settings.
    Integrates with Unity's Localization system to handle locale switching and responds to game settings changes through event dispatching.

    UnityLocalizationServiceFactory

    Unity-specific factory for creating localization service instances as MonoBehaviour components.
    Creates a new GameObject with the UnityLocalizationService component and initializes it with the provided dependencies.

    In this article
    © 2026 Serenity. All Rights Reserved