mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
Language selection
This commit is contained in:
parent
5adb7b3967
commit
502f749151
@ -82,7 +82,7 @@ export default function Settings() {
|
||||
const [pushoverUrl, setPushoverUrl] = useState<string>("")
|
||||
const [pushoverToken, setPushoverToken] = useState<string>("")
|
||||
const [pushoverUser, setPushoverUser] = useState<string>("")
|
||||
|
||||
const [language, setLanguage] = useState<string>("english")
|
||||
const [notifications, setNotifications] = useState<any[]>([])
|
||||
|
||||
const [notificationTextApplication, setNotificationTextApplication] = useState<string>("")
|
||||
@ -271,6 +271,26 @@ export default function Settings() {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const language = Cookies.get("language")
|
||||
if (language === "en") {
|
||||
setLanguage("english")
|
||||
} else if (language === "de") {
|
||||
setLanguage("german")
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setLanguageFunc = (value: string) => {
|
||||
setLanguage(value)
|
||||
if (value === "english") {
|
||||
Cookies.set("language", "en")
|
||||
} else if (value === "german") {
|
||||
Cookies.set("language", "de")
|
||||
}
|
||||
// Reload the page
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
@ -424,6 +444,34 @@ export default function Settings() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden border-2 border-muted/20 shadow-sm">
|
||||
<CardHeader className="bg-muted/10 px-6 py-4 border-b">
|
||||
<div className="flex items-center gap-2">
|
||||
<Palette className="h-5 w-5 text-primary" />
|
||||
<h2 className="text-xl font-semibold">{t('Settings.LanguageSettings.Title')}</h2>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="pb-6">
|
||||
<div className="text-sm text-muted-foreground mb-6">
|
||||
{t('Settings.LanguageSettings.Description')}
|
||||
</div>
|
||||
|
||||
<div className="max-w-md">
|
||||
<Select value={language} onValueChange={(value: string) => setLanguageFunc(value)}>
|
||||
<SelectTrigger className="w-full h-11">
|
||||
<SelectValue>
|
||||
{t(`Settings.LanguageSettings.${(language ?? "english").charAt(0).toUpperCase() + (language ?? "english").slice(1)}`)}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="english">{t('Settings.LanguageSettings.English')}</SelectItem>
|
||||
<SelectItem value="german">{t('Settings.LanguageSettings.German')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden border-2 border-muted/20 shadow-sm">
|
||||
<CardHeader className="bg-muted/10 px-6 py-4 border-b">
|
||||
<div className="flex items-center gap-3">
|
||||
|
||||
@ -4,6 +4,7 @@ import "./globals.css";
|
||||
import { ThemeProvider } from "@/components/theme-provider"
|
||||
import {NextIntlClientProvider} from 'next-intl';
|
||||
import {getLocale} from 'next-intl/server';
|
||||
import {cookies} from 'next/headers';
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
@ -20,13 +21,17 @@ export const metadata: Metadata = {
|
||||
description: "The only Dashboard you will need for your Services",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const cookieStore = await cookies();
|
||||
const locale = cookieStore.get('language')?.value || 'en';
|
||||
const messages = (await import(`@/i18n/languages/${locale}.json`)).default;
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<html lang={locale}>
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
@ -36,7 +41,7 @@ export default function RootLayout({
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
<NextIntlClientProvider>
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
{children}
|
||||
</NextIntlClientProvider>
|
||||
</ThemeProvider>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
"noData": "Keine Daten",
|
||||
"Loading": "Lade...",
|
||||
"Refresh": "Aktualisieren",
|
||||
"Save": "Speichern",
|
||||
"Server": {
|
||||
"CPU": "CPU",
|
||||
"GPU": "GPU",
|
||||
@ -330,6 +331,12 @@
|
||||
"Dark": "Dunkel",
|
||||
"System": "System"
|
||||
},
|
||||
"LanguageSettings": {
|
||||
"Title": "Spracheinstellungen",
|
||||
"Description": "Wählen Sie eine Sprache für die Anwendung.",
|
||||
"English": "Englisch",
|
||||
"German": "Deutsch"
|
||||
},
|
||||
"Notifications": {
|
||||
"Title": "Benachrichtigungen",
|
||||
"Description": "Erhalten Sie Warnungen bei Statusänderungen",
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
"noData": "No data",
|
||||
"Loading": "Loading...",
|
||||
"Refresh": "Refresh",
|
||||
"Save": "Save",
|
||||
"Server": {
|
||||
"CPU": "CPU",
|
||||
"GPU": "GPU",
|
||||
@ -330,6 +331,12 @@
|
||||
"Dark": "Dark",
|
||||
"System": "System"
|
||||
},
|
||||
"LanguageSettings": {
|
||||
"Title": "Language Settings",
|
||||
"Description": "Select a language for the application.",
|
||||
"English": "English",
|
||||
"German": "German"
|
||||
},
|
||||
"Notifications": {
|
||||
"Title": "Notifications",
|
||||
"Description": "Set up notifications to get instantly alerted when an application changes status.",
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import {getRequestConfig} from 'next-intl/server';
|
||||
|
||||
import {cookies} from 'next/headers';
|
||||
|
||||
export default getRequestConfig(async () => {
|
||||
// Provide a static locale, fetch a user setting,
|
||||
// read from `cookies()`, `headers()`, etc.
|
||||
const locale = 'en';
|
||||
const cookieStore = await cookies();
|
||||
const locale = cookieStore.get('language')?.value || 'en';
|
||||
|
||||
return {
|
||||
locale,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user