Locale
Represents a selectable language or region in a localized project. A locale carries a culture code, an optional display name, a formatting culture, and an optional fallback.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
public class Locale
Remarks
A locale is the unit the runtime selects between when it resolves localized content. It pairs a LocaleIdentifier (the culture code) with a display name and the formatting culture reported by Locale.CultureInfo, which drives number, date, and string formatting. When a value is missing in the selected locale, the runtime can fall back to the locale named by Locale.FallbackCode. A locale is a plain serializable object rather than a asset, so it is stored inline in the localization settings.
ScriptableObjectCreate a locale, then read its identifier, display name, and formatting culture.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class LocaleOverviewExample { public void Run() { var locale = new Locale("fr-CA", "French (Canada)"); Debug.Log(locale.Identifier); // fr-CA Debug.Log(locale.LocaleName); // French (Canada) Debug.Log(locale.CultureInfo.Name); // fr-CA Debug.Log(locale.Enabled); // True } }}
Constructors
Constructor | Description |
|---|---|
| Locale() | Creates a locale with no culture code. |
| Locale(System.String,System.String) | Creates a locale for a culture code, with an optional display name. |
Properties
Property | Description |
|---|---|
| Code | The culture code, for example "en" or "fr-CA". |
| CultureInfo | The formatting culture for this locale, or the invariant culture when the code is not a known culture. |
| Enabled | Whether the locale is active: a disabled locale is excluded from runtime selection and its tables are not shipped in a build. |
| FallbackCode | The culture code of the fallback locale, resolved through the settings, or null when there is no fallback. |
| Identifier | The identifier for this locale. |
| LocaleName | The display name, for example "English". When not set, falls back to the culture's native name, then the code. |