Function 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.

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

Parameters

NameDescription
locale original locale to match to
firstKeyLocale first key locale, can be empty
secondKeyLocale second key locale, can be empty

Returns

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.

See Also

separateFromLocale, selectLocalizedValue

Example

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);