Skip to content

Game.UI.Localization.UILocalizationManager

Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Localization

Type: class

Base: ILocalizationManager

Summary:
Wrapper implementation of ILocalizationManager used to bridge the game's LocalizationManager (Colossal.Localization.LocalizationManager) to cohtml's TranslationData. When asked to translate a key, this class queries the game's active dictionary and sets the resulting localized string on the provided TranslationData. If no translation is found or the underlying LocalizationManager is null, it falls back to setting the raw key so UI text is never left unset.


Fields

  • private readonly LocalizationManager m_LocalizationManager
    Reference to the game's LocalizationManager used to look up translations. This is provided via the public constructor; if null, Translate will fall back to using the key string directly.

Properties

  • This class has no public or private properties.

Constructors

  • public UILocalizationManager(LocalizationManager localizationManager)
    Creates a new UILocalizationManager that will use the provided LocalizationManager instance for translations.

  • private UILocalizationManager()
    A private parameterless constructor. Likely present to prevent default construction from outside the class or for serialization/deserialization considerations.

Methods

  • public override void Translate(string key, TranslationData data)
    Looks up the provided key in m_LocalizationManager.activeDictionary. If a value is found, it calls data.Set(value) to supply the translated string to the cohtml UI. If the lookup fails or m_LocalizationManager is null, it calls data.Set(key) so the key itself is displayed as a fallback. Parameters:
  • key: the localization key to translate.
  • data: cohtml.Net.TranslationData instance where the translated (or fallback) string will be stored.

Usage Example

using cohtml.Net;
using Colossal.Localization;
using Game.UI.Localization;

// Example: creating the manager and translating a key
LocalizationManager gameLocalization = /* obtain the game's LocalizationManager instance */;
var uiLocManager = new UILocalizationManager(gameLocalization);

var translationData = new TranslationData();
uiLocManager.Translate("MY_UI_KEY", translationData);

// Now translationData contains the localized string (or the key if not found)
string localized = translationData.ToString(); // depending on TranslationData API

{{ Notes: - Requires references to cohtml.Net and Colossal.Localization. - This class is lightweight and only forwards lookups to the game's active dictionary; it does not perform caching or formatting. - Ensure you pass a valid LocalizationManager (from the game's runtime) if you want actual translations instead of key fallbacks. }}