i18n: per-network locale (en/es/fr) for karma replies and the web board
All checks were successful
ci / check (push) Successful in 45s
All checks were successful
ci / check (push) Successful in 45s
This commit is contained in:
parent
f290554325
commit
739fc8ad94
11 changed files with 406 additions and 115 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use rustbot::bot::module::{Action, Chat, Command, Module};
|
||||
use rustbot::bot::modules::karma::{extract_reason, format_event, parse_changes, Karma};
|
||||
use rustbot::i18n::Locale;
|
||||
|
||||
fn chat<'a>(sender: &'a str, text: &'a str) -> Chat<'a> {
|
||||
Chat {
|
||||
|
|
@ -208,3 +209,53 @@ fn on_message_appends_to_the_event_log() {
|
|||
let _ = std::fs::remove_file(&path);
|
||||
let _ = std::fs::remove_file(&log);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spanish_reason_connector_is_stripped() {
|
||||
assert_eq!(
|
||||
extract_reason("rust++ porque es rápido").as_deref(),
|
||||
Some("es rápido")
|
||||
);
|
||||
assert_eq!(
|
||||
extract_reason("rust++ por los tests").as_deref(),
|
||||
Some("los tests")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replies_in_spanish_for_es_locale() {
|
||||
let path = std::env::temp_dir().join("rubot-test-karma-es.json");
|
||||
let log = std::env::temp_dir().join("rubot-test-karma-es.events.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let _ = std::fs::remove_file(&log);
|
||||
let mut k = Karma::with_path_locale(path.clone(), Locale::Es);
|
||||
k.on_message(&chat("alice", "rust++ porque es bueno"));
|
||||
// report
|
||||
let cmd = Command {
|
||||
sender: "z",
|
||||
reply_to: "#argentina",
|
||||
name: "karma",
|
||||
args: &["rust"],
|
||||
prefix: ">",
|
||||
network: "libera",
|
||||
};
|
||||
let r = match k.on_command(&cmd).as_slice() {
|
||||
[Action::Reply(s)] => visible(s),
|
||||
_ => panic!("expected one reply"),
|
||||
};
|
||||
assert!(r.contains("tiene 1 de karma"), "{r}");
|
||||
assert!(r.contains("(#1 de 1)"), "{r}");
|
||||
assert!(r.contains("último: \"es bueno\""), "{r}");
|
||||
// unseen thing
|
||||
let cmd2 = Command {
|
||||
args: &["ghost"],
|
||||
..cmd
|
||||
};
|
||||
let ghost = match k.on_command(&cmd2).as_slice() {
|
||||
[Action::Reply(s)] => visible(s),
|
||||
_ => panic!("expected one reply"),
|
||||
};
|
||||
assert!(ghost.contains("todavía no hay karma para"), "{ghost}");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let _ = std::fs::remove_file(&log);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue