pub(crate) const GETTEXT_PACKAGE: &str = "udisks2";
pub(crate) fn dpgettext<T, U>(msgctxt: T, msgid: U) -> String
where
T: Into<String>,
U: Into<String>,
{
const MSG_SEPARATOR: char = '\u{004}';
gettextrs::dgettext(
GETTEXT_PACKAGE,
format!("{}{MSG_SEPARATOR}{}", msgctxt.into(), msgid.into()),
)
}
pub(crate) fn pgettext_f(
msgctxt: &str,
format: &str,
args: impl IntoIterator<Item = impl AsRef<str>>,
) -> String {
let s = gettextrs::pgettext(msgctxt, format.replace("{}", "%s"));
arg_replace(s, args)
}
pub(crate) fn gettext_f(format: &str, args: impl IntoIterator<Item = impl AsRef<str>>) -> String {
let s = gettextrs::gettext(format.replace("{}", "%s"));
arg_replace(s, args)
}
fn arg_replace(mut s: String, args: impl IntoIterator<Item = impl AsRef<str>>) -> String {
for arg in args {
s = s.replacen("%s", arg.as_ref(), 1);
}
s
}