diff --git a/src/bin/fish.rs b/src/bin/fish.rs index e919f3ed6..f399ed9ef 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -319,9 +319,8 @@ fn fish_parse_opt(args: &mut [WString], opts: &mut FishCmdOpts) -> ControlFlow { - let localized_description = p.description.localize(); - if localized_description.is_empty() { + if p.description.is_empty() { L!("").to_owned() } else { escape_string( - localized_description, + &p.description, EscapeStringStyle::Script( EscapeFlags::NO_PRINTABLES | EscapeFlags::NO_QUOTED, ), diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index 2ca4510b4..39800c5f2 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -1039,9 +1039,11 @@ fn builtin_false(_parser: &Parser, _streams: &mut IoStreams, _argv: &mut [&wstr] /// Strings not present in our repo would require a custom MO file for translation to be possible. fn builtin_gettext(_parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> BuiltinResult { for arg in &argv[1..] { - streams.out.append( - crate::wutil::LocalizableString::from_external_source((*arg).to_owned()).localize(), - ); + streams + .out + .append(crate::wutil::LocalizableString::from_external_source( + (*arg).to_owned(), + )); } Ok(SUCCESS) } diff --git a/src/complete.rs b/src/complete.rs index a7c0ba99a..1690a2f6d 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -1310,7 +1310,7 @@ fn complete_param_for_command( } let (arg_prefix, arg) = s.split_once(arg_offset); let first_new = self.completions.completions.len(); - self.complete_from_args(arg, &o.comp, o.desc.localize(), o.flags); + self.complete_from_args(arg, &o.comp, &o.desc, o.flags); for compl in &mut self.completions.completions[first_new..] { if compl.replaces_token() { compl.completion.insert_utfstr(0, arg_prefix); @@ -1341,7 +1341,7 @@ fn complete_param_for_command( if o.result_mode.force_files { has_force = true; } - self.complete_from_args(s, &o.comp, o.desc.localize(), o.flags); + self.complete_from_args(s, &o.comp, &o.desc, o.flags); } } @@ -1377,7 +1377,7 @@ fn complete_param_for_command( if o.result_mode.force_files { has_force = true; } - self.complete_from_args(s, &o.comp, o.desc.localize(), o.flags); + self.complete_from_args(s, &o.comp, &o.desc, o.flags); } } } @@ -1400,7 +1400,7 @@ fn complete_param_for_command( if o.option.is_empty() { use_files &= !o.result_mode.no_files; has_force |= o.result_mode.force_files; - self.complete_from_args(s, &o.comp, o.desc.localize(), o.flags); + self.complete_from_args(s, &o.comp, &o.desc, o.flags); } if !use_switches || s.is_empty() { @@ -1433,12 +1433,11 @@ fn complete_param_for_command( } } // It's a match. - let desc = o.desc.localize(); // Append a short-style option - if !self - .completions - .add(Completion::with_desc(o.option.clone(), desc.to_owned())) - { + if !self.completions.add(Completion::with_desc( + o.option.clone(), + o.desc.localize().to_owned(), + )) { return false; } } @@ -2414,7 +2413,7 @@ fn completion2string(index: &CompletionEntryIndex, o: &CompleteEntryOpt) -> WStr CompleteOptionType::DoubleLong => append_switch_short_arg(&mut out, 'l', &o.option), } - append_switch_short_arg(&mut out, 'd', o.desc.localize()); + append_switch_short_arg(&mut out, 'd', &o.desc); append_switch_short_arg(&mut out, 'a', &o.comp); for c in &o.conditions { append_switch_short_arg(&mut out, 'n', c); diff --git a/src/fds.rs b/src/fds.rs index c54b0568f..8d03169c2 100644 --- a/src/fds.rs +++ b/src/fds.rs @@ -145,7 +145,7 @@ pub fn make_autoclose_pipes() -> nix::Result { pipes } Err(err) => { - FLOG!(warning, PIPE_ERROR.localize()); + FLOG!(warning, &PIPE_ERROR); perror("pipe2"); return Err(err); } diff --git a/src/function.rs b/src/function.rs index 963f22151..8a3face09 100644 --- a/src/function.rs +++ b/src/function.rs @@ -419,7 +419,7 @@ pub fn copy_definition_lineno(&self) -> u32 { /// Note callers must provide the function name, since the function does not know its own name. pub fn annotated_definition(&self, name: &wstr) -> WString { let mut out = WString::new(); - let desc = self.description.localize(); + let desc = &self.description; let def = get_function_body_source(self); let handlers = event::get_function_handlers(name); diff --git a/src/wutil/gettext.rs b/src/wutil/gettext.rs index 550e85254..502f0e5ae 100644 --- a/src/wutil/gettext.rs +++ b/src/wutil/gettext.rs @@ -164,6 +164,18 @@ pub fn localize(&self) -> &'static wstr { } } +impl std::ops::Deref for LocalizableString { + type Target = wstr; + fn deref(&self) -> &Self::Target { + self.localize() + } +} + +impl AsRef for LocalizableString { + fn as_ref(&self) -> &wstr { + self + } +} impl std::fmt::Display for LocalizableString { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.localize())