Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: i18n displays real lang name #995

Merged
merged 4 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions apps/dokploy/components/dashboard/settings/appearance-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ import { useTheme } from "next-themes";
import { useEffect } from "react";
import { toast } from "sonner";


const languageCodes = Object.values(Languages).map(lang => lang.code) as [string, ...string[]];

const appearanceFormSchema = z.object({
theme: z.enum(["light", "dark", "system"], {
required_error: "Please select a theme.",
}),
language: z.nativeEnum(Languages, {

language: z.enum(languageCodes, {
required_error: "Please select a language.",
}),
})
});

type AppearanceFormValues = z.infer<typeof appearanceFormSchema>;

// This can come from your database or API.
const defaultValues: Partial<AppearanceFormValues> = {
theme: "system",
language: Languages.English,
language: Languages.english.code,
};

export function AppearanceForm() {
Expand Down Expand Up @@ -173,15 +177,11 @@ export function AppearanceForm() {
<SelectValue placeholder="No preset selected" />
</SelectTrigger>
<SelectContent>
{Object.keys(Languages).map((preset) => {
const value =
Languages[preset as keyof typeof Languages];
return (
<SelectItem key={value} value={value}>
{preset}
</SelectItem>
);
})}
{Object.values(Languages).map((language) => (
<SelectItem key={language.code} value={language.code}>
{language.name}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItem>
Expand Down
40 changes: 20 additions & 20 deletions apps/dokploy/lib/languages.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export enum Languages {
English = "en",
Polish = "pl",
Russian = "ru",
French = "fr",
German = "de",
ChineseTraditional = "zh-Hant",
ChineseSimplified = "zh-Hans",
Turkish = "tr",
Kazakh = "kz",
Persian = "fa",
Korean = "ko",
Portuguese = "pt-br",
Italian = "it",
Japanese = "ja",
Spanish = "es",
Norwegian = "no",
}

export type Language = keyof typeof Languages;
export const Languages = {
english: { code: "en", name: "English" },
polish: { code: "pl", name: "Polski" },
russian: { code: "ru", name: "Русский" },
french: { code: "fr", name: "Français" },
german: { code: "de", name: "Deutsch" },
chineseTraditional: { code: "zh-Hant", name: "繁體中文" },
chineseSimplified: { code: "zh-Hans", name: "简体中文" },
turkish: { code: "tr", name: "Türkçe" },
kazakh: { code: "kz", name: "Қазақ" },
persian: { code: "fa", name: "فارسی" },
korean: { code: "ko", name: "한국어" },
portuguese: { code: "pt-br", name: "Português" },
italian: { code: "it", name: "Italiano" },
japanese: { code: "ja", name: "日本語" },
spanish: { code: "es", name: "Español" },
};
export type Language = keyof typeof Languages;
export type LanguageCode = (typeof Languages)[keyof typeof Languages]["code"];
2 changes: 1 addition & 1 deletion apps/dokploy/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default api.withTRPC(
appWithTranslation(MyApp, {
i18n: {
defaultLocale: "en",
locales: Object.values(Languages),
locales: Object.values(Languages).map(language => language.code),
localeDetection: false,
},
fallbackLng: "en",
Expand Down
7 changes: 4 additions & 3 deletions apps/dokploy/utils/hooks/use-locale.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Languages } from "@/lib/languages";
import { LanguageCode } from "@/lib/languages";
import Cookies from "js-cookie";

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 });
window.location.reload();
};
Expand Down
2 changes: 1 addition & 1 deletion apps/dokploy/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const serverSideTranslations = (
keySeparator: false,
i18n: {
defaultLocale: "en",
locales: Object.values(Languages),
locales: Object.values(Languages).map(language => language.code),
localeDetection: false,
},
});
Loading