Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cannot export some properties and functions via useI18n as local scope #1663

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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