Skip to content

Commit 2d1cb61

Browse files
authored
fix(i18n): add missing translations (#119)
* feat(lang): add load default settings translation * feat(lang): add disable proxy sign setting translation * fix(useT): optimize template translate * feat(lang): add Grid item size translation
1 parent 45ca846 commit 2d1cb61

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

src/hooks/useT.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import { dict, i18n, languages } from "~/app/i18n"
22
import { firstUpperCase } from "~/utils"
33

4-
export const useT = () => {
5-
const t = i18n.translator(dict)
6-
const tt = (key: string, params?: i18n.BaseTemplateArgs) => {
7-
return i18n.resolveTemplate ? i18n.resolveTemplate(key, params) : t(key)
4+
const translator = i18n.translator(dict)
5+
6+
const resolveTranslation = (
7+
key: string,
8+
params?: i18n.BaseTemplateArgs,
9+
): string | undefined => {
10+
const template = translator(key)
11+
if (typeof template !== "string") {
12+
return undefined
813
}
14+
15+
if (params) {
16+
return i18n.resolveTemplate(template, params) || template
17+
}
18+
19+
return template
20+
}
21+
export const useT = () => {
922
return (
1023
key: string,
1124
params?: i18n.BaseTemplateArgs | undefined,
1225
defaultValue?: string | undefined,
13-
) => {
14-
const value = params
15-
? (tt(key, params) as string | undefined)
16-
: (t(key) as string | undefined)
17-
18-
if (value) return value
26+
): string => {
27+
const translatedValue = resolveTranslation(key, params)
1928

29+
if (translatedValue) return translatedValue
2030
if (defaultValue) return defaultValue
21-
2231
if (import.meta.env.DEV) return key
2332

2433
return formatKeyAsDisplay(key)

src/lang/en/home.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
"sticky": "Stick to top of page",
163163
"only_navbar_sticky": "Only nav bar sticky"
164164
},
165+
"grid_item_size": "Grid item size",
165166
"show_sidebar": "Show sidebar",
166167
"show_sidebar_options": {
167168
"none": "None",

src/lang/en/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
"ldap_user_search_base": "Ldap user search base",
5050
"ldap_user_search_filter": "Ldap user search filter",
5151
"link_expiration": "Link expiration",
52+
"load_default_setting": "Load default settings",
53+
"load_default_setting_success": "Load default settings successfully",
5254
"logo": "Logo",
5355
"main_color": "Main color",
5456
"max_client_download_speed": "Max client download speed",

src/lang/en/storages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"cache_expiration": "Cache Expiration",
1111
"cache_expiration-tips": "The cache expiration time for this storage(minutes)",
1212
"down_proxy_url": "Download proxy URL",
13+
"disable_proxy_sign": "Disable proxy sign",
14+
"disable_proxy_sign-tips": "Disable sign for Download proxy URL",
1315
"web_proxy": "Web proxy",
1416
"webdav_policy": "WebDAV policy",
1517
"proxy_range": "Proxy Range",

0 commit comments

Comments
 (0)