mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-27 16:51:15 -03:00
l10n: add initialize_localization function
This replaces `initialize_gettext`. It is only defined when the `localize-messages` feature is enabled, to avoid giving the impression that it does anything useful when the feature is disabled. With this change, Fluent will be initialized as well once it is added, without requiring any additional code for initialization. Closes #12190
This commit is contained in:
committed by
danielrainer
parent
5c36a1be1b
commit
fdef7c8689
@@ -385,7 +385,8 @@ fn throwing_main() -> i32 {
|
||||
set_libc_locales(/*log_ok=*/ false)
|
||||
};
|
||||
|
||||
fish::localization::initialize_gettext();
|
||||
#[cfg(feature = "localize-messages")]
|
||||
fish::localization::initialize_localization();
|
||||
|
||||
// Enable debug categories set in FISH_DEBUG.
|
||||
// This is in *addition* to the ones given via --debug.
|
||||
|
||||
@@ -930,7 +930,8 @@ fn throwing_main() -> i32 {
|
||||
unsafe {
|
||||
set_libc_locales(/*log_ok=*/ false)
|
||||
};
|
||||
crate::localization::initialize_gettext();
|
||||
#[cfg(feature = "localize-messages")]
|
||||
crate::localization::initialize_localization();
|
||||
env_init(None, true, false);
|
||||
|
||||
// Only set these here so you can't set them via the builtin.
|
||||
|
||||
@@ -289,7 +289,8 @@ fn throwing_main() -> i32 {
|
||||
set_interactive_session(true);
|
||||
topic_monitor_init();
|
||||
threads::init();
|
||||
crate::localization::initialize_gettext();
|
||||
#[cfg(feature = "localize-messages")]
|
||||
crate::localization::initialize_localization();
|
||||
env_init(None, true, false);
|
||||
reader_init(false);
|
||||
if let Some(features_var) = EnvStack::globals().get(L!("fish_features")) {
|
||||
|
||||
@@ -1,24 +1,7 @@
|
||||
#[cfg(feature = "localize-messages")]
|
||||
use crate::env::EnvStack;
|
||||
use fish_wchar::{L, WString, wstr};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[cfg(not(feature = "localize-messages"))]
|
||||
pub fn initialize_gettext() {}
|
||||
|
||||
/// This function only exists to provide a way for initializing gettext before an [`EnvStack`] is
|
||||
/// available. Without this, early error messages cannot be localized.
|
||||
#[cfg(feature = "localize-messages")]
|
||||
pub fn initialize_gettext() {
|
||||
let vars = EnvStack::new();
|
||||
env_stack_set_from_env!(vars, "LANGUAGE");
|
||||
env_stack_set_from_env!(vars, "LC_ALL");
|
||||
env_stack_set_from_env!(vars, "LC_MESSAGES");
|
||||
env_stack_set_from_env!(vars, "LANG");
|
||||
super::update_from_env(&vars);
|
||||
}
|
||||
|
||||
/// Use this function to localize a message.
|
||||
/// The [`MaybeStatic`] wrapper type allows avoiding allocating and leaking a new [`wstr`] when no
|
||||
/// localization is found and the input is returned, but as a static reference.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
mod gettext;
|
||||
pub use gettext::{
|
||||
LocalizableString, initialize_gettext, localizable_consts, localizable_string, wgettext,
|
||||
wgettext_fmt,
|
||||
LocalizableString, localizable_consts, localizable_string, wgettext, wgettext_fmt,
|
||||
};
|
||||
#[cfg(feature = "localize-messages")]
|
||||
mod settings;
|
||||
@@ -10,3 +9,18 @@
|
||||
list_available_languages, status_language, unset_from_status_language_builtin, update_from_env,
|
||||
update_from_status_language_builtin,
|
||||
};
|
||||
|
||||
#[cfg(feature = "localize-messages")]
|
||||
/// This function only exists to provide a way for initializing gettext before an `EnvStack` is
|
||||
/// available. Without this, early error messages cannot be localized.
|
||||
pub fn initialize_localization() {
|
||||
use crate::env::EnvStack;
|
||||
use fish_wchar::L;
|
||||
|
||||
let env = EnvStack::new();
|
||||
env_stack_set_from_env!(env, "LANGUAGE");
|
||||
env_stack_set_from_env!(env, "LC_ALL");
|
||||
env_stack_set_from_env!(env, "LC_MESSAGES");
|
||||
env_stack_set_from_env!(env, "LANG");
|
||||
update_from_env(&env);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user