Struct Locale
Locale value type that unifies ISO 639-1 language codes (e.g., "en", "ja")
and IETF/BCP-47 tags (e.g., "en-US", "ja-JP") for game/app localization:
- Purpose: Represent a language (and optionally a region) with a single, ergonomic type.
- Inputs: Accepts
string codes, SystemLanguage, CultureInfo, enum int index, or another Locale. - Parsing: Strings containing '-' or '_' are treated as IETF/BCP-47 (e.g.,
en-US); otherwise parsed as ISO 639-1 (e.g., en). - Normalization: Internally normalizes to
CultureInfo.Name (e.g., "en-US"); case-insensitive; underscores tolerated. - Defaults:
Unknown maps to SystemLanguage.Unknown; null/empty/invalid inputs safely fall back to "en-US". - Properties:
CultureCode returns normalized tag (e.g., "en-US"); DisplayName from CultureInfo (e.g., "English (United States)"). - System bridges:
EnumValue exposes SystemLanguage; CultureInfo exposes full culture data for formatting and ICU rules. - Conversions:
implicit/explicit operators for SystemLanguage, CultureInfo, string, and int enable ergonomic use. - API helpers:
FromISO6391("en") and FromIETFTag("en-US") parse common code paths with safe fallbacks. - Equality:
Equals/== compare SystemLanguage and normalized CultureCode (case-insensitive); GetHashCode stable for dictionary keys. - Ordering:
CompareTo orders by SystemLanguage enum for predictable sorting. - Serialization:
OnBeforeSerialize/OnAfterDeserialize keep CultureInfo, EnumValue, and cultureCode consistent; safe default is "en-US". - When to use ISO 639-1 If regional differences are irrelevant (shared audio/UI), simple language codes (e.g., "en", "ja") are sufficient.
- When to use IETF tags If spelling/audio/content varies by region, use locale-specific tags (e.g., "en-US", "en-GB", "ja-JP").
- Best practice Store
CultureCode (normalized) for persistence; convert to SystemLanguage/CultureInfo at UI/runtime edges.
Implements
ISerializationCallbackReceiver
Assembly: Glitch9.dll
Syntax
[Serializable]
[JsonConverter(typeof(LocaleIetfConverter))]
public struct Locale : ISerializationCallbackReceiver, IComparable, IValidatable
Constructors
|
Edit this page
View Source
Locale(Locale)
Declaration
public Locale(Locale locale)
Parameters
| Type |
Name |
Description |
| Locale |
locale |
|
|
Edit this page
View Source
Locale(CultureInfo)
Declaration
public Locale(CultureInfo cultureInfo)
Parameters
|
Edit this page
View Source
Locale(SystemLanguage)
Declaration
public Locale(SystemLanguage enumValue)
Parameters
| Type |
Name |
Description |
| SystemLanguage |
enumValue |
|
|
Edit this page
View Source
Locale(SystemLanguage, string, CultureInfo)
Declaration
public Locale(SystemLanguage enumValue, string cultureCode, CultureInfo cultureInfo)
Parameters
| Type |
Name |
Description |
| SystemLanguage |
enumValue |
|
| string |
cultureCode |
|
| CultureInfo |
cultureInfo |
|
Fields
|
Edit this page
View Source
cultureCode
Declaration
[SerializeField]
public string cultureCode
Field Value
Properties
|
Edit this page
View Source
ArAE
Declaration
public static Locale ArAE { get; }
Property Value
|
Edit this page
View Source
ArSA
Declaration
public static Locale ArSA { get; }
Property Value
|
Edit this page
View Source
BgBG
Declaration
public static Locale BgBG { get; }
Property Value
|
Edit this page
View Source
CsCZ
Declaration
public static Locale CsCZ { get; }
Property Value
|
Edit this page
View Source
CultureCode
Declaration
[JsonIgnore]
public readonly string CultureCode { get; }
Property Value
|
Edit this page
View Source
CultureInfo
Declaration
[JsonIgnore]
public readonly CultureInfo CultureInfo { get; }
Property Value
|
Edit this page
View Source
DaDK
Declaration
public static Locale DaDK { get; }
Property Value
|
Edit this page
View Source
DeDE
Declaration
public static Locale DeDE { get; }
Property Value
|
Edit this page
View Source
DisplayName
Declaration
[JsonIgnore]
public readonly string DisplayName { get; }
Property Value
|
Edit this page
View Source
EnAU
Declaration
public static Locale EnAU { get; }
Property Value
|
Edit this page
View Source
EnCA
Declaration
public static Locale EnCA { get; }
Property Value
|
Edit this page
View Source
EnGB
Declaration
public static Locale EnGB { get; }
Property Value
|
Edit this page
View Source
EnUS
Declaration
public static Locale EnUS { get; }
Property Value
|
Edit this page
View Source
EnumValue
Declaration
[JsonIgnore]
public readonly SystemLanguage EnumValue { get; }
Property Value
| Type |
Description |
| SystemLanguage |
|
|
Edit this page
View Source
EsAR
Declaration
public static Locale EsAR { get; }
Property Value
|
Edit this page
View Source
EsES
Declaration
public static Locale EsES { get; }
Property Value
|
Edit this page
View Source
EsMX
Declaration
public static Locale EsMX { get; }
Property Value
|
Edit this page
View Source
FiFI
Declaration
public static Locale FiFI { get; }
Property Value
|
Edit this page
View Source
FrCA
Declaration
public static Locale FrCA { get; }
Property Value
|
Edit this page
View Source
FrFR
Declaration
public static Locale FrFR { get; }
Property Value
|
Edit this page
View Source
HeIL
Declaration
public static Locale HeIL { get; }
Property Value
|
Edit this page
View Source
HiIN
Declaration
public static Locale HiIN { get; }
Property Value
|
Edit this page
View Source
HuHU
Declaration
public static Locale HuHU { get; }
Property Value
|
Edit this page
View Source
IdID
Declaration
public static Locale IdID { get; }
Property Value
|
Edit this page
View Source
ItIT
Declaration
public static Locale ItIT { get; }
Property Value
|
Edit this page
View Source
JaJP
Declaration
public static Locale JaJP { get; }
Property Value
|
Edit this page
View Source
KoKR
Declaration
public static Locale KoKR { get; }
Property Value
|
Edit this page
View Source
MsMY
Declaration
public static Locale MsMY { get; }
Property Value
|
Edit this page
View Source
NbNO
Declaration
public static Locale NbNO { get; }
Property Value
|
Edit this page
View Source
NlNL
Declaration
public static Locale NlNL { get; }
Property Value
|
Edit this page
View Source
PlPL
Declaration
public static Locale PlPL { get; }
Property Value
|
Edit this page
View Source
PtBR
Declaration
public static Locale PtBR { get; }
Property Value
|
Edit this page
View Source
PtPT
Declaration
public static Locale PtPT { get; }
Property Value
|
Edit this page
View Source
RoRO
Declaration
public static Locale RoRO { get; }
Property Value
|
Edit this page
View Source
RuRU
Declaration
public static Locale RuRU { get; }
Property Value
|
Edit this page
View Source
SvSE
Declaration
public static Locale SvSE { get; }
Property Value
|
Edit this page
View Source
ThTH
Declaration
public static Locale ThTH { get; }
Property Value
|
Edit this page
View Source
TrTR
Declaration
public static Locale TrTR { get; }
Property Value
|
Edit this page
View Source
UkUA
Declaration
public static Locale UkUA { get; }
Property Value
|
Edit this page
View Source
Unspecified
Declaration
public static Locale Unspecified { get; }
Property Value
|
Edit this page
View Source
ViVN
Declaration
public static Locale ViVN { get; }
Property Value
|
Edit this page
View Source
ZhCN
Declaration
public static Locale ZhCN { get; }
Property Value
|
Edit this page
View Source
ZhHK
Declaration
public static Locale ZhHK { get; }
Property Value
|
Edit this page
View Source
ZhTW
Declaration
public static Locale ZhTW { get; }
Property Value
Methods
|
Edit this page
View Source
CompareTo(object)
Declaration
public readonly int CompareTo(object obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
|
Edit this page
View Source
Equals(Locale)
Declaration
public readonly bool Equals(Locale other)
Parameters
| Type |
Name |
Description |
| Locale |
other |
|
Returns
|
Edit this page
View Source
Equals(object)
Declaration
public override readonly bool Equals(object obj)
Parameters
| Type |
Name |
Description |
| object |
obj |
|
Returns
Overrides
|
Edit this page
View Source
FromCode(string, LanguageCodeType)
Declaration
public static Locale FromCode(string code, LanguageCodeType codeType = LanguageCodeType.IETF_BCP_47)
Parameters
Returns
|
Edit this page
View Source
FromCultureCode(string)
Declaration
public static Locale FromCultureCode(string cultureCode)
Parameters
| Type |
Name |
Description |
| string |
cultureCode |
|
Returns
|
Edit this page
View Source
GetHashCode()
Declaration
public override readonly int GetHashCode()
Returns
Overrides
|
Edit this page
View Source
IsValid()
Declaration
public readonly bool IsValid()
Returns
|
Edit this page
View Source
OnAfterDeserialize()
Implement this callback to transform data back into runtime data types after an object is deserialized.
Declaration
public void OnAfterDeserialize()
|
Edit this page
View Source
OnBeforeSerialize()
Implement this callback to transform data into serializable data types immediately before an object is serialized.
Declaration
public void OnBeforeSerialize()
|
Edit this page
View Source
ToString()
Declaration
public override readonly string ToString()
Returns
Overrides
|
Edit this page
View Source
Validate()
Validates the object's parameters and throws if invalid.
Declaration
public readonly void Validate()
Operators
|
Edit this page
View Source
operator ==(Locale, Locale)
Declaration
public static bool operator ==(Locale a, Locale b)
Parameters
Returns
|
Edit this page
View Source
operator ==(Locale, SystemLanguage)
Declaration
public static bool operator ==(Locale a, SystemLanguage b)
Parameters
| Type |
Name |
Description |
| Locale |
a |
|
| SystemLanguage |
b |
|
Returns
|
Edit this page
View Source
operator ==(SystemLanguage, Locale)
Declaration
public static bool operator ==(SystemLanguage a, Locale b)
Parameters
| Type |
Name |
Description |
| SystemLanguage |
a |
|
| Locale |
b |
|
Returns
|
Edit this page
View Source
explicit operator int(Locale)
Declaration
public static explicit operator int(Locale locale)
Parameters
| Type |
Name |
Description |
| Locale |
locale |
|
Returns
|
Edit this page
View Source
explicit operator Locale(int)
Declaration
public static explicit operator Locale(int enumIndex)
Parameters
| Type |
Name |
Description |
| int |
enumIndex |
|
Returns
|
Edit this page
View Source
explicit operator Locale(string)
Declaration
public static explicit operator Locale(string localeCode)
Parameters
| Type |
Name |
Description |
| string |
localeCode |
|
Returns
|
Edit this page
View Source
implicit operator SystemLanguage(Locale)
Declaration
public static implicit operator SystemLanguage(Locale locale)
Parameters
| Type |
Name |
Description |
| Locale |
locale |
|
Returns
| Type |
Description |
| SystemLanguage |
|
|
Edit this page
View Source
implicit operator Locale(CultureInfo)
Declaration
public static implicit operator Locale(CultureInfo cultureInfo)
Parameters
Returns
|
Edit this page
View Source
implicit operator Locale(SystemLanguage)
Declaration
public static implicit operator Locale(SystemLanguage language)
Parameters
| Type |
Name |
Description |
| SystemLanguage |
language |
|
Returns
|
Edit this page
View Source
operator !=(Locale, Locale)
Declaration
public static bool operator !=(Locale a, Locale b)
Parameters
Returns
|
Edit this page
View Source
operator !=(Locale, SystemLanguage)
Declaration
public static bool operator !=(Locale a, SystemLanguage b)
Parameters
| Type |
Name |
Description |
| Locale |
a |
|
| SystemLanguage |
b |
|
Returns
|
Edit this page
View Source
operator !=(SystemLanguage, Locale)
Declaration
public static bool operator !=(SystemLanguage a, Locale b)
Parameters
| Type |
Name |
Description |
| SystemLanguage |
a |
|
| Locale |
b |
|
Returns
Implements
UnityEngine.ISerializationCallbackReceiver
Extension Methods