Localization
- Namespace: Turian.Engine.Core
- Source File: Localization.cs
Static entry point for game code and UI documents, resolving the active LocaleService from RuntimeServices the same way InputActions resolves the input service.
Remarks
Every member is neutral when no service is registered, so a script or document can call T before the project's tables are loaded without throwing. The service itself is reachable through Service for handlers that need its events.
Properties
Service
(LocaleService?): The active service, or null when none is registered.
IsAvailable
(bool): Whether a localization service is in force.
ActiveLocale
(string): The active locale, or en when no service is registered.
Public Methods
SetLocale
public static bool SetLocale(string locale)
Switches the active locale; no-op when no service is registered.
Parameters:
locale(string): The BCP-47 locale to switch to.
Returns: bool
truewhen the locale actually changed.
T
public static string T(string key, string? fallback = null, decimal? count = null)
Resolves a key, falling back to the key itself when there is no service or no entry.
Parameters:
key(string): The localization key.fallback(string?): Text to return when no table holds the key; defaults to the key. (Default:null)count(decimal?): The count a plural message selects its variant from, ornull. (Default:null)
Returns: string
- The localized, formatted string.
Source
public static string Source(string source, decimal? count = null)
Resolves authored source text, returning it unchanged when there is no translation.
Parameters:
source(string): The authored text, also used as the lookup key.count(decimal?): The count a plural message selects its variant from, ornull. (Default:null)
Returns: string
- The localized string, or
source.
Resolve
public static string Resolve(string? key, string? source)
The text a .ui element should draw: key when the document names one explicitly, otherwise source used as its own key. Both paths return the source unchanged when there is no service or no matching entry.
Parameters:
key(string?): An explicit localization key, ornull/empty when the document has none.source(string?): The authored text.
Returns: string
- The localized text.