gettext.rs: allow translating non-literal strings

A following commit will pass global string constants to the gettext macro.
This is not ideal because we might accidentally use the constants without
gettext (which we should never do). To fix that we might need to define a
macro per constant, or use a proc macro which is maybe not worth it.
This commit is contained in:
Johannes Altmanninger 2023-02-05 10:00:17 +01:00
parent 47cc98fd57
commit 29a2c4b718

View file

@ -15,7 +15,7 @@ pub fn wgettext_impl_do_not_use_directly(text: &[wchar_t]) -> &'static wstr {
/// Get a (possibly translated) string from a string literal. /// Get a (possibly translated) string from a string literal.
/// This returns a &'static wstr. /// This returns a &'static wstr.
macro_rules! wgettext { macro_rules! wgettext {
($string:literal) => { ($string:expr) => {
crate::wutil::gettext::wgettext_impl_do_not_use_directly( crate::wutil::gettext::wgettext_impl_do_not_use_directly(
crate::wchar_ffi::u32cstr!($string).as_slice_with_nul(), crate::wchar_ffi::u32cstr!($string).as_slice_with_nul(),
) )
@ -27,7 +27,7 @@ pub(crate) use wgettext;
/// The result is a WString. /// The result is a WString.
macro_rules! wgettext_fmt { macro_rules! wgettext_fmt {
( (
$string:literal, // format string $string:expr, // format string
$($args:expr),* // list of expressions $($args:expr),* // list of expressions
$(,)? // optional trailing comma $(,)? // optional trailing comma
) => { ) => {