Table of Contents

Struct Locale

Namespace
Sdl3Sharp
Assembly
Sdl3Sharp.dll

Represents locale identification data

public readonly struct Locale : IEquatable<Locale>, ISpanFormattable, IFormattable, IEqualityOperators<Locale, Locale, bool>
Implements
Inherited Members

Remarks

Locale identification data is split into a spoken language, like English, and an optional country, like Canada.

Constructors

Locale(string, string?)

Represents locale identification data

[SetsRequiredMembers]
public Locale(string language, string? country = null)

Parameters

language string

The language identifier for the Locale

country string

The country identifier for the Locale, or null if there's none

Remarks

Locale identification data is split into a spoken language, like English, and an optional country, like Canada.

Properties

Country

Gets the country identifier for the Locale

public string? Country { get; init; }

Property Value

string

The country identifier for the Locale, if there's any; otherwise, null

Remarks

The value for this property will be in ISO-3166 format, e.g. Canada would be "CA", if there's a country identifier to the Locale; otherwise, the value for this property will be null.

Language

Gets the language identifier for the Locale

public required string Language { get; init; }

Property Value

string

The language identifier for the Locale

Remarks

The value for this property will be in ISO-639 format, e.g. English would be "en".

Methods

Deconstruct(out string, out string?)

Deconstructs the Locale into its language identifier part and its country identifier part

public void Deconstruct(out string language, out string? country)

Parameters

language string

The language identifier for the Locale

country string

The country identifier for the Locale, if there's any; otherwise, null

Remarks

The resulting value for the language parameter will be in ISO-639 format, e.g. English would be "en".

The resulting value for the country parameter will be in ISO-3166 format, e.g. Canada would be "CA", if there's a country identifier to the Locale; otherwise, the value will be null.

See Also

Equals(Locale)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Locale other)

Parameters

other Locale

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

TryFormat(Span<char>, out int)

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten)

Parameters

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

Returns

bool

true if the formatting was successful; otherwise, false.

TryGetPreferredLocales(out Locale[]?)

Tries to get the user's preferred locales

public static bool TryGetPreferredLocales(out Locale[]? locales)

Parameters

locales Locale[]

The user's preferred locales when this method returns true; otherwise, null

Returns

bool

true, if the user's preferred locales could be successfully retrieved; otherwise, false (check TryGet(out string?) for more information)

Remarks

The returned list of locales are in the order of the user's preference. For example, a German citizen that is fluent in US English and knows enough Japanese to navigate around Tokyo might have a list like: de, en-US, jp. Someone from England might prefer British English (where "color" is spelled "colour", etc), but will settle for anything like it: en-GB, en.

This method returns false together with locales set to null on failure, including when the platform does not supply preferred locale information at all.

This might be a "slow" call that has to query the operating system. It's best to ask for this once and save the results. However, this list can change, usually because the user has changed a system preference outside of your program; SDL will send an LocaleChanged event (see also LocaleChanged) in this case, if possible, and you can call this method again to get an updated copy of preferred locales.

Operators

operator ==(Locale, Locale)

Compares two values to determine equality.

public static bool operator ==(Locale left, Locale right)

Parameters

left Locale

The value to compare with right.

right Locale

The value to compare with left.

Returns

bool

true if left is equal to right; otherwise, false.

operator !=(Locale, Locale)

Compares two values to determine inequality.

public static bool operator !=(Locale left, Locale right)

Parameters

left Locale

The value to compare with right.

right Locale

The value to compare with left.

Returns

bool

true if left is not equal to right; otherwise, false.