Skip to content

Commit

Permalink
chore: update storages i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 27, 2022
1 parent 8e33d6e commit b7bb33e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/hooks/useT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const useT = () => {
) => {
const value = t(key, params, defaultValue);
if (!value) {
if (import.meta.env.DEV) return key;
let lastDotIndex = key.lastIndexOf(".");
if (lastDotIndex === key.length - 1) {
lastDotIndex = key.lastIndexOf(".", lastDotIndex - 1);
Expand Down
44 changes: 38 additions & 6 deletions src/lang/en/storages.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
{
"mount_path": "Mount Path",
"driver": "Driver",
"index": "Index",
"status": "Status",
"remark": "Remark",
"operations": "Operations"
"common": {
"mount_path": "Mount Path",
"driver": "Driver",
"drivers": {
"Local": "Local"
},
"index": "Index",
"status": "Status",
"remark": "Remark",
"operations": "Operations",
"down_proxy_url": "Download proxy URL",
"web_proxy": "Web proxy",
"webdav_policy": "WebDAV policy",
"webdav_policys": {
"302_redirect": "302 redirect",
"use_proxy_url": "use proxy URL",
"native_proxy": "native proxy"
},
"order_by": "Order by",
"order_bys": {
"name": "Name",
"size": "Size",
"modified": "Modified"
},
"order_direction": "Order direction",
"order_directions": {
"asc": "Ascending",
"desc": "Descending"
},
"extract_folder": "Extract folder",
"extract_folders": {
"front": "Extract to front",
"back": "Extract to back"
}
},
"Local": {
"root_folder": "Root folder"
}
}
9 changes: 6 additions & 3 deletions src/pages/manage/storages/AddOrEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Item } from "./Item";
import { ResponsiveGrid } from "../ResponsiveGrid";

interface DriverItems {
main: DriverItem[];
common: DriverItem[];
additional: DriverItem[];
}

Expand Down Expand Up @@ -93,9 +93,10 @@ const AddOrEdit = () => {
type={Type.Select}
values={id ? storage.driver : Object.keys(drivers()).join(",")}
value={storage.driver}
scop="common"
onChange={(value) => {
setStorage("driver", value);
for (const item of drivers()[value].main) {
for (const item of drivers()[value].common) {
setStorage(
item.name as keyof Storage,
GetDefaultValue(item.type, item.default) as any
Expand All @@ -110,10 +111,11 @@ const AddOrEdit = () => {
}}
/>
<Show when={drivers()[storage.driver]}>
<For each={drivers()[storage.driver].main}>
<For each={drivers()[storage.driver].common}>
{(item) => (
<Item
{...item}
scop="common"
value={(storage as any)[item.name]}
onChange={(val: any) => {
setStorage(item.name as keyof Storage, val);
Expand All @@ -125,6 +127,7 @@ const AddOrEdit = () => {
{(item) => (
<Item
{...item}
scop={storage.driver}
value={addition[item.name] as any}
onChange={(val: any) => {
setAddition(item.name, val);
Expand Down
5 changes: 3 additions & 2 deletions src/pages/manage/storages/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DriverItem, Type } from "~/types";

export type ItemProps = DriverItem & {
readonly?: boolean;
scop?: string;
} & (
| {
type: Type.Bool;
Expand Down Expand Up @@ -51,7 +52,7 @@ const Item = (props: ItemProps) => {
required={props.required}
>
<FormLabel for={props.name} display="flex" alignItems="center">
{t(`manage.settings.${props.name}`)}
{t(`storages.${props.scop}.${props.name}`)}
</FormLabel>
<Switch fallback={<Center>{t("settings.unknown_type")}</Center>}>
<Match when={props.type === Type.String}>
Expand Down Expand Up @@ -125,7 +126,7 @@ const Item = (props: ItemProps) => {
{(item) => (
<SelectOption value={item}>
<SelectOptionText>
{t(`manage.settings.${item}`)}
{t(`storages.${props.scop}.${props.name}s.${item}`)}
</SelectOptionText>
<SelectOptionIndicator />
</SelectOption>
Expand Down

0 comments on commit b7bb33e

Please sign in to comment.