Skip to content

Translated language name lists in global & vocab search bar#1844

Merged
joelit merged 27 commits intomainfrom
translated-language-names
Dec 4, 2025
Merged

Translated language name lists in global & vocab search bar#1844
joelit merged 27 commits intomainfrom
translated-language-names

Conversation

@joelit
Copy link
Contributor

@joelit joelit commented Nov 27, 2025

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

  • When in global search results page, or landing page, use the list of every available language in the dataset, translated by punic
  • When in vocablulary-related page (vocab-home, concept, or vocab-search-result), use the list of languages configured for the vocabulary, translated by punic
  • Remove the mock-up translations from skosmos-object
  • Move some of the logic up to the controller level
  • Format the list with 'all languages' option
  • Update cypress tests accordingly

Known problems or uncertainties in this PR

  • Support for adding additional languages needs to be explored (e.g. for Northern Sami)

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@joelit joelit self-assigned this Nov 27, 2025
@joelit joelit added this to the 3.0 milestone Nov 27, 2025
@joelit joelit marked this pull request as ready for review November 27, 2025 15:27
@joelit joelit requested a review from osma November 27, 2025 15:27
@joelit joelit moved this to Needs review in Skosmos 3.x Backlog Nov 27, 2025
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, mostly things are working, but I have a few suggestions for changes:

  1. The "All languages" option should be last, after the languages, not first, just like in Skosmos 2.
  2. The "All languages" option could be called "Any language" in English, just like in Skosmos 2.
  3. I suggest renaming the variables $searchLangList and $vocabSearchLangList (php), search_lang_list (twig) and searchLangStrings (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. the content_lang and clang variable names. For example searchLangStrings could be called contentLanguages.
  4. The SKOSMOS object now has both languageOrder and searchLangStrings fields, for slightly different reasons, but both containing a list of languages. Would it be possible to get rid of languageOrder and instead order searchLangStrings/contentLanguages in the right order?
  5. 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:
    window.SKOSMOS.content_lang = clang

@joelit joelit requested a review from osma December 2, 2025 15:18
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • allLanguages method -> anyLanguage
  • allLanguegesEntry -> anyLanguageEntry (note the typo in the current name)
  • $contentLangList -> $contentLanguages
  • content_lang_list -> content_languages
  • $sortedContentLangList -> $contentLanguages or $sortedContentLanguages

As a final nitpick, the formattedList variable in both the formatLangStrings methods is useless and the value could just be returned directly.

private function parseVocabularyLanguageOrder($vocab)
{
$vocabContentLangList = array_flip($vocab->getConfig()->getLanguages());
$languageOrder = $vocab->getConfig()->getLanguageOrder(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use null here as an argument? It should be the current content language

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@joelit joelit requested a review from osma December 3, 2025 13:37
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -> formatLanguages
  • langStrings -> languages
  • contentLangStrings ->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!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 4, 2025

@joelit joelit merged commit 432e1fb into main Dec 4, 2025
16 checks passed
@github-project-automation github-project-automation bot moved this from Needs review to Issue/PR closed in Skosmos 3.x Backlog Dec 4, 2025
@joelit joelit deleted the translated-language-names branch December 4, 2025 08:44
@joelit joelit moved this from Issue/PR closed to Done (verified in test.dev.finto.fi, set Milestone 3.0 for both issue & PR, update docs) in Skosmos 3.x Backlog Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants