IniLikeGroup.localizedValue

Perform locale matching lookup as described in Localized values for keys.

class IniLikeGroup
@safe final const nothrow pure
string
localizedValue
(
string key
,
string locale
,
Flag!"nonLocaleFallback" nonLocaleFallback = Yes.nonLocaleFallback
)

Parameters

key string

Non-localized key.

locale string

Locale in intereset.

nonLocaleFallback Flag!"nonLocaleFallback"

Allow fallback to non-localized version.

Return Value

Type: string

The localized value associated with key and locale, or the value associated with non-localized key if group does not contain localized value and nonLocaleFallback is true. Note: The value is not unescaped automatically.

Examples

auto lilf = new IniLikeFile;
lilf.addGenericGroup("Entry");
auto group = lilf.group("Entry");
assert(group.groupName == "Entry");
group["Name"] = "Programmer";
group["Name[ru_RU]"] = "Разработчик";
group["Name[ru@jargon]"] = "Кодер";
group["Name[ru]"] = "Программист";
group["Name[de_DE@dialect]"] = "Programmierer"; //just example
group["Name[fr_FR]"] = "Programmeur";
group["GenericName"] = "Program";
group["GenericName[ru]"] = "Программа";
assert(group["Name"] == "Programmer");
assert(group.localizedValue("Name", "ru@jargon") == "Кодер");
assert(group.localizedValue("Name", "ru_RU@jargon") == "Разработчик");
assert(group.localizedValue("Name", "ru") == "Программист");
assert(group.localizedValue("Name", "ru_RU.UTF-8") == "Разработчик");
assert(group.localizedValue("Name", "nonexistent locale") == "Programmer");
assert(group.localizedValue("Name", "de_DE@dialect") == "Programmierer");
assert(group.localizedValue("Name", "fr_FR.UTF-8") == "Programmeur");
assert(group.localizedValue("GenericName", "ru_RU") == "Программа");
assert(group.localizedValue("GenericName", "fr_FR") == "Program");
assert(group.localizedValue("GenericName", "fr_FR", No.nonLocaleFallback) is null);

See Also

Meta