From 8d480c8b6d645882cfc83f87d7729f337b4c166d Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 13 Aug 2024 18:39:29 +0400 Subject: [PATCH] Introduced translateBookCategory() --- include/i18n.h | 2 ++ src/server/i18n.cpp | 9 +++++++++ static/skin/i18n/en.json | 18 ++++++++++++++++++ static/skin/i18n/qqq.json | 20 +++++++++++++++++++- static/skin/i18n/test.json | 18 ++++++++++++++++++ test/i18n.cpp | 14 ++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/include/i18n.h b/include/i18n.h index 381232985..0b15729e0 100644 --- a/include/i18n.h +++ b/include/i18n.h @@ -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 diff --git a/src/server/i18n.cpp b/src/server/i18n.cpp index 11e0641b8..f1975f405 100644 --- a/src/server/i18n.cpp +++ b/src/server/i18n.cpp @@ -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 diff --git a/static/skin/i18n/en.json b/static/skin/i18n/en.json index 3c7aa39eb..9345a1cb5 100644 --- a/static/skin/i18n/en.json +++ b/static/skin/i18n/en.json @@ -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" } diff --git a/static/skin/i18n/qqq.json b/static/skin/i18n/qqq.json index 9a8c5c144..f41c5d7ad 100644 --- a/static/skin/i18n/qqq.json +++ b/static/skin/i18n/qqq.json @@ -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" } diff --git a/static/skin/i18n/test.json b/static/skin/i18n/test.json index 29c2e9613..f997ef5e0 100644 --- a/static/skin/i18n/test.json +++ b/static/skin/i18n/test.json @@ -47,4 +47,22 @@ , "empty-search-results-page-header": "[I18N TESTING] No results were found for \"{{{SEARCH_PATTERN}}}\"" , "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]" } diff --git a/test/i18n.cpp b/test/i18n.cpp index 0cfca7576..a40e01ebf 100644 --- a/test/i18n.cpp +++ b/test/i18n.cpp @@ -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"); +}