Merge pull request 'feat: refs #7189 add Accept-Language header to axios requests' (!1111) from 7189-setAcceptLanguage into dev
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #1111
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-12-19 09:22:16 +00:00
commit 9e686f6a25
5 changed files with 12 additions and 9 deletions

View File

@ -3,12 +3,12 @@ import { useSession } from 'src/composables/useSession';
import { Router } from 'src/router'; import { Router } from 'src/router';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
import { useStateQueryStore } from 'src/stores/useStateQueryStore'; import { useStateQueryStore } from 'src/stores/useStateQueryStore';
import { i18n } from 'src/boot/i18n';
const session = useSession(); const session = useSession();
const { notify } = useNotify(); const { notify } = useNotify();
const stateQuery = useStateQueryStore(); const stateQuery = useStateQueryStore();
const baseUrl = '/api/'; const baseUrl = '/api/';
axios.defaults.baseURL = baseUrl; axios.defaults.baseURL = baseUrl;
const axiosNoError = axios.create({ baseURL: baseUrl }); const axiosNoError = axios.create({ baseURL: baseUrl });
@ -16,6 +16,7 @@ const onRequest = (config) => {
const token = session.getToken(); const token = session.getToken();
if (token.length && !config.headers.Authorization) { if (token.length && !config.headers.Authorization) {
config.headers.Authorization = token; config.headers.Authorization = token;
config.headers['Accept-Language'] = i18n.global.locale.value;
} }
stateQuery.add(config); stateQuery.add(config);
return config; return config;

View File

@ -1,9 +1,11 @@
import { boot } from 'quasar/wrappers'; import { boot } from 'quasar/wrappers';
import { createI18n } from 'vue-i18n'; import { createI18n } from 'vue-i18n';
import messages from 'src/i18n'; import messages from 'src/i18n';
import { useState } from 'src/composables/useState';
const user = useState().getUser();
const i18n = createI18n({ const i18n = createI18n({
locale: navigator.language || navigator.userLanguage, locale: user.value.lang || navigator.language || navigator.userLanguage,
fallbackLocale: 'en', fallbackLocale: 'en',
globalInjection: true, globalInjection: true,
messages, messages,

View File

@ -87,10 +87,10 @@ async function saveDarkMode(value) {
async function saveLanguage(value) { async function saveLanguage(value) {
const query = `/VnUsers/${user.value.id}`; const query = `/VnUsers/${user.value.id}`;
try { try {
await axios.patch(query, { await axios.patch(query, { lang: value });
lang: value,
});
user.value.lang = value; user.value.lang = value;
useState().setUser(user.value);
onDataSaved(); onDataSaved();
} catch (error) { } catch (error) {
onDataError(); onDataError();

View File

@ -9,15 +9,15 @@ describe('VnLog', () => {
cy.visit(`/#/claim/${1}/log`); cy.visit(`/#/claim/${1}/log`);
cy.openRightMenu(); cy.openRightMenu();
}); });
// Se tiene que cambiar el Accept-Language a 'en', ya hay una tarea para eso #7189.
xit('should filter by insert actions', () => { it('should filter by insert actions', () => {
cy.checkOption(':nth-child(7) > .q-checkbox'); cy.checkOption(':nth-child(7) > .q-checkbox');
cy.get('.q-page').click(); cy.get('.q-page').click();
cy.validateContent(chips[0], 'Document'); cy.validateContent(chips[0], 'Document');
cy.validateContent(chips[1], 'Beginning'); cy.validateContent(chips[1], 'Beginning');
}); });
xit('should filter by entity', () => { it('should filter by entity', () => {
cy.selectOption('.q-drawer--right .q-item > .q-select', 'Claim'); cy.selectOption('.q-drawer--right .q-item > .q-select', 'Claim');
cy.get('.q-page').click(); cy.get('.q-page').click();
cy.validateContent(chips[0], 'Claim'); cy.validateContent(chips[0], 'Claim');

View File

@ -1,4 +1,3 @@
import { Notify } from 'quasar';
import { onRequest, onResponseError } from 'src/boot/axios'; import { onRequest, onResponseError } from 'src/boot/axios';
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
@ -27,6 +26,7 @@ describe('Axios boot', () => {
expect(resultConfig).toEqual( expect(resultConfig).toEqual(
expect.objectContaining({ expect.objectContaining({
headers: { headers: {
'Accept-Language': 'en-US',
Authorization: 'DEFAULT_TOKEN', Authorization: 'DEFAULT_TOKEN',
}, },
}) })