mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-26 14:28:46 +00:00
feat(login): dynamically configure languages based on settings (#11372)
Closes #11199 # Which Problems Are Solved This PR refactors the login app to load allowed languages and the default language directly from the Zitadel API equivalents (`getGeneralSettings`), rather than relying on a hardcoded list. This ensures that the available languages in the UI and the locale selection logic match the instance's configuration. # How the Problems Are Solved - Fetches allowed languages server-side and passes them to the LanguageSwitcher - The NEXT_LOCALE cookie and Accept-Language headers are now strictly validated against the API-provided allowed languages. - Fallback: If a cookie requests an unsupported language, the system now falls back to the API's defaultLanguage (instead of valid but unconfigured defaults). # Additional Changes Helper: Added `getLanguage(code)` to map API language codes to display names (utilizing Intl.DisplayNames if the code isn't in our static mapping). --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
d27833e1bc
commit
ab0f045499
@@ -39,7 +39,7 @@ export const LANGS: Lang[] = [
|
||||
{
|
||||
name: "Русский",
|
||||
code: "ru",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Türkçe",
|
||||
code: "tr",
|
||||
@@ -60,3 +60,15 @@ export const LANGS: Lang[] = [
|
||||
|
||||
export const LANGUAGE_COOKIE_NAME = "NEXT_LOCALE";
|
||||
export const LANGUAGE_HEADER_NAME = "accept-language";
|
||||
|
||||
export function getLanguage(code: string): Lang {
|
||||
const lang = LANGS.find((l) => l.code === code);
|
||||
if (lang) {
|
||||
return lang;
|
||||
}
|
||||
|
||||
return {
|
||||
code,
|
||||
name: new Intl.DisplayNames([code], { type: "language" }).of(code) || code,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import {
|
||||
VerifyPasskeyRegistrationRequest,
|
||||
VerifyU2FRegistrationRequest,
|
||||
} from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||
import { unstable_cacheLife as cacheLife } from "next/cache";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { unstable_cacheLife as cacheLife } from "next/cache";
|
||||
import { getUserAgent } from "./fingerprint";
|
||||
|
||||
import { createServiceForHost } from "./service";
|
||||
@@ -159,10 +159,15 @@ export async function registerTOTP({ serviceConfig, userId }: WithServiceConfig<
|
||||
return userService.registerTOTP({ userId }, {});
|
||||
}
|
||||
|
||||
export async function getGeneralSettings({ serviceConfig }: WithServiceConfig) {
|
||||
export async function getAllowedLanguages({ serviceConfig }: WithServiceConfig) {
|
||||
const settingsService: Client<typeof SettingsService> = await createServiceForHost(SettingsService, serviceConfig);
|
||||
|
||||
const callback = settingsService.getGeneralSettings({}, {}).then((resp) => resp.supportedLanguages);
|
||||
const callback = settingsService.getGeneralSettings({}, {}).then((resp) => {
|
||||
return {
|
||||
allowedLanguages: resp.allowedLanguages,
|
||||
defaultLanguage: resp.defaultLanguage,
|
||||
};
|
||||
});
|
||||
|
||||
return useCache ? cacheWrapper(callback) : callback;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user