mirror of
https://github.com/chatmail/core.git
synced 2026-04-18 22:16:30 +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,
|
id: StockMessage,
|
||||||
stockstring: String,
|
stockstring: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.translated_stockstrings
|
if stockstring.contains("%1") && !id.fallback().contains("%1") {
|
||||||
.insert(id as usize, stockstring);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +281,19 @@ mod tests {
|
|||||||
assert_eq!(t.ctx.stock_str(StockMessage::NoMessages), "xyz")
|
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]
|
#[test]
|
||||||
fn test_stock_str() {
|
fn test_stock_str() {
|
||||||
let t = dummy_context();
|
let t = dummy_context();
|
||||||
|
|||||||
Reference in New Issue
Block a user