mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #995 from 190km/refactor-i18n
feat: i18n displays real lang name
This commit is contained in:
@@ -34,13 +34,17 @@ import { useTheme } from "next-themes";
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
|
||||||
|
const languageCodes = Object.values(Languages).map(lang => lang.code) as [string, ...string[]];
|
||||||
|
|
||||||
const appearanceFormSchema = z.object({
|
const appearanceFormSchema = z.object({
|
||||||
theme: z.enum(["light", "dark", "system"], {
|
theme: z.enum(["light", "dark", "system"], {
|
||||||
required_error: "Please select a theme.",
|
required_error: "Please select a theme.",
|
||||||
}),
|
}),
|
||||||
language: z.nativeEnum(Languages, {
|
|
||||||
|
language: z.enum(languageCodes, {
|
||||||
required_error: "Please select a language.",
|
required_error: "Please select a language.",
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>;
|
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>;
|
||||||
@@ -48,7 +52,7 @@ type AppearanceFormValues = z.infer<typeof appearanceFormSchema>;
|
|||||||
// This can come from your database or API.
|
// This can come from your database or API.
|
||||||
const defaultValues: Partial<AppearanceFormValues> = {
|
const defaultValues: Partial<AppearanceFormValues> = {
|
||||||
theme: "system",
|
theme: "system",
|
||||||
language: Languages.English,
|
language: Languages.english.code,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AppearanceForm() {
|
export function AppearanceForm() {
|
||||||
@@ -173,15 +177,11 @@ export function AppearanceForm() {
|
|||||||
<SelectValue placeholder="No preset selected" />
|
<SelectValue placeholder="No preset selected" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{Object.keys(Languages).map((preset) => {
|
{Object.values(Languages).map((language) => (
|
||||||
const value =
|
<SelectItem key={language.code} value={language.code}>
|
||||||
Languages[preset as keyof typeof Languages];
|
{language.name}
|
||||||
return (
|
</SelectItem>
|
||||||
<SelectItem key={value} value={value}>
|
))}
|
||||||
{preset}
|
|
||||||
</SelectItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
export enum Languages {
|
export const Languages = {
|
||||||
English = "en",
|
english: { code: "en", name: "English" },
|
||||||
Polish = "pl",
|
polish: { code: "pl", name: "Polski" },
|
||||||
Russian = "ru",
|
russian: { code: "ru", name: "Русский" },
|
||||||
French = "fr",
|
french: { code: "fr", name: "Français" },
|
||||||
German = "de",
|
german: { code: "de", name: "Deutsch" },
|
||||||
ChineseTraditional = "zh-Hant",
|
chineseTraditional: { code: "zh-Hant", name: "繁體中文" },
|
||||||
ChineseSimplified = "zh-Hans",
|
chineseSimplified: { code: "zh-Hans", name: "简体中文" },
|
||||||
Turkish = "tr",
|
turkish: { code: "tr", name: "Türkçe" },
|
||||||
Kazakh = "kz",
|
kazakh: { code: "kz", name: "Қазақ" },
|
||||||
Persian = "fa",
|
persian: { code: "fa", name: "فارسی" },
|
||||||
Korean = "ko",
|
korean: { code: "ko", name: "한국어" },
|
||||||
Portuguese = "pt-br",
|
portuguese: { code: "pt-br", name: "Português" },
|
||||||
Italian = "it",
|
italian: { code: "it", name: "Italiano" },
|
||||||
Japanese = "ja",
|
japanese: { code: "ja", name: "日本語" },
|
||||||
Spanish = "es",
|
spanish: { code: "es", name: "Español" },
|
||||||
Norwegian = "no",
|
};
|
||||||
}
|
|
||||||
|
export type Language = keyof typeof Languages;
|
||||||
export type Language = keyof typeof Languages;
|
export type LanguageCode = (typeof Languages)[keyof typeof Languages]["code"];
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default api.withTRPC(
|
|||||||
appWithTranslation(MyApp, {
|
appWithTranslation(MyApp, {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: "en",
|
defaultLocale: "en",
|
||||||
locales: Object.values(Languages),
|
locales: Object.values(Languages).map(language => language.code),
|
||||||
localeDetection: false,
|
localeDetection: false,
|
||||||
},
|
},
|
||||||
fallbackLng: "en",
|
fallbackLng: "en",
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import type { Languages } from "@/lib/languages";
|
import { LanguageCode } from "@/lib/languages";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
export default function useLocale() {
|
export default function useLocale() {
|
||||||
const currentLocale = (Cookies.get("DOKPLOY_LOCALE") ?? "en") as Languages;
|
|
||||||
|
const currentLocale = (Cookies.get("DOKPLOY_LOCALE") ?? "en") as LanguageCode;
|
||||||
|
|
||||||
const setLocale = (locale: Languages) => {
|
const setLocale = (locale: LanguageCode) => {
|
||||||
Cookies.set("DOKPLOY_LOCALE", locale, { expires: 365 });
|
Cookies.set("DOKPLOY_LOCALE", locale, { expires: 365 });
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const serverSideTranslations = (
|
|||||||
keySeparator: false,
|
keySeparator: false,
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: "en",
|
defaultLocale: "en",
|
||||||
locales: Object.values(Languages),
|
locales: Object.values(Languages).map(language => language.code),
|
||||||
localeDetection: false,
|
localeDetection: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user