mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 02:35:12 +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
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { setLanguageCookie } from "@/lib/cookies";
|
||||
import { Lang, LANGS } from "@/lib/i18n";
|
||||
import { Lang } from "@/lib/i18n";
|
||||
import { getThemeConfig, getComponentRoundness, APPEARANCE_STYLES } from "@/lib/theme";
|
||||
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "@headlessui/react";
|
||||
import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline";
|
||||
@@ -22,12 +22,12 @@ function getLanguageSwitcherCardAppearance(): string {
|
||||
return appearance?.card || "bg-black/5 dark:bg-white/5"; // Fallback to current styling
|
||||
}
|
||||
|
||||
export function LanguageSwitcher() {
|
||||
export function LanguageSwitcher({ languages }: { languages: Lang[] }) {
|
||||
const currentLocale = useLocale();
|
||||
const switcherRoundness = getLanguageSwitcherRoundness();
|
||||
const cardAppearance = getLanguageSwitcherCardAppearance();
|
||||
|
||||
const [selected, setSelected] = useState(LANGS.find((l) => l.code === currentLocale) || LANGS[0]);
|
||||
const [selected, setSelected] = useState(languages.find((l) => l.code === currentLocale) || languages[0]);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -61,7 +61,7 @@ export function LanguageSwitcher() {
|
||||
"transition duration-100 ease-in data-[leave]:data-[closed]:opacity-0",
|
||||
)}
|
||||
>
|
||||
{LANGS.map((lang) => (
|
||||
{languages.map((lang) => (
|
||||
<ListboxOption
|
||||
key={lang.code}
|
||||
value={lang}
|
||||
|
||||
Reference in New Issue
Block a user