Translated language name lists in global & vocab search bar#1844
Translated language name lists in global & vocab search bar#1844
Conversation
osma
left a comment
There was a problem hiding this comment.
Looks good, mostly things are working, but I have a few suggestions for changes:
- The "All languages" option should be last, after the languages, not first, just like in Skosmos 2.
- The "All languages" option could be called "Any language" in English, just like in Skosmos 2.
- I suggest renaming the variables
$searchLangListand$vocabSearchLangList(php),search_lang_list(twig) andsearchLangStrings(SKOSMOS object). These are indeed used for the search language dropdown (along with the "all"/"any" option), but I think it would be better to call these "content languages" so they align with e.g. thecontent_langandclangvariable names. For examplesearchLangStringscould be calledcontentLanguages. - The SKOSMOS object now has both
languageOrderandsearchLangStringsfields, for slightly different reasons, but both containing a list of languages. Would it be possible to get rid oflanguageOrderand instead ordersearchLangStrings/contentLanguagesin the right order? - This isn't a new bug in this PR (found by @UnniKohonen ), but I think it needs to be fixed: in the vocabulary search bar, selecting the "All languages" (or "Any language") option causes SKOSMOS.content_lang to be set to "all", which breaks the sidebar components that expect a language tag and not this special value:
Skosmos/resource/js/vocab-search.js
Line 198 in 072d67f
… Get rid of the languageOrder parameter as duplicate information.
osma
left a comment
There was a problem hiding this comment.
Avoiding passing languageOrder separately is much better now. However, I have some doubts about parseVocabularyLanguageOrder:
- getLanguageOrder should be given the current content language, not null
- $languageOrder can never be null so the if is_null check is useless (in my understanding)
- no need to assign to a variable in the end, could just return the expression directly
I think we need a PHPUnit test (or several) for this method, because it does non-trivial things and I suspect that it could be buggy and/or contain dead code.
Other comments:
I noticed that $langList (php) and lang_list (twig) variables are still declared within WebController::invokeGlobalSearch even though they are not used in Twig templates. They should be deleted.
I have some suggestions for renaming variables / methods to make them clearer:
allLanguagesmethod ->anyLanguageallLanguegesEntry->anyLanguageEntry(note the typo in the current name)$contentLangList->$contentLanguagescontent_lang_list->content_languages$sortedContentLangList->$contentLanguagesor$sortedContentLanguages
As a final nitpick, the formattedList variable in both the formatLangStrings methods is useless and the value could just be returned directly.
src/controller/WebController.php
Outdated
| private function parseVocabularyLanguageOrder($vocab) | ||
| { | ||
| $vocabContentLangList = array_flip($vocab->getConfig()->getLanguages()); | ||
| $languageOrder = $vocab->getConfig()->getLanguageOrder(null); |
There was a problem hiding this comment.
Why use null here as an argument? It should be the current content language
There was a problem hiding this comment.
If an argument is passed for the getLanguageOrder, this language is put in the front of the list of returned language codes. If null is passed, the language order is returned as it's declared in the configuration. So, if the language parameter is passed as a parameter in this piece of code, we will get a situation where in the UI the current language is always shown as the first option in the language dropdown. I'm sure that's not a feature we want. I thought the expected behaviour is to return the languages in the order the skosmos:languageOrder is configured in config.ttl.
There was a problem hiding this comment.
I see. Practically it makes sense to get the desired end result, but feels like a hack. The method is declared as getLanguageOrder($clang) with a docstring @param string $clang. I suggest changing it so it explicitly allows null values (maybe $clang could default to null, so it could be just omitted in this call) and the method should not return the null value within the array as it currently does.
osma
left a comment
There was a problem hiding this comment.
There's a problem with the new PHPUnit test. I suggested how to fix it in a comment.
Otherwise looks good, though I dislike the variable/method names *LangStrings (within the SKOSMOS object and in Vue code); I don't think the value being a string is a relevant aspect and I would rather rename them to *Languages, like this:
formatLangStrings->formatLanguageslangStrings->languagescontentLangStrings->contentLanguages
But I've already nitpicked a lot about variable names a lot in the previous round so I leave this up to you to decide. 😉
After considering these, this PR can be merged. It's a big improvement for the search bars!
|



Reasons for creating this PR
Previously, we have used a mock-up translation of language lists in the search bar. This implements a punic-generated list of language names for the search bar dropdowns
Link to relevant issue(s), if any
Description of the changes in this PR
Known problems or uncertainties in this PR
Checklist
.sr-onlyclass, color contrast)