From dd118df612dee0603d19fabcf655c8363097caa6 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 4 Jul 2021 15:28:27 +0400 Subject: [PATCH] Got rid of langMap in opds_dumper.cpp Language code to human friendly name translation is now done with the help of the ICU library. It works if the line ``` -include $(LANGSRCDIR)/resfiles.mk ``` in the file `source/data/Makefile.in` of the icu4c dependency is not commented out. Currently, the said line is commented out (along with some other include's) by the `icu4c_custom_data.patch` patch of the `kiwix-build` tool. --- src/opds_dumper.cpp | 24 ++++++++++++------------ test/server.cpp | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index 65ea3c526..68bffbe13 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -84,22 +84,22 @@ BookData getBookData(const Library* library, const std::vector& boo return bookData; } -struct LangInfo { - std::string selfName, englishName; -}; - -std::map langMap = { - {"eng", { "English", "English"} }, - {"fra", { "Français", "French"} }, - {"rus", { "Русский", "Russian"} }, -}; - std::string getLanguageSelfName(const std::string& lang) { - return langMap.at(lang).selfName; + const icu::Locale locale(lang.c_str()); + icu::UnicodeString ustring; + locale.getDisplayLanguage(locale, ustring); + std::string result; + ustring.toUTF8String(result); + return result; }; std::string getLanguageEnglishName(const std::string& lang) { - return langMap.at(lang).englishName; + const icu::Locale locale(lang.c_str()); + icu::UnicodeString ustring; + locale.getDisplayLanguage(icu::Locale("en"), ustring); + std::string result; + ustring.toUTF8String(result); + return result; }; } // unnamed namespace diff --git a/test/server.cpp b/test/server.cpp index 110486198..77dd92a6c 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -1043,7 +1043,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages) All entries in English. - Français + français fra All entries in French. - Русский + русский rus