Skip to content

Commit 1ef13af

Browse files
committed
initial i18n
1 parent 80acdbf commit 1ef13af

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"vite": "^6.0.6",
2121
"vooks": "^0.2.12",
2222
"vue": "^3.5.13",
23+
"vue-i18n": "10",
2324
"vue-tsc": "^2.2.0"
2425
}
2526
}

src/FooterButtons.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import { NButton, NFlex } from 'naive-ui'
3+
import { t } from './i18n'
34
45
defineProps<{
56
reset: () => void
@@ -17,13 +18,13 @@ defineProps<{
1718
secondary
1819
@click="reset"
1920
>
20-
Reset to default
21+
{{ t('Reset to default') }}
2122
</NButton>
2223
<NButton
2324
secondary
2425
@click="close"
2526
>
26-
Cancel
27+
{{ t('Cancel') }}
2728
</NButton>
2829
</NFlex>
2930
<NFlex>

src/InputMethodConfig.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NButton, NCheckbox, NCheckboxGroup, NFlex, NLayout, NLayoutFooter, NLay
44
import { computed, h, ref, watchEffect } from 'vue'
55
import BasicConfig from './BasicConfig.vue'
66
import FooterButtons from './FooterButtons.vue'
7+
import { t } from './i18n'
78
import MinusButton from './MinusButton.vue'
89
import PlusButton from './PlusButton.vue'
910
import { extractValue } from './util'
@@ -188,7 +189,7 @@ function apply() {
188189
v-model:checked="onlyShowCurrentLanguage"
189190
style="height: 50px; display: flex; justify-content: center; align-items: center"
190191
>
191-
{{ collapsed ? '' : 'Only show current language' }}
192+
{{ collapsed ? '' : t('Only show current language') }}
192193
</NCheckbox>
193194
<div
194195
v-else
@@ -208,7 +209,7 @@ function apply() {
208209
v-if="selectedLanguage === null"
209210
style="display: flex; justify-content: center; align-items: center; height: calc(100% - 50px);"
210211
>
211-
Select a language from the left list
212+
{{ t('Select a language from the left list') }}
212213
</div>
213214
<NLayout
214215
v-else
@@ -235,15 +236,15 @@ function apply() {
235236
style="padding: 8px; justify-content: space-between"
236237
>
237238
<NButton secondary @click="adding = false">
238-
Cancel
239+
{{ t('Cancel') }}
239240
</NButton>
240241
<NButton
241242
secondary
242243
type="info"
243244
:disabled="imsToAdd.length === 0"
244245
@click="add"
245246
>
246-
Add
247+
{{ t('Add') }}
247248
</NButton>
248249
</NFlex>
249250
</NLayoutFooter>

src/PluginManager.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { UploadFileInfo } from 'naive-ui'
33
import { NA, NAlert, NCode, NFlex, NList, NListItem, NUpload, NUploadDragger, useMessage } from 'naive-ui'
44
import { computed, ref } from 'vue'
5+
import { t } from './i18n'
56
67
const message = useMessage()
78
@@ -40,26 +41,26 @@ async function onUpload(files: UploadFileInfo[]) {
4041
<NFlex vertical>
4142
<NUpload v-model:file-list="fileList" style="width: auto" multiple accept=".zip" @update:file-list="onUpload">
4243
<NUploadDragger style="height: 200px">
43-
Download and drag zip to this area
44+
{{ t('Download and drag zip to this area') }}
4445
</NUploadDragger>
4546
</NUpload>
46-
<NAlert title="Warning" type="warning">
47-
Mozc doesn't work on Chrome unless start the process with <br>
47+
<NAlert :title="t('Warning')" type="warning">
48+
{{ t("Mozc doesn't work on Chrome unless start the process with") }} <br>
4849
<NCode>--enable-features=WebAssemblyUnlimitedSyncCompilation</NCode>
4950
</NAlert>
5051
</NFlex>
5152
<NFlex>
5253
<NList style="min-width: 100px">
5354
<template #header>
54-
Installed
55+
{{ t('Installed') }}
5556
</template>
5657
<NListItem v-for="plugin in installedPlugins" :key="plugin">
5758
{{ plugin }}
5859
</NListItem>
5960
</NList>
6061
<NList style="min-width: 100px">
6162
<template #header>
62-
Available
63+
{{ t('Available') }}
6364
</template>
6465
<NListItem v-for="plugin in availablePlugins" :key="plugin">
6566
<NA :href="`https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/${plugin}.zip`">

src/i18n.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { createI18n } from 'vue-i18n'
2+
import zhCN from './locales/zh-CN.json'
3+
4+
const messages = {
5+
'en': Object.fromEntries(Object.keys(zhCN).map(key => [key, key])),
6+
'zh-CN': zhCN,
7+
}
8+
9+
function getLocale() {
10+
for (const language of navigator.languages) {
11+
if (language in messages) {
12+
return language
13+
}
14+
if (language.startsWith('en')) {
15+
return 'en'
16+
}
17+
if (language === 'zh-SG') {
18+
return 'zh-CN'
19+
}
20+
}
21+
}
22+
23+
const i18n = createI18n({
24+
locale: getLocale(),
25+
messages,
26+
})
27+
28+
export function t(key: string) {
29+
return i18n.global.t(key)
30+
}

src/locales/zh-CN.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Add": "添加",
3+
"Available": "可用",
4+
"Cancel": "取消",
5+
"Download and drag zip to this area": "下载并拖拽 zip 到此区域",
6+
"Installed": "已安装",
7+
"Mozc doesn't work on Chrome unless start the process with": "Mozc 在 Chrome 下不工作,除非用如下参数启动进程",
8+
"Only show current language": "只显示当前语言",
9+
"Reset to default": "重设为默认值",
10+
"Select a language from the left list": "从左侧列表中选择一个语言",
11+
"Warning": "警告"
12+
}

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default defineConfig({
1414
'vue',
1515
'naive-ui',
1616
'vooks',
17+
'vue-i18n',
1718
],
1819
},
1920
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy