Skip to content

Commit

Permalink
refactor: 动态导入语言文件
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Aug 9, 2023
1 parent bfb123b commit 5a28bf1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/custom-footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { t } = useI18n()
</div>
<div>
Code with by
<ALink target="_blank" href="https://www.ikxin.com">{{ t('app.author.name') }}</ALink>
<ALink target="_blank" href="https://www.ikxin.com">{{ t('main.author') }}</ALink>
</div>
</ASpace>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/activation.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/locales/en/index.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/locales/en/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
author: 'ikxin',
nav: {
activate: 'Activate',
check: 'Check',
download: 'Download',
guide: 'Guide',
home: 'Home',
monitor: 'Monitor'
},
theme: {
auto: 'Auto Mode',
dark: 'Dark Mode',
light: 'Light Mode'
},
languages: {
'en-us': 'English',
'zh-cn': 'Simplified Chinese'
}
}
15 changes: 14 additions & 1 deletion src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@ const en = import.meta.glob('./en/*.ts', {
eager: true
})

export default { en }
const message = {}

for (const key in en) {
const [language, fileName] = key.split('/').slice(1)
const value = en[key]

if (!message[language]) {
message[language] = {}
}

message[language][fileName.split('.')[0]] = value
}

export default message
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import App from '@/App.vue'
import { router } from '@/router'
import { createI18n } from 'vue-i18n'
import messages from '@intlify/unplugin-vue-i18n/messages'
// import messages from '@intlify/unplugin-vue-i18n/messages'

import locales from '@/locales'

Expand All @@ -15,6 +15,6 @@ const app = createApp(App)

const pinia = createPinia()

const i18n = createI18n({ locale: 'zh-cn', messages })
const i18n = createI18n({ locale: 'en', messages: locales })

app.use(pinia).use(i18n).use(router).mount('#app')
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"baseUrl": "./",
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true,
"paths": { "@/*": ["src/*"] },
"skipLibCheck": true,
Expand Down

0 comments on commit 5a28bf1

Please sign in to comment.