LC_LANG now works as a fallback properly
This commit is contained in:
parent
c77c886290
commit
02c8ecde3e
24
cmd/locale/main.ha
Normal file
24
cmd/locale/main.ha
Normal file
@ -0,0 +1,24 @@
|
||||
use fmt;
|
||||
use locale;
|
||||
|
||||
export fn main() void = {
|
||||
let ctype = locale::format(locale::get_ctype());
|
||||
defer free(ctype);
|
||||
let collate = locale::format(locale::get_collate());
|
||||
defer free(collate);
|
||||
let monetary = locale::format(locale::get_monetary());
|
||||
defer free(monetary);
|
||||
let numeric = locale::format(locale::get_numeric());
|
||||
defer free(numeric);
|
||||
let time = locale::format(locale::get_time());
|
||||
defer free(time);
|
||||
let messages = locale::format(locale::get_messages());
|
||||
defer free(messages);
|
||||
|
||||
fmt::printf("LC_CTYPE={}\n", ctype)!;
|
||||
fmt::printf("LC_COLLATE={}\n", collate)!;
|
||||
fmt::printf("LC_MONETARY={}\n", monetary)!;
|
||||
fmt::printf("LC_NUMERIC={}\n", numeric)!;
|
||||
fmt::printf("LC_TIME={}\n", time)!;
|
||||
fmt::printf("LC_MESSAGES={}\n", messages)!;
|
||||
};
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user