Introduced translateBookCategory()

This commit is contained in:
Veloman Yunkan 2024-08-13 18:39:29 +04:00
parent 82ff88f5d8
commit 8d480c8b6d
6 changed files with 80 additions and 1 deletions

View File

@ -85,6 +85,8 @@ inline ParameterizedMessage nonParameterizedMessage(const std::string& msgId)
return ParameterizedMessage(msgId, noParams);
}
std::string translateBookCategory(const std::string& lang, const std::string& category);
} // namespace kiwix
#endif // KIWIX_I18N

View File

@ -193,4 +193,13 @@ std::string selectMostSuitableLanguage(const UserLangPreferences& prefs)
return bestLangSoFar;
}
std::string translateBookCategory(const std::string& lang, const std::string& category)
{
try {
return getTranslatedString(lang, "book-category." + category);
} catch (...) {
return category;
}
}
} // namespace kiwix

View File

@ -60,4 +60,22 @@
, "preview-book": "Preview"
, "non-translated-text": "{{MSG}}"
, "unknown-error": "Unknown error"
, "book-category.gutenberg": "Gutenberg"
, "book-category.iFixit": "iFixit"
, "book-category.mooc": "MOOC"
, "book-category.phet": "Phet"
, "book-category.stack_exchange": "Stack Exchange"
, "book-category.ted": "Ted"
, "book-category.vikidia": "Vikidia"
, "book-category.wikibooks": "Wikibooks"
, "book-category.wikihow": "wikiHow"
, "book-category.wikinews": "Wikinews"
, "book-category.wikipedia": "Wikipedia"
, "book-category.wikiquote": "Wikiquote"
, "book-category.wikisource": "Wikisource"
, "book-category.wikispecies": "Wikispecies"
, "book-category.wikiversity": "Wikiversity"
, "book-category.wikivoyage": "Wikivoyage"
, "book-category.wiktionary": "Wiktionary"
, "book-category.other": "Other"
}

View File

@ -62,5 +62,23 @@
"download-links-title": "Title for no-js download page",
"preview-book": "Tooltip of book-tile leading to the book",
"non-translated-text": "{{ignored}}\nUsed to display text that is generated at runtime and cannot be translated. Nothing to translate about this one.",
"unknown-error": "Unknown error"
"unknown-error": "Unknown error",
"book-category.gutenberg": "Name for the category of books from the Gutenberg project",
"book-category.iFixit": "Name for the category of iFixit books",
"book-category.mooc": "Name for the category of MOOC books",
"book-category.phet": "Name for the category of Phet books",
"book-category.stack_exchange": "Name for the category of books from the Stack Exchange network books",
"book-category.ted": "Name for the category of Ted books",
"book-category.vikidia": "Name for the category of Vikidia books",
"book-category.wikibooks": "Name for the category of Wikibooks books books",
"book-category.wikihow": "Name for the category of wikiHow books",
"book-category.wikinews": "Name for the category of Wikinews books",
"book-category.wikipedia": "Name for the category of Wikipedia books",
"book-category.wikiquote": "Name for the category of Wikiquote books",
"book-category.wikisource": "Name for the category of Wikisource books",
"book-category.wikispecies": "Name for the category of Wikispecies books",
"book-category.wikiversity": "Name for the category of Wikiversity books",
"book-category.wikivoyage": "Name for the category of Wikivoyage books",
"book-category.wiktionary": "Name for the category of Wiktionary books",
"book-category.other": "Books not belonging to any special category are listed under this one"
}

View File

@ -47,4 +47,22 @@
, "empty-search-results-page-header": "[I18N TESTING] No results were found for <b>\"{{{SEARCH_PATTERN}}}\"</b>"
, "search-result-book-info": "from [I18N TESTING] {{BOOK_TITLE}}"
, "word-count": "{{COUNT}} [I18N TESTING] words"
, "book-category.gutenberg": "[I18N] Gutenberg [TESTING]"
, "book-category.iFixit": "[I18N] iFixit [TESTING]"
, "book-category.mooc": "[I18N] MOOC [TESTING]"
, "book-category.phet": "[I18N] Phet [TESTING]"
, "book-category.stack_exchange": "[I18N] Stack Exchange [TESTING]"
, "book-category.ted": "[I18N] Ted [TESTING]"
, "book-category.vikidia": "[I18N] Vikidia [TESTING]"
, "book-category.wikibooks": "[I18N] Wikibooks [TESTING]"
, "book-category.wikihow": "[I18N] wikiHow [TESTING]"
, "book-category.wikinews": "[I18N] Wikinews [TESTING]"
, "book-category.wikipedia": "[I18N] Wikipedia [TESTING]"
, "book-category.wikiquote": "[I18N] Wikiquote [TESTING]"
, "book-category.wikisource": "[I18N] Wikisource [TESTING]"
, "book-category.wikispecies": "[I18N] Wikispecies [TESTING]"
, "book-category.wikiversity": "[I18N] Wikiversity [TESTING]"
, "book-category.wikivoyage": "[I18N] Wikivoyage [TESTING]"
, "book-category.wiktionary": "[I18N] Wiktionary [TESTING]"
, "book-category.other": "[I18N] Other [TESTING]"
}

View File

@ -48,3 +48,17 @@ TEST(ParameterizedMessage, messagesWithParameters)
EXPECT_EQ(msg.getText("test"), "Filter [I18N] by [TESTING] tag \"\"");
}
}
TEST(I18n, translateBookCategory)
{
EXPECT_EQ(translateBookCategory("en", "ted"), "Ted");
EXPECT_EQ(translateBookCategory("test", "ted"), "[I18N] Ted [TESTING]");
EXPECT_EQ(translateBookCategory("en", "stack_exchange"), "Stack Exchange");
EXPECT_EQ(translateBookCategory("test", "stack_exchange"), "[I18N] Stack Exchange [TESTING]");
// unknown categories are simply not translated
EXPECT_EQ(translateBookCategory("en", "Qwerty"), "Qwerty");
EXPECT_EQ(translateBookCategory("test", "Qwerty"), "Qwerty");
}