feat(i18n): replace translation in Appearance

This commit is contained in:
JiPai
2024-11-08 12:40:31 +08:00
parent 7f0a92f224
commit 046f0a5c20
5 changed files with 57 additions and 26 deletions

View File

@@ -63,7 +63,7 @@ export function AppearanceForm() {
useEffect(() => {
form.reset({
theme: (theme ?? "system") as AppearanceFormValues["theme"],
language: locale ?? "en",
language: locale,
});
}, [form, theme, locale]);
function onSubmit(data: AppearanceFormValues) {
@@ -92,9 +92,9 @@ export function AppearanceForm() {
render={({ field }) => {
return (
<FormItem className="space-y-1 ">
<FormLabel>Theme</FormLabel>
<FormLabel>{t("settings.appearance.theme")}</FormLabel>
<FormDescription>
Select a theme for your dashboard
{t("settings.appearance.themeDescription")}
</FormDescription>
<FormMessage />
<RadioGroup
@@ -112,7 +112,7 @@ export function AppearanceForm() {
<img src="/images/theme-light.svg" alt="light" />
</div>
<span className="block w-full p-2 text-center font-normal">
Light
{t("settings.appearance.themes.light")}
</span>
</FormLabel>
</FormItem>
@@ -125,7 +125,7 @@ export function AppearanceForm() {
<img src="/images/theme-dark.svg" alt="dark" />
</div>
<span className="block w-full p-2 text-center font-normal">
Dark
{t("settings.appearance.themes.dark")}
</span>
</FormLabel>
</FormItem>
@@ -141,7 +141,7 @@ export function AppearanceForm() {
<img src="/images/theme-system.svg" alt="system" />
</div>
<span className="block w-full p-2 text-center font-normal">
System
{t("settings.appearance.themes.system")}
</span>
</FormLabel>
</FormItem>
@@ -158,9 +158,9 @@ export function AppearanceForm() {
render={({ field }) => {
return (
<FormItem className="space-y-1">
<FormLabel>Language</FormLabel>
<FormLabel>{t("settings.appearance.language")}</FormLabel>
<FormDescription>
Select a language for your dashboard
{t("settings.appearance.languageDescription")}
</FormDescription>
<FormMessage />
<Select
@@ -187,7 +187,7 @@ export function AppearanceForm() {
}}
/>
<Button type="submit">Save</Button>
<Button type="submit">{t("settings.common.save")}</Button>
</form>
</Form>
</CardContent>

View File

@@ -96,9 +96,7 @@ export const ProfileForm = () => {
<CardTitle className="text-xl">
{t("settings.profile.title")}
</CardTitle>
<CardDescription>
Change the details of your profile here.
</CardDescription>
<CardDescription>{t("settings.profile.description")}</CardDescription>
</div>
{!data?.is2FAEnabled ? <Enable2FA /> : <Disable2FA />}
</CardHeader>
@@ -111,9 +109,12 @@ export const ProfileForm = () => {
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormLabel>{t("settings.profile.email")}</FormLabel>
<FormControl>
<Input placeholder="Email" {...field} />
<Input
placeholder={t("settings.profile.email")}
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
@@ -124,11 +125,11 @@ export const ProfileForm = () => {
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormLabel>{t("settings.profile.password")}</FormLabel>
<FormControl>
<Input
type="password"
placeholder="Password"
placeholder={t("settings.profile.password")}
{...field}
value={field.value || ""}
/>
@@ -143,7 +144,7 @@ export const ProfileForm = () => {
name="image"
render={({ field }) => (
<FormItem>
<FormLabel>Avatar</FormLabel>
<FormLabel>{t("settings.profile.avatar")}</FormLabel>
<FormControl>
<RadioGroup
onValueChange={(e) => {
@@ -181,7 +182,7 @@ export const ProfileForm = () => {
</div>
<div>
<Button type="submit" isLoading={isLoading}>
Save
{t("settings.common.save")}
</Button>
</div>
</form>

View File

@@ -1,11 +1,27 @@
{
"settings": {
"common": {
"save": "Save"
},
"profile": {
"title": "Account"
"title": "Account",
"description": "Change the details of your profile here.",
"email": "Email",
"password": "Password",
"avatar": "Avatar"
},
"appearance": {
"title": "Appearance",
"description": "Customize the theme of your dashboard."
"description": "Customize the theme of your dashboard.",
"theme": "Theme",
"themeDescription": "Select a theme for your dashboard",
"themes": {
"light": "Light",
"dark": "Dark",
"system": "System"
},
"language": "Language",
"languageDescription": "Select a language for your dashboard"
}
}
}

View File

@@ -1,11 +1,27 @@
{
"settings": {
"common": {
"save": "保存"
},
"profile": {
"title": "账户偏好"
"title": "账户偏好",
"description": "更改您的个人资料详情。",
"email": "电子邮件",
"password": "密码",
"avatar": "头像"
},
"appearance": {
"title": "外观",
"description": "自定义仪表板主题。"
"description": "自定义仪表板主题。",
"theme": "主题",
"themeDescription": "选择仪表板主题",
"themes": {
"light": "亮",
"dark": "暗",
"system": "系统"
},
"language": "语言",
"languageDescription": "选择仪表板语言"
}
}
}

View File

@@ -1,13 +1,11 @@
import Cookies from "js-cookie";
const SUPPORTED_LOCALES = ["en", "zh-Hans"] as const;
type Locale = (typeof SUPPORTED_LOCALES)[number];
type PossibleLocale = (typeof SUPPORTED_LOCALES)[number] | undefined | null;
export default function useLocale() {
const currentLocale = Cookies.get("DOKPLOY_LOCALE") as PossibleLocale;
console.log(currentLocale);
const currentLocale = (Cookies.get("DOKPLOY_LOCALE") ?? "en") as Locale;
const setLocale = (locale: Locale) => {
Cookies.set("DOKPLOY_LOCALE", locale);