Skip to content
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

Fix setting reading the search language cookie #1693

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resource/js/vocab-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const vocabSearch = Vue.createApp({
this.languages = window.SKOSMOS.languageOrder
this.selectedLanguage = this.parseSearchLang()
this.searchCounter = 0 // used for matching the query and the response in case there are many responses
this.languageStrings = window.SKOSMOS.language_strings[window.SKOSMOS.lang] ?? window.SKOSMOS.language_strings.en
this.languageStrings = window.SKOSMOS.language_strings
this.msgs = window.SKOSMOS.msgs[window.SKOSMOS.lang] ?? window.SKOSMOS.msgs.en
this.renderedResultsList = []
this.showNotation = window.SKOSMOS.showNotation
Expand Down
4 changes: 2 additions & 2 deletions src/controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function __construct($model)
public function guessLanguage($request, $vocid = null)
{
// 1. select language based on SKOSMOS_LANGUAGE cookie
$languageCookie = $request->getCookie('SKOSMOS_LANGUAGE');
if ($languageCookie) {
$languageCookie = $request->getCookie('SKOSMOS_SEARCH_LANG');
if ($languageCookie && $languageCookie != 'all') {
return $languageCookie;
}

Expand Down
40 changes: 25 additions & 15 deletions src/view/scripts.inc.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
<!-- Skosmos variables passed from the backend to the frontend code-->
<!-- NB: Do not add comments inside the JS object as it would break JSON parsing -->
<script id="skosmos-global-vars">
{% set mockup_translations = {
"fi": {
"fi": "suomi",
"en": "englanti",
"se": "pohjoissaame",
"sv": "ruotsi",
"all": "kaikilla kielillä"
},
"sv": {
"fi": "finska",
"en": "engelska",
"se": "nordsamiska",
"sv": "svenska",
"all": "på alla språk"
},
"en": {
"fi": "Finnish",
"en": "English",
"se": "Northern Sami",
"sv": "Swedish",
"all": "In all languages"
}
} %}
window.SKOSMOS = {
"content_lang": "{{ request.contentLang }}",
"explicitLangCodes": {{ explicit_langcodes ? "true" : "false" }},
Expand Down Expand Up @@ -33,21 +56,8 @@ window.SKOSMOS = {
},
{%- endif -%}
"baseHref": "{{ BaseHref }}",
"language_strings": { "fi": { "fi": "suomi",
"en": "englanti",
"se": "pohjoissaame",
"sv": "ruotsi",
"all": "kaikilla kielillä"},
"sv": { "fi": "finska",
"en": "engelska",
"se": "nordsamiska",
"sv": "svenska",
"all": "på alla språk"},
"en": { "fi": "Finnish",
"en": "English",
"se": "Northern Sami",
"sv": "Swedish",
"all": "In all languages"}},
"language_strings": { {% for lang in request.vocab.config.languages %}"{{ lang }}": "{{ mockup_translations[request.lang][lang] }}", {% endfor -%}
"all": "{{ mockup_translations[request.lang].all }}" },
"msgs" : { "fi": { "No results": "Ei hakutuloksia",
"http://www.yso.fi/onto/yso-meta/Concept": "Yleiskäsite",
"http://www.yso.fi/onto/yso-meta/Hierarchy": "Hierarkisoiva käsite",
Expand Down
16 changes: 16 additions & 0 deletions tests/cypress/template/vocab-search-bar.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ describe('Vocab search bar', () => {
cy.url().should('include', 'clang=sv');
})

it('available search languages are the ones described in the vocabulary config', () => {
cy.visit('/yso/en/') // go to the YSO home page in English language

// check that the vocabulary languages can be found in the search bar language dropdown menu
cy.window().then((win) => {
cy.get('#language-list .dropdown-item').then($elements => {
const actualLanguages = $elements.map((index, el) => Cypress.$(el).attr('value')).get();

const expectedLanguages = ['fi', 'sv', 'se', 'en', 'all'];

// The two language lists should be of equal length and all of the expected languages can be found
expect(expectedLanguages).to.have.lengthOf(actualLanguages.length);
expectedLanguages.forEach(lang => { expect(actualLanguages).to.include(lang); });
})
})
})
});

describe('Autocomplete', () => {
Expand Down
Loading