Skip to content

Commit 2c5e6c1

Browse files
committed
Add locale feedback link if not zh-CN (#90)
1 parent 90c5539 commit 2c5e6c1

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

src/app/layout/menu.ts

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import { ElIcon, ElMenu, ElMenuItem, ElMenuItemGroup, MenuItemRegistered } from
1010
import { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from "vue-router"
1111
import { I18nKey, t } from "@app/locale"
1212
import { MenuMessage } from "@app/locale/components/menu"
13-
import { GITHUB_ISSUE_ADD, HOME_PAGE, MEAT_URL, TU_CAO_PAGE } from "@util/constant/url"
13+
import { HOME_PAGE, MEAT_URL, TU_CAO_PAGE } from "@util/constant/url"
1414
import { Aim, Calendar, ChatSquare, Folder, Food, HotWater, Rank, SetUp, Stopwatch, Sugar, Tickets, Timer } from "@element-plus/icons-vue"
1515
import ElementIcon from "../element-ui/icon"
1616
import { locale } from "@util/i18n"
17-
import { IS_EDGE } from "@util/constant/environment"
1817

1918
type _MenuItem = {
2019
title: keyof MenuMessage
@@ -35,37 +34,46 @@ type _RouteProps = {
3534
}
3635

3736
/**
38-
* Use TU_CAO_PAGE, if the locale is Chinese
39-
*
40-
* @since 0.9.0
37+
* Generate menu items after locale initialized
4138
*/
42-
let realFeedbackLink: string = GITHUB_ISSUE_ADD
43-
if (locale === 'zh_CN') {
44-
realFeedbackLink = TU_CAO_PAGE
45-
}
46-
47-
const OTHER_MENU_ITEMS: _MenuItem[] = [{
48-
title: 'feedback',
49-
href: realFeedbackLink,
50-
icon: ChatSquare,
51-
index: '_feedback'
52-
}]
53-
HOME_PAGE && OTHER_MENU_ITEMS.push({
54-
title: 'rate',
55-
href: HOME_PAGE,
56-
icon: Sugar,
57-
index: '_rate'
58-
})
59-
OTHER_MENU_ITEMS.push({
60-
title: 'meat',
61-
href: MEAT_URL,
62-
icon: Food,
63-
index: '_meat'
64-
})
39+
function generateMenus(): _MenuGroup[] {
40+
/**
41+
* Use TU_CAO_PAGE, if the locale is Chinese
42+
*
43+
* @since 0.9.0
44+
*/
45+
const isZhCn = locale === "zh_CN"
46+
47+
const otherMenuItems: _MenuItem[] = []
48+
HOME_PAGE && otherMenuItems.push({
49+
title: 'rate',
50+
href: HOME_PAGE,
51+
icon: Sugar,
52+
index: '_rate'
53+
})
54+
if (isZhCn) {
55+
otherMenuItems.push({
56+
title: 'feedback',
57+
href: TU_CAO_PAGE,
58+
icon: ChatSquare,
59+
index: '_feedback'
60+
}, {
61+
title: 'meat',
62+
href: MEAT_URL,
63+
icon: Food,
64+
index: '_meat'
65+
})
66+
} else {
67+
otherMenuItems.push({
68+
title: 'translationMistake',
69+
href: 'https://github.com/sheepzh/timer/issues/new?assignees=&labels=locale&template=translation-------.md&title=Report+translation+mistakes',
70+
icon: ChatSquare,
71+
index: '_i18n'
72+
})
73+
}
6574

66-
// All menu items
67-
const ALL_MENU: _MenuGroup[] = [
68-
{
75+
// All menu items
76+
return [{
6977
title: 'data',
7078
children: [{
7179
title: 'dataReport',
@@ -112,9 +120,9 @@ const ALL_MENU: _MenuGroup[] = [
112120
}]
113121
}, {
114122
title: 'other',
115-
children: OTHER_MENU_ITEMS
116-
}
117-
]
123+
children: otherMenuItems
124+
}]
125+
}
118126

119127
function openMenu(route: string, title: I18nKey, routeProps: UnwrapRef<_RouteProps>) {
120128
const routerVal = routeProps.router
@@ -175,7 +183,7 @@ const _default = defineComponent({
175183

176184
return () => h(ElMenu,
177185
{ defaultActive: routeProps.current.path },
178-
() => ALL_MENU.map(menu => renderMenu(menu, routeProps))
186+
() => generateMenus().map(menu => renderMenu(menu, routeProps))
179187
)
180188
}
181189
})

src/app/locale/components/menu.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type MenuMessage = {
2424
feedback: string
2525
rate: string
2626
meat: string
27+
translationMistake: string
2728
}
2829
const _default: Messages<MenuMessage> = {
2930
zh_CN: {
@@ -42,7 +43,8 @@ const _default: Messages<MenuMessage> = {
4243
other: '其他',
4344
feedback: '有什么反馈吗?',
4445
rate: '打个分吧!',
45-
meat: '请作者吃饭~'
46+
meat: '请作者吃饭~',
47+
translationMistake: '提交翻译错误'
4648
},
4749
zh_TW: {
4850
data: '我的數據',
@@ -60,7 +62,8 @@ const _default: Messages<MenuMessage> = {
6062
other: '其他',
6163
feedback: '有什麼反饋嗎?',
6264
rate: '打個分吧!',
63-
meat: '請作者吃飯~'
65+
meat: '請作者吃飯~',
66+
translationMistake: '改善翻译~'
6467
},
6568
en: {
6669
data: 'My Data',
@@ -78,7 +81,8 @@ const _default: Messages<MenuMessage> = {
7881
option: 'Options',
7982
feedback: 'Feedback',
8083
rate: 'Rate It',
81-
meat: 'Invite the author to dinner'
84+
meat: 'Invite the author to dinner',
85+
translationMistake: 'Improve translation'
8286
},
8387
ja: {
8488
data: '私のデータ',
@@ -96,7 +100,8 @@ const _default: Messages<MenuMessage> = {
96100
option: '拡張設定',
97101
feedback: 'フィードバック',
98102
rate: 'それを評価',
99-
meat: '著者を夕食に招待する'
103+
meat: '著者を夕食に招待する',
104+
translationMistake: '翻訳を改善する'
100105
}
101106
}
102107

0 commit comments

Comments
 (0)