mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 13:35:07 +00:00
move language config to i18n/request
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Lang, LANGS } from "@/i18n/request";
|
||||
import { setLanguageCookie } from "@/lib/cookies";
|
||||
import {
|
||||
Listbox,
|
||||
@@ -13,40 +14,6 @@ import { useLocale } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
interface Lang {
|
||||
id: number;
|
||||
name: string;
|
||||
img: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
const LANGS: Lang[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: "English",
|
||||
code: "en",
|
||||
img: "/images/flags/us.png",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Deutsch",
|
||||
code: "de",
|
||||
img: "/images/flags/de.png",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Italiano",
|
||||
code: "it",
|
||||
img: "/images/flags/it.png",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "Español",
|
||||
code: "es",
|
||||
img: "/images/flags/es.png",
|
||||
},
|
||||
];
|
||||
|
||||
export function LanguageSwitcher() {
|
||||
const currentLocale = useLocale();
|
||||
|
||||
|
||||
@@ -2,10 +2,36 @@ import deepmerge from "deepmerge";
|
||||
import { getRequestConfig } from "next-intl/server";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export interface Lang {
|
||||
name: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export const LANGS: Lang[] = [
|
||||
{
|
||||
name: "English",
|
||||
code: "en",
|
||||
},
|
||||
{
|
||||
name: "Deutsch",
|
||||
code: "de",
|
||||
},
|
||||
{
|
||||
name: "Italiano",
|
||||
code: "it",
|
||||
},
|
||||
{
|
||||
name: "Español",
|
||||
code: "es",
|
||||
},
|
||||
];
|
||||
|
||||
export const LANGUAGE_COOKIE_NAME = "NEXT_LOCALE";
|
||||
|
||||
export default getRequestConfig(async () => {
|
||||
const fallback = "en";
|
||||
const cookiesList = cookies();
|
||||
const locale: string = cookiesList.get("NEXT_LOCALE")?.value ?? "en";
|
||||
const locale: string = cookiesList.get(LANGUAGE_COOKIE_NAME)?.value ?? "en";
|
||||
|
||||
const userMessages = (await import(`../../locales/${locale}.json`)).default;
|
||||
const fallbackMessages = (await import(`../../locales/${fallback}.json`))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { LANGUAGE_COOKIE_NAME } from "@/i18n/request";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export type Cookie = {
|
||||
@@ -30,7 +31,7 @@ export async function setLanguageCookie(language: string) {
|
||||
const cookiesList = cookies();
|
||||
|
||||
await cookiesList.set({
|
||||
name: "NEXT_LOCALE",
|
||||
name: LANGUAGE_COOKIE_NAME,
|
||||
value: language,
|
||||
httpOnly: true,
|
||||
path: "/",
|
||||
|
||||
Reference in New Issue
Block a user