Skip to content

Commit

Permalink
fix: cannot export some perperties and functions via useI18n as local…
Browse files Browse the repository at this point in the history
… scope (#1663)
  • Loading branch information
kazupon committed Nov 21, 2022
1 parent 2bbf18d commit 378e2de
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 58 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -68,7 +68,7 @@
},
"dependencies": {
"@intlify/bundle-utils": "^3.4.0",
"@intlify/shared": "9.3.0-beta.7",
"@intlify/shared": "9.3.0-beta.10",
"@intlify/unplugin-vue-i18n": "^0.8.0",
"@nuxt/kit": "^3.0.0",
"@vue/compiler-sfc": "^3.2.44",
Expand All @@ -84,8 +84,8 @@
"pkg-types": "^1.0.1",
"ufo": "^1.0.0",
"unplugin": "^1.0.0",
"vue-i18n": "^9.3.0-beta.7",
"vue-i18n-routing": "^0.9.2"
"vue-i18n": "^9.3.0-beta.10",
"vue-i18n-routing": "^0.10.1"
},
"devDependencies": {
"@babel/parser": "^7.20.2",
Expand Down
3 changes: 2 additions & 1 deletion playground/pages/blog.vue
Expand Up @@ -9,9 +9,10 @@ defineI18nRoute({
}
})
const { t } = useI18n({
const { t, locales, baseUrl } = useI18n({
useScope: 'local'
})
console.log('locales', locales, baseUrl)
</script>

<template>
Expand Down
99 changes: 50 additions & 49 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions src/runtime/plugin.ts
Expand Up @@ -11,7 +11,8 @@ import {
switchLocalePath,
localeHead,
setLocale,
getLocale
getLocale,
getComposer
} from 'vue-i18n-routing'
import { defineNuxtPlugin, useRouter, useRoute, addRouteMiddleware, defineNuxtRouteMiddleware } from '#imports'
import { localeCodes, resolveNuxtI18nOptions, nuxtI18nInternalOptions } from '#build/i18n.options.mjs'
Expand All @@ -34,7 +35,7 @@ import {
} from '#build/i18n.internal.mjs'

import type { Composer, I18nOptions, Locale } from 'vue-i18n'
import type { LocaleObject, ExtendProperyDescripters } from 'vue-i18n-routing'
import type { LocaleObject, ExtendProperyDescripters, VueI18nRoutingPluginOptions } from 'vue-i18n-routing'
import type { NuxtApp } from '#imports'

type GetRouteBaseName = typeof getRouteBaseName
Expand Down Expand Up @@ -318,9 +319,24 @@ export default defineNuxtPlugin(async nuxt => {
}
})

// install vue-i18n
// TODO: should implement `{ inject: boolean }
app.use(i18n)
// vue-i18n installation
const pluginOptions: VueI18nRoutingPluginOptions = {
__composerExtend: (c: Composer) => {
const g = getComposer(i18n)
c.strategy = g.strategy
c.localeProperties = computed(() => g.localeProperties.value)
c.setLocale = g.setLocale
c.differentDomains = g.differentDomains
c.getBrowserLocale = g.getBrowserLocale
c.getLocaleCookie = g.getLocaleCookie
c.setLocaleCookie = g.setLocaleCookie
c.onBeforeLanguageSwitch = g.onBeforeLanguageSwitch
c.onLanguageSwitched = g.onLanguageSwitched
c.finalizePendingLocaleChange = g.finalizePendingLocaleChange
c.waitForPendingLocaleChange = g.waitForPendingLocaleChange
}
}
app.use(i18n, pluginOptions) // TODO: should implement `{ inject: false } via `nuxtjs/i18n` configuration

// inject for nuxt helpers
inejctNuxtHelpers(nuxtContext, i18n)
Expand Down

0 comments on commit 378e2de

Please sign in to comment.