logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class 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.
    Inheritance
    object
    SerenityFallbackLocalizationService
    Implements
    ILocalizationService
    IService
    IFoundationSettings
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.Localization.Infrastructure.Services
    Assembly: Serenity.UnityLocalization.Infrastructure.dll
    Syntax
    public class SerenityFallbackLocalizationService : ILocalizationService, IService, IFoundationSettings

    Constructors

    SerenityFallbackLocalizationService(ILogService, IGameSettingsService, IEventDispatcherService, string, string)

    Builds a fallback localization service. Any constructor argument may be null — the service degrades gracefully (no game-settings seeding, no log output, no translation data — TryTranslate just returns false).

    Slice CC: when both eventDispatcherService and gameLanguageKey are non-null/non-empty, the service subscribes to OnGameSettingsOnValueUpdatedSignal and routes changes to the language game-setting back into SetGameLanguage(LocalizationSetGameLanguageInput). This is what makes the language dropdown in the settings UI actually take effect on WebGL — the UI only calls _gameSettingsService.SetStringValue, which dispatches the signal; without this subscription the localization service would never hear about it. Mirror of UnityLocalizationService.SubscribeToEventDispatcherEvents.

    Declaration
    public SerenityFallbackLocalizationService(ILogService logService = null, IGameSettingsService gameSettingsService = null, IEventDispatcherService eventDispatcherService = null, string gameLanguageKey = null, string voiceLanguageKey = null)
    Parameters
    Type Name Description
    ILogService logService

    Logger used for the one-time mode-switch message.

    IGameSettingsService gameSettingsService

    Optional game-settings source. When provided together with non-empty language keys, the current language is seeded from the game-settings value, then the setting's default, then Serenity.Localization.Infrastructure.Services.SerenityFallbackLocalizationService.DefaultLanguage.

    IEventDispatcherService eventDispatcherService

    Optional event dispatcher. When provided together with non-empty language keys, the service auto-syncs with game-settings changes via OnGameSettingsOnValueUpdatedSignal.

    string gameLanguageKey

    Game-settings key for the game language (e.g. "GameLanguage"). Empty/null skips game-settings seeding for game language AND skips the language-change subscription for this key.

    string voiceLanguageKey

    Game-settings key for the voice language. Empty/null skips game-settings seeding for voice language AND skips the language-change subscription for this key.

    Properties

    Guid

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    string

    Id

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    LogService

    Declaration
    public ILogService LogService { get; set; }
    Property Value
    Type Description
    ILogService

    Methods

    GetGameLanguage()

    Declaration
    public string GetGameLanguage()
    Returns
    Type Description
    string

    GetStringTableReference()

    Returns an empty string. Consumers (e.g. the TMP localization updater) treat empty as "no Unity Localization table available, take the fallback path" — which is the correct behaviour in ResourcesOnly. The fallback path then calls TryTranslate(string, out string) on this service.

    Declaration
    public string GetStringTableReference()
    Returns
    Type Description
    string

    GetVoiceLanguage()

    Declaration
    public string GetVoiceLanguage()
    Returns
    Type Description
    string

    SetGameLanguage(LocalizationSetGameLanguageInput)

    Declaration
    public void SetGameLanguage(LocalizationSetGameLanguageInput input)
    Parameters
    Type Name Description
    LocalizationSetGameLanguageInput input

    SetVoiceLanguage(LocalizationSetVoiceLanguageInput)

    Declaration
    public void SetVoiceLanguage(LocalizationSetVoiceLanguageInput input)
    Parameters
    Type Name Description
    LocalizationSetVoiceLanguageInput input

    TryTranslate(string, out string)

    Declaration
    public bool TryTranslate(string key, out string value)
    Parameters
    Type Name Description
    string key
    string value
    Returns
    Type Description
    bool
    Remarks

    O(1) lookup against the in-memory map built at construction. Empty/null keys, an unknown current locale, or an unknown key all return false with value = null — the caller (typically the TMP updater) leaves the raw key on screen as the last-resort fallback. Translated empty strings are treated as misses so a malformed export does not silently blank out UI text.

    Events

    GameLanguageChanged

    Declaration
    public event Action GameLanguageChanged
    Event Type
    Type Description
    Action

    Implements

    ILocalizationService
    IService
    IFoundationSettings
    In this article
    © 2026 Serenity. All Rights Reserved