pub fn is_plural_key(key: &str) -> bool {
key.ends_with("(zero)")
|| key.ends_with("(one)")
|| key.ends_with("(two)")
|| key.ends_with("(few)")
|| key.ends_with("(many)")
|| key.ends_with("(other)")
}
pub fn extract_base_key(key: &str) -> String {
if let Some(pos) = key.rfind('(') {
key[..pos].to_string()
} else {
key.to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_plural_key() {
assert!(is_plural_key("items(one)"));
assert!(is_plural_key("items(other)"));
assert!(!is_plural_key("items"));
}
#[test]
fn test_extract_base_key() {
assert_eq!(extract_base_key("items(one)"), "items");
assert_eq!(
extract_base_key("ui.messages.count(other)"),
"ui.messages.count"
);
}
}