locale: Fix string_resolve
This commit is contained in:
parent
3f88e96395
commit
1055173246
@ -3,7 +3,9 @@ export type string = [](locale, str);
|
|||||||
|
|
||||||
// Selects the most appropriate localized version of a [[string]] given a
|
// Selects the most appropriate localized version of a [[string]] given a
|
||||||
// [[locale]]. The matching algorithm used is the one specified by the
|
// [[locale]]. The matching algorithm used is the one specified by the
|
||||||
// XDG Desktop Entry Specification, §5. Memory is borrowed from the input.
|
// 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) = {
|
export fn string_resolve(strin: string, local: locale) (str | void) = {
|
||||||
// The matching is done as follows. If LC_MESSAGES is of the form
|
// The matching is done as follows. If LC_MESSAGES is of the form
|
||||||
// lang_COUNTRY.ENCODING@MODIFIER, then it will match a key of the form
|
// lang_COUNTRY.ENCODING@MODIFIER, then it will match a key of the form
|
||||||
@ -19,41 +21,47 @@ export fn string_resolve(strin: string, local: locale) (str | void) = {
|
|||||||
// If LC_MESSAGES just has a lang field, then it will do a straight
|
// If LC_MESSAGES just has a lang field, then it will do a straight
|
||||||
// match to a key with a similar value.
|
// match to a key with a similar value.
|
||||||
|
|
||||||
|
// lang_COUNTRY@MODIFIER
|
||||||
let lang_country_modifier = local;
|
let lang_country_modifier = local;
|
||||||
lang_country_modifier.encoding = "";
|
lang_country_modifier.encoding = "";
|
||||||
match (string_resolve_exact(strin, lang_country_modifier)) {
|
match (string_resolve_exact(strin, lang_country_modifier)) {
|
||||||
case let index: size => return index;
|
case let result: str => return result;
|
||||||
case => void;
|
case => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// lang_COUNTRY
|
||||||
let lang_country = local;
|
let lang_country = local;
|
||||||
lang_country.modifier = "";
|
lang_country.modifier = "";
|
||||||
match (string_resolve_exact(strin, lang_country)) {
|
match (string_resolve_exact(strin, lang_country)) {
|
||||||
case let index: size => return index;
|
case let result: str => return result;
|
||||||
case => void;
|
case => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// lang@MODIFIER
|
||||||
let lang_modifier = lang_country_modifier;
|
let lang_modifier = lang_country_modifier;
|
||||||
lang_modifier.country = "";
|
lang_modifier.country = "";
|
||||||
match (string_resolve_exact(strin, lang_modifier)) {
|
match (string_resolve_exact(strin, lang_modifier)) {
|
||||||
case let index: size => return index;
|
case let result: str => return result;
|
||||||
case => void;
|
case => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// lang
|
||||||
let lang = lang_modifier;
|
let lang = lang_modifier;
|
||||||
lang.modifier = "";
|
lang.modifier = "";
|
||||||
match (string_resolve_exact(strin, lang)) {
|
match (string_resolve_exact(strin, lang)) {
|
||||||
case let index: size => return index;
|
case let result: str => return result;
|
||||||
|
case => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
// fallback to c locale
|
||||||
|
match (string_resolve_exact(strin, c)) {
|
||||||
|
case let result: str => return result;
|
||||||
case => void;
|
case => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
return void;
|
return void;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn string_resolve_exact(strin: string, local: locale) (size | void) = {
|
fn string_resolve_exact(strin: string, local: locale) (str | void) = {
|
||||||
let index = 0z;
|
for (let pair .. strin) if(equal(pair.0, local)) return pair.1;
|
||||||
for (let pair .. strn) {
|
|
||||||
if(equal(pair.1, local)) return index;
|
|
||||||
index += 1;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user