Files
driftwood/src/i18n.rs

35 lines
1008 B
Rust

/// Mark a string for translation.
/// Currently a passthrough; will use gettext when locale support is wired up.
pub fn i18n(msgid: &str) -> String {
msgid.to_string()
}
/// Translate a string with singular/plural forms.
pub fn ni18n(singular: &str, plural: &str, n: u32) -> String {
if n == 1 {
singular.to_string()
} else {
plural.to_string()
}
}
/// Translate a string and replace named placeholders.
pub fn i18n_f(msgid: &str, args: &[(&str, &str)]) -> String {
let mut result = msgid.to_string();
for (key, value) in args {
result = result.replace(key, value);
}
result
}
/// Translate a string with singular/plural forms and named placeholders.
#[allow(dead_code)]
pub fn ni18n_f(singular: &str, plural: &str, n: u32, args: &[(&str, &str)]) -> String {
let base = if n == 1 { singular } else { plural };
let mut result = base.to_string();
for (key, value) in args {
result = result.replace(key, value);
}
result
}