diff --git a/locale/string.ha b/locale/string.ha index 073c736..261d749 100644 --- a/locale/string.ha +++ b/locale/string.ha @@ -18,10 +18,17 @@ export type string = [](locale, str); // Selects the most appropriate localized version of a [[string]] given a // [[locale]]. The matching algorithm used is the one specified by the -// XDG Desktop Entry Specification, §5. If no suitable version is found, an -// exact match with the C locale will be attempted. If there are none, void will -// be returned. Memory is borrowed from the input. -export fn string_resolve(strin: string, local: locale) (str | void) = { +// XDG Desktop Entry Specification, §5, with the addition of a preliminary step +// where a match against the exact locale is attempted. If no suitable version +// is found, an exact match with the C locale will be attempted. If there are +// none, void will be returned. Memory is borrowed from the input. +export fn string_resolve(strin: string, local: locale) (str | void) = { + // lang_COUNTRY@MODIFIER.ENCODING + match (string_resolve_exact(strin, local)) { + case let result: str => return result; + case => void; + }; + // lang_COUNTRY@MODIFIER let lang_country_modifier = local; lang_country_modifier.encoding = ""; @@ -74,6 +81,12 @@ export type strings = [](locale, []str); // [[locale]]. See the documentation for [[string_resolve]] for more // information. export fn strings_resolve(strins: strings, local: locale) ([]str | void) = { + // lang_COUNTRY@MODIFIER.ENCODING + match (strings_resolve_exact(strins, local)) { + case let result: []str => return result; + case => void; + }; + // lang_COUNTRY@MODIFIER let lang_country_modifier = local; lang_country_modifier.encoding = ""; diff --git a/locale/string_test.ha b/locale/string_test.ha index 746aab3..1dd77e0 100644 --- a/locale/string_test.ha +++ b/locale/string_test.ha @@ -7,6 +7,16 @@ (c, "c"), (parse("xx_XX")!, "xx_XX"), ], parse("xx_XX.UTF-8")!) as str == "xx_XX"); + assert(string_resolve([ + (c, "c"), + (parse("xx_XX")!, "xx_XX"), + (parse("xx_XX.UTF-8")!, "xx_XX2"), + ], parse("xx_XX")!) as str == "xx_XX"); + assert(string_resolve([ + (c, "c"), + (parse("xx_XX")!, "xx_XX"), + (parse("xx_XX.UTF-8")!, "xx_XX2"), + ], parse("xx_XX.UTF-8")!) as str == "xx_XX2"); assert(string_resolve([ (c, "c"), (parse("xx_XX")!, "xx_XX"),