From 6c04ac987dc69bc1f7eabab07442e32e7541e052 Mon Sep 17 00:00:00 2001 From: djbusstop Date: Fri, 8 Sep 2023 13:51:31 +0100 Subject: [PATCH] use language set by user first, if there is one --- integrationTesting/mockData/users/RosaLuxemburgUser.ts | 1 + src/utils/next.ts | 2 +- src/utils/types/zetkin.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integrationTesting/mockData/users/RosaLuxemburgUser.ts b/integrationTesting/mockData/users/RosaLuxemburgUser.ts index 626c1c9977..93531f9f2e 100644 --- a/integrationTesting/mockData/users/RosaLuxemburgUser.ts +++ b/integrationTesting/mockData/users/RosaLuxemburgUser.ts @@ -3,6 +3,7 @@ import { ZetkinUser } from 'utils/types/zetkin'; const RosaLuxemburgUser: ZetkinUser = { first_name: 'Rosa', id: 1, + lang: null, last_name: 'Luxemburg', username: 'red_rosa', }; diff --git a/src/utils/next.ts b/src/utils/next.ts index bbe00fb52a..fb8b4bdb4b 100644 --- a/src/utils/next.ts +++ b/src/utils/next.ts @@ -189,7 +189,7 @@ export const scaffold = const result = (await wrapped(ctx)) || {}; // Figure out browser's preferred language - const lang = getBrowserLanguage(contextFromNext.req); + const lang = ctx.user?.lang || getBrowserLanguage(contextFromNext.req); // TODO: Respect scope from options again //const localeScope = (options?.localeScope ?? []).concat(['misc', 'zui']); diff --git a/src/utils/types/zetkin.ts b/src/utils/types/zetkin.ts index b25ac9198b..b26892a184 100644 --- a/src/utils/types/zetkin.ts +++ b/src/utils/types/zetkin.ts @@ -132,6 +132,7 @@ export interface ZetkinUser { first_name: string; id: number; is_superuser?: boolean; + lang: string | null; last_name: string; username: string; }