selectKeyLocale

Between two key locales (i.e. locales found in keys of .ini-like file) select a better match for the provided locale. The "goodness" is determined using algorithm described in Localized values for keys.

@nogc @trusted
selectKeyLocale
(
String
)
(
scope String locale
,
scope return String firstKeyLocale
,
scope return String secondKeyLocale
)
if (
isSomeString!String &&
is(ElementEncodingType!String : char)
)

Parameters

locale String

original locale to match to

firstKeyLocale String

first key locale, can be empty

secondKeyLocale String

second key locale, can be empty

Return Value

Type: auto

a locale which is considered a better alternative or an empty string if none of alternatives match the provided locale. Note: Empty locale is considered a better choice than a locale that does not match the original one.

Examples

string locale = "ru_RU.UTF-8@jargon";
assert(selectKeyLocale(string.init, "ru_RU", "ru@jargon") == string.init);
assert(selectKeyLocale(locale, "fr_FR", string.init) == string.init);
assert(selectKeyLocale(locale, string.init, "de_DE") == string.init);
assert(selectKeyLocale(locale, "fr_FR", "de_DE") == string.init);

assert(selectKeyLocale(locale, "ru", string.init) == "ru");
assert(selectKeyLocale(locale, "ru", "ru@jargon") == "ru@jargon");
assert(selectKeyLocale(locale, "ru_RU", string.init) == "ru_RU");
assert(selectKeyLocale(locale, "ru_RU", "ru") == "ru_RU");
assert(selectKeyLocale(locale, "ru_RU", "ru@jargon") == "ru_RU");
assert(selectKeyLocale(locale, "ru_RU", "ru_RU@jargon") == "ru_RU@jargon");

assert(selectKeyLocale("en_US.UTF-8", "en", "en_GB") == "en");
assert(selectKeyLocale("en_US.UTF-8", string.init, "en_GB") == string.init);

See Also

Meta