From ab8a7147b4d9f8136c83f26c7e57493d60f06afe Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Tue, 16 Jan 2024 23:07:36 +0200 Subject: [PATCH] Add test that checks that all items have en i18n --- voxygen/i18n-helpers/src/lib.rs | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/voxygen/i18n-helpers/src/lib.rs b/voxygen/i18n-helpers/src/lib.rs index 5751cfab38..c7c1bcd5da 100644 --- a/voxygen/i18n-helpers/src/lib.rs +++ b/voxygen/i18n-helpers/src/lib.rs @@ -262,3 +262,43 @@ fn insert_alias(you: bool, info: PlayerInfo, localization: &Localization) -> Str (true, true) => format!("{}{}", MOD_SPACING, &localization.get_msg(YOU),), } } + +#[cfg(test)] +mod tests { + #[allow(unused)] use super::*; + use common::comp::{ + inventory::item::{all_items_expect, ItemDesc, ItemI18n}, + Content, + }; + use i18n::LocalizationHandle; + + // item::tests::ensure_item_localization tests that we have Content for + // each item. This tests that we actually have at least English translation + // for this Content. + #[test] + fn test_item_text() { + let manifest = ItemI18n::new_expect(); + let localization = LocalizationHandle::load_expect("en").read(); + let items = all_items_expect(); + + for item in items { + let (name, desc) = item.i18n(&manifest); + + // check i18n for item name + let Content::Key(key) = name else { + panic!("name is expected to be Key, please fix the test"); + }; + localization.try_msg(&key).unwrap_or_else(|| { + panic!("'{key}' name doesn't have i18n"); + }); + + // check i18n for item desc + let Content::Attr(key, attr) = desc else { + panic!("desc is expected to be Attr, please fix the test"); + }; + localization.try_attr(&key, &attr).unwrap_or_else(|| { + panic!("'{key}' description doesn't have i18n"); + }); + } + } +}