Skip to content

Commit

Permalink
Merge pull request #219 from inbo/fix-spatial-hub-language-settings
Browse files Browse the repository at this point in the history
#123: Finally fix the issue with the cookies on front and back being different
  • Loading branch information
StefanVanDyck authored Dec 16, 2024
2 parents f0667f4 + ac739ed commit b3ba72c
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion branding/app/assets/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html>
<html lang="nl">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Vlaams Biodiversiteitsportaal"/>
Expand Down
19 changes: 4 additions & 15 deletions branding/app/js/i18next-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ var jqueryI18next = require('jquery-i18next');
var backend = require("i18next-http-backend");
var lngDetector = require('i18next-browser-languagedetector');
var Url = require('domurl');
var Cookies = require('js-cookie');

const i18nOpts = {
backend: {
loadPath: "/locales/{{lng}}/{{ns}}",
crossDomain: false,
initImmediate: false,
},
// lng: 'nl', cookieOptions: { path: '/', sameSite: 'strict' },
supportedLngs: [settings.enabledLangs],
fallbackLng: {
"en-US": ['en'],
"nl-NL": ['nl'],
"nl-BE": ['nl'],
default: ['nl']
},
fallbackLng: 'nl',
sendMissingTo: 'en',
interpolation: {
escapeValue: false,
Expand Down Expand Up @@ -47,24 +40,18 @@ const i18nOpts = {

const detectorOptions = {
// order and from where user language should be detected
order: ['querystring', 'cookie', 'navigator'],
order: ['querystring', 'cookie', 'navigator', 'htmlTag'],

// keys or params to lookup language from
lookupQuerystring: 'lang',
lookupCookie: 'vbp-lang',
cookieMinutes: 525600, // a year
cookiePath: '/',
cookieDomain: `.${settings.mainDomain}`,
cookieOptions: { path: '/', sameSite: 'strict', secure: settings.mainLAUrl.startsWith('https') },
caches: ['cookie'],
excludeCacheFor: ['cimode']
};

if (document.location.host !== 'localhost:3333') {
// We set the upper domain in production so all ALA modules get the same locale
detectorOptions.cookieDomain = settings.mainDomain;
}

i18nOpts.detection = detectorOptions;

i18nOpts.sendMissing = false;
Expand Down Expand Up @@ -95,7 +82,9 @@ i18n.use(backend)
console.log('jquery i18next initialized');
$("body").localize();


$('.locale-link').on('click', function(e) {

e.preventDefault();
const lang = $(this).data('locale');
console.log(`Lang clicked ${lang}`);
Expand Down
2 changes: 1 addition & 1 deletion branding/app/js/index-auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Cookies = require("js-cookie");
const settings = require("js/settings");
const settings = require("./settings");
const authCookieName = "VBP-AUTH";
const loginClass = "signedIn";
const logoutClass = "signedOut";
Expand Down
2 changes: 1 addition & 1 deletion docker/alerts/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/apikey/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/bie-hub/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/bie-index/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/biocache-hub/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/collectory/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/doi-service/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/image-service/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/logger/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/regions/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/spatial-hub/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/species-list/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down
2 changes: 1 addition & 1 deletion docker/userdetails/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="nl"/>
<property name="cookieName" value="vbp-lang"/>
<property name="cookieMaxAge" value="525600"/>
<property name="cookieMaxAge" value="31536000"/>
<property name="cookieHttpOnly" value="false" />
<property name="cookieSecure" value="true" />
</bean>
Expand Down

0 comments on commit b3ba72c

Please sign in to comment.