Skip to content

Commit

Permalink
Got rid of langMap in opds_dumper.cpp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
veloman-yunkan committed Jul 4, 2021
1 parent e40547f commit 0198cda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/opds_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ BookData getBookData(const Library* library, const std::vector<std::string>& boo
return bookData;
}

struct LangInfo {
std::string selfName, englishName;
};

std::map<std::string, LangInfo> 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
Expand Down
4 changes: 2 additions & 2 deletions test/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
<content type="text">All entries in English.</content>
</entry>
<entry>
<title>Français</title>
<title>français</title>
<dc:language>fra</dc:language>
<link rel="subsection"
href="/catalog/v2/entries?lang=fra"
Expand All @@ -1053,7 +1053,7 @@ TEST_F(LibraryServerTest, catalog_v2_languages)
<content type="text">All entries in French.</content>
</entry>
<entry>
<title>Русский</title>
<title>русский</title>
<dc:language>rus</dc:language>
<link rel="subsection"
href="/catalog/v2/entries?lang=rus"
Expand Down

0 comments on commit 0198cda

Please sign in to comment.