mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
error out if %1 %2 replacements are not contained in default english version
This commit is contained in:
30
src/stock.rs
30
src/stock.rs
@@ -129,8 +129,21 @@ impl Context {
|
||||
id: StockMessage,
|
||||
stockstring: String,
|
||||
) -> Result<(), Error> {
|
||||
self.translated_stockstrings
|
||||
.insert(id as usize, stockstring);
|
||||
if stockstring.contains("%1") && !id.fallback().contains("%1") {
|
||||
bail!(
|
||||
"translation {} contains invalid %1 placeholder, default is {}",
|
||||
stockstring,
|
||||
id.fallback()
|
||||
);
|
||||
}
|
||||
if stockstring.contains("%2") && !id.fallback().contains("%2") {
|
||||
bail!(
|
||||
"translation {} contains invalid %2 placeholder, default is {}",
|
||||
stockstring,
|
||||
id.fallback()
|
||||
);
|
||||
}
|
||||
self.translated_stockstrings.insert(id as usize, stockstring);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -268,6 +281,19 @@ mod tests {
|
||||
assert_eq!(t.ctx.stock_str(StockMessage::NoMessages), "xyz")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_stock_translation_wrong_replacements() {
|
||||
let mut t = dummy_context();
|
||||
assert!(t
|
||||
.ctx
|
||||
.set_stock_translation(StockMessage::NoMessages, "xyz %1$s ".to_string())
|
||||
.is_err());
|
||||
assert!(t
|
||||
.ctx
|
||||
.set_stock_translation(StockMessage::NoMessages, "xyz %2$s ".to_string())
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stock_str() {
|
||||
let t = dummy_context();
|
||||
|
||||
Reference in New Issue
Block a user