locale: Take encoding into account when resolving strings
This commit is contained in:
parent
1d3cdbe6a1
commit
2c7e8ef76d
@ -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 = "";
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user