Game.Debug.LocalizationDebugUI
Assembly: Game (Cities: Skylines 2 game assembly)
Namespace: Game.Debug
Type: class
Base: System.IDisposable
Summary:
Debug UI helper that exposes localization-related debugging tools in the in-game debug UI. It is marked with DebugContainer and provides a "Localization" debug tab (via DebugTab attribute). The tab lets you switch the active language, toggle localization debug modes (Show Translations / Show IDs / Show Fallback), and contains buttons to print input bindings/controls and to export asset categories (with their localization IDs) to a CSV in the user's data path. The class accesses the game's LocalizationManager, InputManager, EditorAssetCategorySystem and uses Unity.Entities.World to query editor categories.
Fields
-
private static readonly UnityEngine.GUIContent[] kLocalizationDebugModeStrings
Stores the three GUIContent entries used for the "Debug Mode" enum field in the debug UI: "Show Translations", "Show IDs", and "Show Fallback". These correspond to localization debugging modes presented to the user. -
private int m_SelectedContentId
Holds a selected content ID used during initialization. It is provided to InitLocalization in the constructor, but in this implementation InitLocalization is empty (placeholder).
Properties
- None (no public or private properties declared in this type)
Constructors
public LocalizationDebugUI()
Constructs the debug UI helper and calls InitLocalization(m_SelectedContentId). InitLocalization is currently an empty placeholder; the constructor primarily ensures any needed initialization call is invoked.
Methods
-
private void InitLocalization(int contentId)
Placeholder method intended to initialize localization-related state for the given contentId. Currently empty in this implementation. -
public void Dispose()
Implements IDisposable. Currently empty — no teardown logic is implemented here, but the method exists to allow future cleanup and to satisfy IDisposable. -
private void Rebuild()
Triggers a debug UI rebuild by calling DebugSystem.Rebuild(BuildLocalizationDebugUI). This forces the debug UI to be refreshed using the BuildLocalizationDebugUI method. -
[DebugTab("Localization", -5)] private List<DebugUI.Widget> BuildLocalizationDebugUI(Unity.Entities.World world)
Builds and returns a list of DebugUI.Widget entries that populate the "Localization" debug tab. Behavior and notable widgets: -
Language EnumField
- displayName = "Language"
- enumNames = supported locale strings from LocalizationManager.GetSupportedLocales()
- getter / getIndex = index of current active locale in the locales array
- setter = calls LocalizationManager.SetActiveLocale(locale)
- Allows switching the game's active locale via the debug UI.
-
Debug Mode EnumField
- displayName = "Debug Mode"
- binds to GameManager.instance.userInterface.localizationBindings.debugMode (cast to/from an int)
- enumNames = kLocalizationDebugModeStrings
- autoEnum = typeof(LocalizationBindings.DebugMode)
- Allows toggling localization debug modes (Show Translations / Show IDs / Show Fallback).
-
"Print input bindings and controls" Button
- Gathers rebindable input ProxyBinding entries using InputManager.instance.GetBindings(InputManager.PathType.Effective, InputManager.BindingOptions.OnlyRebindable).
- Builds two lists:
- Unique binding titles (used to emit Options.OPTION[...] entries and a placeholder description).
- Human-readable input control paths (prefixed with device name) used to emit Options.INPUT_CONTROL[...] entries.
- Logs both lists via UnityEngine.Debug.Log (one shows option keys and placeholder descriptions; the other shows input control keys and control names).
- Useful for extracting localization keys for input options and controls.
-
"Print asset categories" Button
- Uses the supplied World to get EditorAssetCategorySystem (world.GetOrCreateSystemManaged
()). - Iterates categories and appends lines of "localizationID,id" for each EditorAssetCategory.
- Writes the resulting CSV to a file named "category_locale.csv" in EnvPath.kUserDataPath.
- Uses File.OpenWrite or File.Create as appropriate and a StreamWriter to write the contents.
- Useful to export category localization IDs to CSV for translation/reference.
- Uses the supplied World to get EditorAssetCategorySystem (world.GetOrCreateSystemManaged
Notes: - If LocalizationManager is not available (null), BuildLocalizationDebugUI returns null. - The list construction uses lambda delegates and closures for getters/setters and button actions.
Usage Example
// The debug system will pick up this class because it is marked with [DebugContainer].
// You can instantiate and dispose it manually if needed for tests:
var debugUI = new Game.Debug.LocalizationDebugUI();
// If you want to force the debug UI to refresh from code:
debugUI.Rebuild(); // Triggers DebugSystem.Rebuild using BuildLocalizationDebugUI
// When finished:
debugUI.Dispose();
// Typical in-game use: open the debug UI and select the "Localization" tab.
// Use "Language" to change active locale via LocalizationManager.SetActiveLocale(...).
// Use "Debug Mode" to toggle localization debug visuals via userInterface.localizationBindings.debugMode.
// Click "Print asset categories" to create category_locale.csv in EnvPath.kUserDataPath.
Additional notes for modders: - The class depends on: - GameManager.instance.localizationManager (Colossal.Localization.LocalizationManager) - GameManager.instance.userInterface.localizationBindings (holds the DebugMode enum) - InputManager for binding extraction - EditorAssetCategorySystem for category enumeration - EnvPath.kUserDataPath for file output - The BuildLocalizationDebugUI method receives a Unity.Entities.World instance — when manually calling this from tests or other systems, ensure you pass the correct World that contains EditorAssetCategorySystem if you need category export functionality.