diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-06-08 01:43:08 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-06-08 01:44:03 +0200 |
| commit | 6bd0c135a877627c2d730649824dee7d5bfa6b08 (patch) | |
| tree | 66f784649904e1561078d5a964e685f0d821da01 /server/src/tests.rs | |
| parent | a60c0f58470f78545544d01d525eae481511abec (diff) | |
Add translation module
Reads from a list of grit files, all strings and their translations.
Diffstat (limited to 'server/src/tests.rs')
| -rw-r--r-- | server/src/tests.rs | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/server/src/tests.rs b/server/src/tests.rs index cc71bf3..5f956fb 100644 --- a/server/src/tests.rs +++ b/server/src/tests.rs @@ -1,3 +1,4 @@ +use pretty_assertions::assert_eq; use rocket::figment::util::map; use rocket::figment::value::{Map, Value}; use rocket::http::{ContentType, Header, Status}; @@ -5,11 +6,13 @@ use rocket::local::asynchronous::{Client, LocalRequest}; use sqlx::mysql::{MySql, MySqlConnectOptions, MySqlPoolOptions}; use sqlx::{Acquire, Executor, Pool}; use std::fmt::Display; +use std::path::PathBuf; use std::sync::OnceLock; use stdext::function_name; use testdir::testdir; use crate::api_model; +use crate::trans; struct RealIP(&'static str); @@ -966,3 +969,197 @@ async fn test_user_keys_del() { assert_eq!(user_keys.more, false); assert_eq!(user_keys.keys.len(), 0); } + +#[tokio::test] +async fn test_collect_strings() { + let base = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("common/src/testdata/grit"); + let mut strings = trans::collect_strings(base, vec!["base.grd".to_string()]) + .await + .unwrap(); + + // Sort translations before comparison, they come unsorted from collect_strings. + for string in &mut strings { + string + .translations + .sort_by(|a, b| a.language.cmp(&b.language)); + } + + assert_eq!( + strings, + vec![ + api_model::LocalizationString { + id: "IDS_EXTRA".to_string(), + // TODO: Should be extra.grpd + file: "base.grd".to_string(), + description: "Extra title".to_string(), + meaning: "".to_string(), + source: "Extra title".to_string(), + placeholders: vec![], + placeholder_offset: vec![], + translation_id: 3567801202192813433, + translations: vec![], + }, + api_model::LocalizationString { + id: "IDS_BOOKMARKS_FRAGMENT_TITLE".to_string(), + file: "base.grd".to_string(), + description: "Title which is shown on the main bookmarks view.".to_string(), + meaning: "".to_string(), + source: "Bookmarks".to_string(), + placeholders: vec![], + placeholder_offset: vec![], + translation_id: 8820817407110198400, + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "Bookmarks".to_string(), + placeholder_offset: vec![], + }, + api_model::TranslationString { + language: "my".to_string(), + translation: "ဝက်ဘ်လိပ်စာ မှတ်ထားမှုများ".to_string(), + placeholder_offset: vec![], + }, + api_model::TranslationString { + language: "my-zg".to_string(), + translation: "ဝက္ဘ္လိပ္စာ မွတ္ထားမွုမ်ား".to_string(), + placeholder_offset: vec![], + }, + api_model::TranslationString { + language: "sv".to_string(), + translation: "Bokmärken".to_string(), + placeholder_offset: vec![], + }, + ], + }, + api_model::LocalizationString { + id: "IDS_GENERIC_WELCOME".to_string(), + file: "base.grd".to_string(), + description: "Generic welcome string.".to_string(), + meaning: "".to_string(), + source: "Welcome to ".to_string(), + placeholders: vec![ + api_model::LocalizationPlaceholder { + id: "STRING".to_string(), + content: "%1$s".to_string(), + example: "Opera".to_string(), + }, + ], + placeholder_offset: vec![11], + translation_id: 8443102241046796905, + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "Welcome to ".to_string(), + placeholder_offset: vec![11], + }, + api_model::TranslationString { + language: "my".to_string(), + translation: " မှ ကြိုဆိုပါသည်".to_string(), + placeholder_offset: vec![0], + }, + api_model::TranslationString { + language: "my-zg".to_string(), + translation: " မွ ႀကိဳဆိုပါသည္".to_string(), + placeholder_offset: vec![0], + }, + api_model::TranslationString { + language: "sv".to_string(), + translation: "Välkommen till ".to_string(), + placeholder_offset: vec![16], + }, + ], + }, + api_model::LocalizationString { + id: "IDS_START_TERMS".to_string(), + file: "base.grd".to_string(), + description: "First startup information about the license and privacy terms.".to_string(), + meaning: "".to_string(), + source: "By using this application you are agreeing to Opera's Terms of Service. Also, you can learn how Opera handles and protects your data in our Privacy Statement.".to_string(), + placeholders: vec![ + api_model::LocalizationPlaceholder { + id: "TOS_BEGIN".to_string(), + content: "<tos>".to_string(), + example: "".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "TOS_END".to_string(), + content: "</tos>".to_string(), + example: "".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "PRIVACY_BEGIN".to_string(), + content: "<privacy>".to_string(), + example: "".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "PRIVACY_END".to_string(), + content: "</privacy>".to_string(), + example: "".to_string(), + }, + ], + placeholder_offset: vec![54, 70, 140, 157], + translation_id: 2466140279568640908, + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "By using this application you are agreeing to Opera's Terms of Service. Also, you can learn how Opera handles and protects your data in our Privacy Statement.".to_string(), + placeholder_offset: vec![54, 70, 140, 157], + }, + api_model::TranslationString { + language: "my".to_string(), + translation: "ဤအပလီကေးရှင်းကို အသုံးပြုခြင်းဖြင့် သင်သည် Opera ၏ ဝန်ဆောင်မှုစည်းမျဉ်းများ ကို သဘောတူရာ ရောက်ပါသည်။ ထို့အပြင် ကျွန်ုပ်တို့၏ကိုယ်ရေးလုံခြုံမှု ထုတ်ပြန်ချက် ထဲတွင် သင့်ဒေတာများကို Opera ၏ ကိုင်တွယ်ပုံနှင့် ကာကွယ်ပုံတို့ကိုလည်း လေ့လာနိုင်သည်။".to_string(), + placeholder_offset: vec![133, 205, 342, 433], + }, + api_model::TranslationString { + language: "my-zg".to_string(), + translation: "ဤအပလီေကးရွင္းကို အသုံးျပဳျခင္းျဖင့္ သင္သည္ Opera ၏ ဝန္ေဆာင္မွုစည္းမ်ဥ္းမ်ား ကို သေဘာတူရာ ေရာက္ပါသည္။ ထို႔အျပင္ ကၽြန္ုပ္တို႔၏ကိုယ္ေရးလုံျခဳံမွု ထုတ္ျပန္ခ်က္ ထဲတြင္ သင့္ေဒတာမ်ားကို Opera ၏ ကိုင္တြယ္ပုံႏွင့္ ကာကြယ္ပုံတို႔ကိုလည္း ေလ့လာနိုင္သည္။".to_string(), + placeholder_offset: vec![133, 205, 342, 433], + }, + api_model::TranslationString { + language: "sv".to_string(), + translation: "I och med din användning av det här programmet samtycker du till Operas Licensvillkor. Du kan också läsa om hur Opera hanterar och skyddar dina data i vårt Sekretessmeddelande.".to_string(), + placeholder_offset: vec![74, 87, 161, 180], + }, + ], + }, + api_model::LocalizationString { + id: "IDS_BOOKMARKS_FOLDERS_DELETED".to_string(), + file: "base.grd".to_string(), + description: "Message which is shown when one or more folders have been deleted from the bookmark list.".to_string(), + meaning: "".to_string(), + source: "{BOOKMARKS, plural,\n one { folder deleted}\n few { folders deleted}\n many { folders deleted}\n other { folders deleted}}".to_string(), + placeholders: vec![ + api_model::LocalizationPlaceholder { + id: "COUNT".to_string(), + content: "%1$d".to_string(), + example: "1".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "COUNT".to_string(), + content: "%1$d".to_string(), + example: "15".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "COUNT".to_string(), + content: "%1$d".to_string(), + example: "100".to_string(), + }, + api_model::LocalizationPlaceholder { + id: "COUNT".to_string(), + content: "%1$d".to_string(), + example: "42".to_string(), + }, + ], + placeholder_offset: vec![34, 65, 98, 132], + translation_id: 7770247413830876286, + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "{BOOKMARKS, plural,\n one { folder deleted}\n few { folders deleted}\n many { folders deleted}\n other { folders deleted}}".to_string(), + placeholder_offset: vec![35, 67, 101, 136], + }, + ], + }, + ], + ) +} |
