LC_LANG now works as a fallback properly

This commit is contained in:
2024-10-04 23:25:18 -04:00
parent c77c886290
commit 02c8ecde3e
3 changed files with 33 additions and 18 deletions

View File

@@ -37,25 +37,24 @@ export fn get_time() locale = get_locale("LC_TIME");
// overwritten later, so use [[dup]] to extend its lifetime.
export fn get_messages() locale = get_locale("LC_MESSAGES");
// Returns the locale to use for linguistic translations.
// The memory is statically allocated and must not be free'd. It may be
// overwritten later, so use [[dup]] to extend its lifetime.
export fn get_lang() locale = get_locale("LC_LANG");
// TODO
fn get_language() []locale;
fn get_locale(var: str) locale =
match (get_env_locale(var)) {
match (get_locale_no_fallback(var)) {
case let local: locale => yield local;
case =>
yield match (get_locale_conf_entry(var)) {
yield match (get_locale_no_fallback("LC_LANG")) {
case let local: locale => yield local;
case =>
yield c;
case => yield c; // TODO: get from LC_LANGUAGE
};
};
fn get_locale_no_fallback(var: str) (locale | errors::invalid) =
match (get_env_locale(var)) {
case let local: locale => yield local;
case => yield (get_locale_conf_entry(var));
};
fn get_env_locale(var: str) (locale | errors::invalid) =
match (os::getenv(var)) {
case let env: str => return parse(env);

View File

@@ -30,11 +30,3 @@ export fn get_time() locale = c;
// The memory is statically allocated and must not be free'd. It may be
// overwritten later, so use [[dup]] to extend its lifetime.
export fn get_messages() locale = c;
// Returns the locale to use for linguistic translations.
// The memory is statically allocated and must not be free'd. It may be
// overwritten later, so use [[dup]] to extend its lifetime.
export fn get_lang() locale = c;
// TODO
export fn get_language() []locale;