-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace multiple comma-separated languages with 'mul' #1181
base: main
Are you sure you want to change the base?
Conversation
Thank you for your PR... We will have a look to it. That said, it's a mystery why the Wikipedia in Bambara is tagged as containing English content! |
Great, thanks so much.
In my example test case, I linked the Wikipedia in Bambara to both eng and bam language codes. And yes, it is mystery the way ted zim files show up on the website: Kiwix Library NoJX endpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For full consistency across the jsful and nojs versions you should also add a tooltip (via the title
attribute of the <div>
tag) that shows the languages names on hover.
src/html_dumper.cpp
Outdated
@@ -72,7 +72,7 @@ std::string HTMLDumper::dumpPlainHTML(kiwix::Filter filter) const | |||
contentId = urlEncode(nameMapper->getNameForId(bookId)); | |||
} catch (...) {} | |||
const auto bookDescription = bookObj.getDescription(); | |||
const auto langCode = bookObj.getCommaSeparatedLanguages(); | |||
const auto langCode = (bookObj.getCommaSeparatedLanguages().find(',') != std::string::npos) ? "mul" : bookObj.getCommaSeparatedLanguages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line. Please try to abide by the Thiruvananthapuram Convention on coding guidelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, comment addressed.
src/html_dumper.cpp
Outdated
const auto langList = bookObj.getCommaSeparatedLanguages(); | ||
const auto langCodes = kiwix::split(langList, ",", true, false); | ||
std::string langCode = ""; | ||
std::string languageSelfName = "Undetermind"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In order to avoid issues with translation, better initialize this variable to "???"
- The singular form used in the name of the variable can be misleading. I would rename it to
bookLanguages
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, addressed the comment.
src/html_dumper.cpp
Outdated
const auto bookIconUrl = rootLocation + "/catalog/v2/illustration/" + bookId + "/?size=48"; | ||
const auto tags = bookObj.getTags(); | ||
const auto downloadAvailable = (bookObj.getUrl() != ""); | ||
std::string faviconAttr = "style=background-image:url(" + bookIconUrl + ")"; | ||
std::string languageAttr = "title=" + languageSelfName + " aria-label=" + languageSelfName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values of HTML attributes should be quoted. This is best solved by updating static/templates/no_js_library_page.html
- instead of passing languageAttr
, the title
and aria-label
attributes should appear explicitly in the template and their value should be passed via a differently named parameter (as proposed in the other comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great feedback, addressed.
src/html_dumper.cpp
Outdated
const auto langCode = bookObj.getCommaSeparatedLanguages(); | ||
const auto langList = bookObj.getCommaSeparatedLanguages(); | ||
const auto langCodes = kiwix::split(langList, ",", true, false); | ||
std::string langCode = ""; | ||
std::string languageSelfName = "Undetermind"; | ||
|
||
if (langCodes.size() > 1) { | ||
std::vector<std::string> mulLanguages; | ||
langCode = "mul"; | ||
for (const auto& lang : langCodes) { | ||
mulLanguages.push_back(getLanguageSelfName(lang)); | ||
} | ||
languageSelfName = kiwix::join(mulLanguages, ","); | ||
} else if (langCodes.size() == 1) { | ||
langCode = langCodes[0]; | ||
languageSelfName = getLanguageSelfName(langCode); | ||
} | ||
languageSelfName = kiwix::toTitle(languageSelfName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function containing this change was already longer than typical human short-term memory can accommodate and this change makes the situation worse. Please encapsulate this enhancement in a couple of helper functions makeLanguagesShortString()
and makeLanguagesFullString()
so that the relevant code in dumpPlainHTML()
reads (BTW, note the use of Book::getLanguages()
instead of Book::getCommaSeparatedLanguages())
:
const auto bookLangs = book.getLanguages();
booksData.push_back(kainjow::mustache::object{
...
{"langShortString", makeLanguagesShortString(bookLangs)},
{"langFullString", makeLanguagesFullString(bookLangs)},
...
});
Note, that the switch from langCode
to langShortString
suggests a further UX enhancement (not for this PR, though, since it has to be discussed first) - if the list of languages is limited to two (or, maybe, even three) languages, all of their codes may be shown instead of being replaced with mul
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, adding the helper function is much cleaner.
src/html_dumper.cpp
Outdated
langCode = langCodes[0]; | ||
languageSelfName = getLanguageSelfName(langCode); | ||
} | ||
languageSelfName = kiwix::toTitle(languageSelfName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't toTitle()
be applied to each individual language?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the attached demo, I have already showcased an example using multiple languages, which is displaying as expected. However, for consistency, I have called the Kiwix Title API for each individual language.
Sorry for the late feedback, but from the user perspective, it should work exactly like on the js homepage https://library.kiwix.org/#q=&category=ted |
Thanks for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash your changes into a single commit
f12e219
to
da16aea
Compare
Addressed this comment. |
@kelson42 Requesting approval on the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ok to merge.
@kelson42 Can you please help me understand this failure ? |
Many things in the CI does not pass (and this is not only packaging). I can not merge like this. |
Thank you, I will look into the non packaging failure. |
da16aea
to
7e80399
Compare
- Refactored language code handling to replace multiple comma-separated values with 'mul'. - Single-language entries remain unchanged. - created the helper function to get the lang tag - ensured the consistent behaviour for js and nojs version for the kiwix library view
7e80399
to
fe1d3d9
Compare
I figured out nojs test were failing in the library server test. Now I have fixed them. |
@kelson42 @veloman-yunkan Requesting approval on the PR. |
@veloman-yunkan This is still failing, I guess we face something which might be unrelated to this PR? |
Thank you for approving and running these workflows. I looked into the testcase failure on the link below is the diff observed
If I look at the difference, it seems that the full language name is missing, indicating that the getLanguageSelfName function returned an empty response. As you mentioned, this issue doesn’t appear to be caused by my PR. @kelson42, could we proceed with merging this while we track the failure separately in a new GitHub issue? |
Fixes #724
Testing
Used this command to start the server locally. I ensured that the ZIM library have at least one book with multiple language codes.
Please check the image below to verify that it's working fine.