Skip to content

Game.UI.Localization.LocalizationBindings

Assembly:
Game (assembly inferred)

Namespace:
Game.UI.Localization

Type:
class

Base:
CompositeBinding, IDisposable

Summary:
LocalizationBindings creates and manages a set of UI data bindings for the game's localization subsystem (group "l10n"). It exposes the available locales, a debug mode setting, an event for active dictionary changes, and a map of localized index counts. The class registers to LocalizationManager events to keep UI bindings up to date and provides a Trigger binding to change the active locale. Dispose() unsubscribes the event handlers.


Fields

  • private const string kGroup = "l10n"
    Identifier used as the binding group for all bindings added by this class.

  • private readonly LocalizationManager m_LocalizationManager
    Reference to the game's LocalizationManager used to query supported locales, the active dictionary, and to set the active locale.

  • private readonly GetterValueBinding<string[]> m_LocalesBinding
    GetterValueBinding that provides the array of supported locale IDs (binding key: "l10n", "locales"). It is backed by LocalizationManager.GetSupportedLocales() and uses an ArrayWriter to serialize.

  • private readonly ValueBinding<int> m_DebugModeBinding
    ValueBinding (binding key: "l10n", "debugMode") storing an integer used to represent the debug mode for localization UI. The class exposes a strongly-typed DebugMode property that reads/writes this binding.

  • private readonly EventBinding m_ActiveDictionaryChangedBinding
    EventBinding (binding key: "l10n", "activeDictionaryChanged") that is triggered when the active dictionary changes in LocalizationManager.

  • private readonly RawMapBinding<string> m_IndexCountsBinding
    RawMapBinding (binding key: "l10n", "indexCounts") used to expose index count values for localization keys. It delegates value serialization to BindIndexCounts.

Properties

  • public DebugMode debugMode { get; private set }
    Exposes the current localization debug mode via an enum (None, Id, Fallback). Getting reads the integer value from m_DebugModeBinding and casts it to DebugMode. Setting updates the underlying ValueBinding with the integer representation of the enum.

DebugMode enum: - None — no debug display - Id — display localization IDs - Fallback — display fallback text

Constructors

  • public LocalizationBindings(LocalizationManager localizationManager)
    Creates the bindings and registers event handlers on the provided LocalizationManager. The constructor:
  • Stores the localizationManager reference.
  • Adds bindings to the CompositeBinding:
    • GetterValueBinding for "l10n","locales"
    • ValueBinding for "l10n","debugMode" (default 0)
    • EventBinding for "l10n","activeDictionaryChanged"
    • RawMapBinding for "l10n","indexCounts" (using BindIndexCounts)
    • TriggerBinding for "l10n","selectLocale" (using SelectLocale)
  • Subscribes to localizationManager.onSupportedLocalesChanged and onActiveDictionaryChanged to update bindings when the manager changes.

Methods

  • public void Dispose()
    Unsubscribes the class from LocalizationManager events (onSupportedLocalesChanged and onActiveDictionaryChanged). Call this when the bindings are no longer needed to avoid memory leaks.

  • private void OnSupportedLocalesChanged()
    Callback invoked when the LocalizationManager reports supported locales changed. Calls m_LocalesBinding.Update() so bound UI can refresh the locales list.

  • private void OnActiveDictionaryChanged()
    Callback invoked when the LocalizationManager's active dictionary changes. Triggers the m_ActiveDictionaryChangedBinding and updates all entries for m_IndexCountsBinding so UI can refresh index counts.

  • private void BindIndexCounts(IJsonWriter binder, string key)
    RawMapBinding callback used to write the index count for a given localization key. It writes the value of m_LocalizationManager.activeDictionary.indexCounts.TryGetValue(key, out value) ? value : 0.

  • private void SelectLocale(string localeID)
    Trigger handler that sets the active locale in the LocalizationManager and, if available, updates the persisted interface setting:

  • Calls m_LocalizationManager?.SetActiveLocale(localeID)
  • If SharedSettings.instance?.userInterface is present, sets interfaceSettings.locale = localeID

Usage Example

// Example: create bindings and change debug mode / select locale
var localizationManager = /* obtain LocalizationManager instance */;
var bindings = new LocalizationBindings(localizationManager);

// Read/modify debug mode
var current = bindings.debugMode;
bindings.debugMode = LocalizationBindings.DebugMode.Id;

// Programmatically select a locale (also updates InterfaceSettings if available)
bindings.SelectLocale("en-US");

// When done with the bindings (e.g. UI closed), dispose to unsubscribe events:
bindings.Dispose();