feat: use module

This commit is contained in:
Anthony Fu 2022-11-28 18:24:05 +08:00
parent 654010b3aa
commit c2f3526e88
7 changed files with 251 additions and 57 deletions

View file

@ -1,6 +1,4 @@
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
</script>

View file

@ -1,10 +1,10 @@
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
import { STORAGE_KEY_LANG } from '~/constants'
const { locale } = useI18n()
useLocalStorage(STORAGE_KEY_LANG, locale)
// TODO: read from $i18n https://i18n.nuxtjs.org/lang-switcher
const languageList = [
{
value: 'en-US',

View file

@ -8,6 +8,7 @@ export default defineNuxtConfig({
'@unocss/nuxt',
'@pinia/nuxt',
'@vue-macros/nuxt',
'@nuxtjs/i18n',
'~/modules/purge-comments',
'~/modules/setup-components',
],
@ -64,4 +65,22 @@ export default defineNuxtConfig({
app: {
keepalive: true,
},
i18n: {
locales: [
{
code: 'en-US',
file: 'en-US.json',
name: 'English',
},
{
code: 'zh-CN',
file: 'zh-CN.json',
name: '简体中文',
},
],
// TODO:
// lazy: true,
langDir: 'locales',
defaultLocale: 'en-US',
},
})

View file

@ -22,6 +22,7 @@
"@iconify-json/logos": "^1.1.19",
"@iconify-json/ri": "^1.1.4",
"@iconify-json/twemoji": "^1.1.6",
"@nuxtjs/i18n": "8.0.0-beta.5",
"@pinia/nuxt": "^0.4.5",
"@tiptap/extension-character-count": "2.0.0-beta.204",
"@tiptap/extension-code-block": "2.0.0-beta.204",
@ -67,7 +68,6 @@
"unplugin-auto-import": "^0.12.0",
"vite-plugin-inspect": "^0.7.9",
"vitest": "^0.25.3",
"vue-i18n": "^9.2.2",
"vue-safe-teleport": "^0.1.1",
"vue-virtual-scroller": "2.0.0-beta.3"
}

View file

@ -1,6 +1,4 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
definePageMeta({
middleware: 'auth',
})

View file

@ -1,25 +0,0 @@
import { createI18n } from 'vue-i18n'
import enUS from '../locales/en-US.json'
import zhCn from '../locales/zh-CN.json'
/** Default language environment */
export const defaultLocale = 'en-US'
export const messages = {
'en-US': enUS,
'zh-CN': zhCn,
}
/** Language Environment List */
export const localeList = Object.keys(messages)
export default defineNuxtPlugin(({ vueApp }) => {
const i18n = createI18n({
legacy: false,
globalInjection: true,
locale: defaultLocale,
messages,
})
vueApp.use(i18n)
})

View file

@ -7,6 +7,7 @@ specifiers:
'@iconify-json/logos': ^1.1.19
'@iconify-json/ri': ^1.1.4
'@iconify-json/twemoji': ^1.1.6
'@nuxtjs/i18n': 8.0.0-beta.5
'@pinia/nuxt': ^0.4.5
'@tiptap/extension-character-count': 2.0.0-beta.204
'@tiptap/extension-code-block': 2.0.0-beta.204
@ -52,7 +53,6 @@ specifiers:
unplugin-auto-import: ^0.12.0
vite-plugin-inspect: ^0.7.9
vitest: ^0.25.3
vue-i18n: ^9.2.2
vue-safe-teleport: ^0.1.1
vue-virtual-scroller: 2.0.0-beta.3
@ -63,6 +63,7 @@ devDependencies:
'@iconify-json/logos': 1.1.19
'@iconify-json/ri': 1.1.4
'@iconify-json/twemoji': 1.1.6
'@nuxtjs/i18n': 8.0.0-beta.5
'@pinia/nuxt': 0.4.5_typescript@4.9.3
'@tiptap/extension-character-count': 2.0.0-beta.204
'@tiptap/extension-code-block': 2.0.0-beta.204
@ -108,7 +109,6 @@ devDependencies:
unplugin-auto-import: 0.12.0
vite-plugin-inspect: 0.7.9
vitest: 0.25.3
vue-i18n: 9.2.2
vue-safe-teleport: 0.1.1
vue-virtual-scroller: 2.0.0-beta.3
@ -657,42 +657,133 @@ packages:
- supports-color
dev: true
/@intlify/core-base/9.2.2:
resolution: {integrity: sha512-JjUpQtNfn+joMbrXvpR4hTF8iJQ2sEFzzK3KIESOx+f+uwIjgw20igOyaIdhfsVVBCds8ZM64MoeNSx+PHQMkA==}
engines: {node: '>= 14'}
/@intlify/bundle-utils/3.4.0_vue-i18n@9.3.0-beta.10:
resolution: {integrity: sha512-2UQkqiSAOSPEHMGWlybqWm4G2K0X+FyYho5AwXz6QklSX1EY5EDmOSxZmwscn2qmKBnp6OYsme5kUrnN9xrWzQ==}
engines: {node: '>= 12'}
peerDependencies:
petite-vue-i18n: '*'
vue-i18n: '*'
peerDependenciesMeta:
petite-vue-i18n:
optional: true
vue-i18n:
optional: true
dependencies:
'@intlify/devtools-if': 9.2.2
'@intlify/message-compiler': 9.2.2
'@intlify/shared': 9.2.2
'@intlify/vue-devtools': 9.2.2
'@intlify/message-compiler': 9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
jsonc-eslint-parser: 1.4.1
source-map: 0.6.1
vue-i18n: 9.3.0-beta.10
yaml-eslint-parser: 0.3.2
dev: true
/@intlify/devtools-if/9.2.2:
resolution: {integrity: sha512-4ttr/FNO29w+kBbU7HZ/U0Lzuh2cRDhP8UlWOtV9ERcjHzuyXVZmjyleESK6eVP60tGC9QtQW9yZE+JeRhDHkg==}
/@intlify/core-base/9.3.0-beta.10:
resolution: {integrity: sha512-WJhjzR6fxoSSdOnQHEAqEAQiXsF38YXbw5asveAirjE2H+75CLZyNwEXaJzNBylrDgTrfWjoAyBuBde7TaooRA==}
engines: {node: '>= 14'}
dependencies:
'@intlify/shared': 9.2.2
'@intlify/devtools-if': 9.3.0-beta.10
'@intlify/message-compiler': 9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
'@intlify/vue-devtools': 9.3.0-beta.10
dev: true
/@intlify/message-compiler/9.2.2:
resolution: {integrity: sha512-IUrQW7byAKN2fMBe8z6sK6riG1pue95e5jfokn8hA5Q3Bqy4MBJ5lJAofUsawQJYHeoPJ7svMDyBaVJ4d0GTtA==}
/@intlify/devtools-if/9.3.0-beta.10:
resolution: {integrity: sha512-9kRiLK57MDogzjPElQhvd+K/s61MZE0TCHJAD+5zw+e3Vxie+xBCSa27mJB3jBuHC/QyMqIdrfyM6rmPtm22Rg==}
engines: {node: '>= 14'}
dependencies:
'@intlify/shared': 9.2.2
'@intlify/shared': 9.3.0-beta.10
dev: true
/@intlify/message-compiler/9.3.0-beta.10:
resolution: {integrity: sha512-RoOC6yceOykLRhN0NlbkNOBUx1el6iphx3W8NfOx3jHVNtfT1FYokx14/5sU3F1F0uxeG4sp6q+ppKvaF8o+ww==}
engines: {node: '>= 14'}
dependencies:
'@intlify/shared': 9.3.0-beta.10
source-map: 0.6.1
dev: true
/@intlify/shared/9.2.2:
resolution: {integrity: sha512-wRwTpsslgZS5HNyM7uDQYZtxnbI12aGiBZURX3BTR9RFIKKRWpllTsgzHWvj3HKm3Y2Sh5LPC1r0PDCKEhVn9Q==}
/@intlify/shared/9.3.0-beta.10:
resolution: {integrity: sha512-h93uAanbAt/XgjDHclrVB7xix6r7Uz11wx0iGNOCdHP7aA2LCJjUT3uNbekJjjbo+Fl5jzTSJZdm2SexzoqhRA==}
engines: {node: '>= 14'}
dev: true
/@intlify/vue-devtools/9.2.2:
resolution: {integrity: sha512-+dUyqyCHWHb/UcvY1MlIpO87munedm3Gn6E9WWYdWrMuYLcoIoOEVDWSS8xSwtlPU+kA+MEQTP6Q1iI/ocusJg==}
/@intlify/unplugin-vue-i18n/0.8.0_vue-i18n@9.3.0-beta.10:
resolution: {integrity: sha512-bqMDYrbmV0oMLGHTdYMUXfcEsy2rPwQnGrQAg4gvw5FimvJfTQt3RliLVayT5ldOfeT2g0IUc/0t7LPeGrFUag==}
engines: {node: '>= 14.16'}
peerDependencies:
petite-vue-i18n: '*'
vue-i18n: '*'
vue-i18n-bridge: '*'
peerDependenciesMeta:
petite-vue-i18n:
optional: true
vue-i18n:
optional: true
vue-i18n-bridge:
optional: true
dependencies:
'@intlify/bundle-utils': 3.4.0_vue-i18n@9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
'@rollup/pluginutils': 4.2.1
'@vue/compiler-sfc': 3.2.45
debug: 4.3.4
fast-glob: 3.2.12
js-yaml: 4.1.0
json5: 2.2.1
pathe: 1.0.0
picocolors: 1.0.0
source-map: 0.6.1
unplugin: 1.0.0
vue-i18n: 9.3.0-beta.10
transitivePeerDependencies:
- supports-color
dev: true
/@intlify/vue-devtools/9.3.0-beta.10:
resolution: {integrity: sha512-SSA2zk+Mn+idJHaIaKeGmuvY3EwxDUUvniecZ7S66KkrUomMDyEq/+WJYlF3+aslLL7vxnRVN2y+sXB+0NI2WQ==}
engines: {node: '>= 14'}
dependencies:
'@intlify/core-base': 9.2.2
'@intlify/shared': 9.2.2
'@intlify/core-base': 9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
dev: true
/@intlify/vue-i18n-bridge/0.8.0_vue-i18n@9.3.0-beta.10:
resolution: {integrity: sha512-wQ18fSccm9QaWpUW2vq2QHvojgKIog7s+UMj9LeY3pUV3yD9bU4YZI+1PTNoX3tOA+BE71gQyqVGox/TVQKP6Q==}
engines: {node: '>= 12'}
hasBin: true
requiresBuild: true
peerDependencies:
'@vue/composition-api': ^1.0.0-rc.1
vue-i18n: ^8.26.1 || ^9.2.0-beta.25 || ^9.3.0-beta.5
vue-i18n-bridge: ^9.2.0-beta.25 || ^9.3.0-beta.5
peerDependenciesMeta:
'@vue/composition-api':
optional: true
vue-i18n:
optional: true
vue-i18n-bridge:
optional: true
dependencies:
vue-i18n: 9.3.0-beta.10
dev: true
/@intlify/vue-router-bridge/0.8.0:
resolution: {integrity: sha512-CNxOgvyQcRhtGmRrksicL+HGjDijXtz+J/x04C/RslZ74CFdZkxjCe8MABkeD3xr+ry8G8tCm2nV2hLjZbynQw==}
engines: {node: '>= 12'}
hasBin: true
requiresBuild: true
peerDependencies:
'@vue/composition-api': ^1.0.0-rc.1
vue-router: ^4.0.0-0 || ^3.0.0
peerDependenciesMeta:
'@vue/composition-api':
optional: true
vue-router:
optional: true
dependencies:
vue-demi: 0.13.11
transitivePeerDependencies:
- vue
dev: true
/@ioredis/commands/1.2.0:
@ -977,6 +1068,39 @@ packages:
- vti
dev: true
/@nuxtjs/i18n/8.0.0-beta.5:
resolution: {integrity: sha512-UGyo80GDd8eYLCYPc+/XKPOQ0MUy7OLbSp5Zud95no6E9yAFxDNrgjaolTKV/f7U/QhSF0+xUOUC32TE8uj5Pg==}
engines: {node: ^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0}
dependencies:
'@intlify/bundle-utils': 3.4.0_vue-i18n@9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
'@intlify/unplugin-vue-i18n': 0.8.0_vue-i18n@9.3.0-beta.10
'@nuxt/kit': 3.0.0
'@vue/compiler-sfc': 3.2.45
cookie-es: 0.5.0
debug: 4.3.4
estree-walker: 3.0.1
is-https: 4.0.0
js-cookie: 3.0.1
knitwork: 1.0.0
magic-string: 0.26.7
mlly: 1.0.0
pathe: 1.0.0
pkg-types: 1.0.1
ufo: 1.0.0
unplugin: 1.0.0
vue-i18n: 9.3.0-beta.10
vue-i18n-routing: 0.10.1_vue-i18n@9.3.0-beta.10
transitivePeerDependencies:
- '@vue/composition-api'
- petite-vue-i18n
- rollup
- supports-color
- vue
- vue-i18n-bridge
- vue-router
dev: true
/@pinia/nuxt/0.4.5_typescript@4.9.3:
resolution: {integrity: sha512-lnJdZkpySxBArpiOLTJZtA+QSbODl6xIk4psgGWzrWiEwPjUSup/RmQ7zlWz7dmQTONA/mttR0j4V1Zh0b5NKA==}
dependencies:
@ -2323,6 +2447,14 @@ packages:
resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==}
dev: true
/acorn-jsx/5.3.2_acorn@7.4.1:
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
peerDependencies:
acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
dependencies:
acorn: 7.4.1
dev: true
/acorn-jsx/5.3.2_acorn@8.8.1:
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
peerDependencies:
@ -2336,6 +2468,12 @@ packages:
engines: {node: '>=0.4.0'}
dev: true
/acorn/7.4.1:
resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==}
engines: {node: '>=0.4.0'}
hasBin: true
dev: true
/acorn/8.8.1:
resolution: {integrity: sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==}
engines: {node: '>=0.4.0'}
@ -3993,6 +4131,15 @@ packages:
tsx: 3.12.1
dev: true
/espree/6.2.1:
resolution: {integrity: sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==}
engines: {node: '>=6.0.0'}
dependencies:
acorn: 7.4.1
acorn-jsx: 5.3.2_acorn@7.4.1
eslint-visitor-keys: 1.3.0
dev: true
/espree/9.4.1:
resolution: {integrity: sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@ -4805,6 +4952,10 @@ packages:
resolution: {integrity: sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==}
dev: true
/is-https/4.0.0:
resolution: {integrity: sha512-FeMLiqf8E5g6SdiVJsPcNZX8k4h2fBs1wp5Bb6uaNxn58ufK1axBqQZdmAQsqh0t9BuwFObybrdVJh6MKyPlyg==}
dev: true
/is-interactive/2.0.0:
resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==}
engines: {node: '>=12'}
@ -4944,6 +5095,11 @@ packages:
hasBin: true
dev: true
/js-cookie/3.0.1:
resolution: {integrity: sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw==}
engines: {node: '>=12'}
dev: true
/js-sdsl/4.2.0:
resolution: {integrity: sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==}
dev: true
@ -4990,6 +5146,17 @@ packages:
hasBin: true
dev: true
/jsonc-eslint-parser/1.4.1:
resolution: {integrity: sha512-hXBrvsR1rdjmB2kQmUjf1rEIa+TqHBGMge8pwi++C+Si1ad7EjZrJcpgwym+QGK/pqTx+K7keFAtLlVNdLRJOg==}
engines: {node: '>=8.10.0'}
dependencies:
acorn: 7.4.1
eslint-utils: 2.1.0
eslint-visitor-keys: 1.3.0
espree: 6.2.1
semver: 6.3.0
dev: true
/jsonc-eslint-parser/2.1.0:
resolution: {integrity: sha512-qCRJWlbP2v6HbmKW7R3lFbeiVWHo+oMJ0j+MizwvauqnCV/EvtAeEeuCgoc/ErtsuoKgYB8U4Ih8AxJbXoE6/g==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@ -7905,15 +8072,44 @@ packages:
- supports-color
dev: true
/vue-i18n/9.2.2:
resolution: {integrity: sha512-yswpwtj89rTBhegUAv9Mu37LNznyu3NpyLQmozF3i1hYOhwpG8RjcjIFIIfnu+2MDZJGSZPXaKWvnQA71Yv9TQ==}
/vue-i18n-routing/0.10.1_vue-i18n@9.3.0-beta.10:
resolution: {integrity: sha512-7sS6yPLtG87xQxeUIK1kt0SyyhVP57lnkmGciWIBRkM6TNRHzOpU9Ur0I2+IxHCPxmd9UkkwfLIhARoZRDcRDQ==}
engines: {node: '>= 14.6'}
peerDependencies:
'@vue/composition-api': ^1.0.0-rc.1
vue: ^2.6.14 || ^2.7.0 || ^3.2.0
vue-i18n: ^8.26.1 || ^9.2.0 || ^9.3.0-beta.10
vue-i18n-bridge: ^9.2.0 || ^9.3.0-beta.10
vue-router: ^3.5.3 || ^3.6.0 || ^4.0.0
peerDependenciesMeta:
'@vue/composition-api':
optional: true
vue:
optional: true
vue-i18n:
optional: true
vue-i18n-bridge:
optional: true
vue-router:
optional: true
dependencies:
'@intlify/shared': 9.3.0-beta.10
'@intlify/vue-i18n-bridge': 0.8.0_vue-i18n@9.3.0-beta.10
'@intlify/vue-router-bridge': 0.8.0
ufo: 1.0.0
vue-demi: 0.13.11
vue-i18n: 9.3.0-beta.10
dev: true
/vue-i18n/9.3.0-beta.10:
resolution: {integrity: sha512-w8ANcayAbF7ZxsSdnv0KwNViel1j6FqRJH3If+2gZgvERMOrKIz6oFQEQwEyiDl3W1DLITMvbgBQpwfUo7YU1Q==}
engines: {node: '>= 14'}
peerDependencies:
vue: ^3.0.0
dependencies:
'@intlify/core-base': 9.2.2
'@intlify/shared': 9.2.2
'@intlify/vue-devtools': 9.2.2
'@intlify/core-base': 9.3.0-beta.10
'@intlify/shared': 9.3.0-beta.10
'@intlify/vue-devtools': 9.3.0-beta.10
'@vue/devtools-api': 6.4.5
dev: true
@ -8087,6 +8283,14 @@ packages:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
dev: true
/yaml-eslint-parser/0.3.2:
resolution: {integrity: sha512-32kYO6kJUuZzqte82t4M/gB6/+11WAuHiEnK7FreMo20xsCKPeFH5tDBU7iWxR7zeJpNnMXfJyXwne48D0hGrg==}
dependencies:
eslint-visitor-keys: 1.3.0
lodash: 4.17.21
yaml: 1.10.2
dev: true
/yaml-eslint-parser/1.1.0:
resolution: {integrity: sha512-b464Q1fYiX1oYx2kE8k4mEp6S9Prk+tfDsY/IPxQ0FCjEuj3AKko5Skf3/yQJeYTTDyjDE+aWIJemnv29HvEWQ==}
engines: {node: ^14.17.0 || >=16.0.0}