From e8bdceac68af62e9df3c9dccce68c079dabb327f Mon Sep 17 00:00:00 2001 From: Alex <49969959+alexzhang1030@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:48:23 +0800 Subject: [PATCH] feat(i18n): improve translations of command palette and others (#341) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲智子 Kevin Deng --- components/user/UserSwitcher.vue | 2 +- composables/command.ts | 24 ++++++++++++------------ layouts/default.vue | 2 +- locales/en-US.json | 11 ++++++++++- locales/zh-CN.json | 24 ++++++++++++++++++------ 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/components/user/UserSwitcher.vue b/components/user/UserSwitcher.vue index 36aa17b8..b63f710c 100644 --- a/components/user/UserSwitcher.vue +++ b/components/user/UserSwitcher.vue @@ -35,7 +35,7 @@ const switchUser = (user: UserLogin) => {
diff --git a/composables/command.ts b/composables/command.ts index b4397eac..44cfe24b 100644 --- a/composables/command.ts +++ b/composables/command.ts @@ -201,7 +201,7 @@ export const useCommands = (cmds: () => CommandProvider[]) => { } export const provideGlobalCommands = () => { - const { locale } = useI18n() + const { locale, t } = useI18n() const { locales } = useI18n() as { locales: ComputedRef } const users = useUsers() @@ -210,9 +210,9 @@ export const provideGlobalCommands = () => { visible: () => currentUser.value, - name: 'Compose', + name: () => t('action.compose'), icon: 'i-ri:quill-pen-line', - description: 'Write a new post', + description: () => t('command.compose_desc'), onActivate() { openPublishDialog() @@ -222,7 +222,7 @@ export const provideGlobalCommands = () => { useCommand({ scope: 'Preferences', - name: 'Toggle dark mode', + name: () => t('command.toggle_dark_mode'), icon: () => isDark.value ? 'i-ri:sun-line' : 'i-ri:moon-line', onActivate() { @@ -233,7 +233,7 @@ export const provideGlobalCommands = () => { useCommand({ scope: 'Preferences', - name: 'Toggle Zen mode', + name: () => t('command.toggle_zen_mode'), icon: () => isZenMode.value ? 'i-ri:layout-right-2-line' : 'i-ri:layout-right-line', onActivate() { @@ -244,7 +244,7 @@ export const provideGlobalCommands = () => { useCommand({ scope: 'Preferences', - name: 'Select language', + name: () => t('command.select_lang'), icon: 'i-ri:earth-line', onComplete: () => ({ @@ -267,8 +267,8 @@ export const provideGlobalCommands = () => { useCommand({ scope: 'Account', - name: 'Sign in', - description: 'Add an existing account', + name: () => t('action.sign_in'), + description: () => t('command.sign_in_desc'), icon: 'i-ri:user-add-line', onActivate() { @@ -280,8 +280,8 @@ export const provideGlobalCommands = () => { visible: () => users.value.length > 1, - name: 'Switch account', - description: 'Switch to another account', + name: () => t('action.switch_account'), + description: t('command.switch_account_desc'), icon: 'i-ri:user-shared-line', onComplete: () => ({ @@ -295,7 +295,7 @@ export const provideGlobalCommands = () => { visible: () => user.account.id !== currentUser.value?.account.id, - name: `Switch to ${getFullHandle(user.account)}`, + name: () => t('command.switch_account', [getFullHandle(user.account)]), icon: 'i-ri:user-shared-line', onActivate() { @@ -307,7 +307,7 @@ export const provideGlobalCommands = () => { visible: () => currentUser.value, - name: () => `Sign out ${getFullHandle(currentUser.value!.account)}`, + name: () => t('user.sign_out_account', [getFullHandle(currentUser.value!.account)]), icon: 'i-ri:logout-box-line', onActivate() { diff --git a/layouts/default.vue b/layouts/default.vue index 70fdad11..8a9b887f 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -35,7 +35,7 @@ -