UNPKG

@nuxtjs/i18n

Version:

Internationalization for Nuxt

41 lines (40 loc) 1.37 kB
import { effectScope } from "#imports"; import { assign } from "@intlify/shared"; import { getComposer } from "../compatibility.js"; export function extendI18n(i18n, { extendComposer, extendComposerInstance }) { const scope = effectScope(); const installI18n = i18n.install.bind(i18n); i18n.install = (app, ...options) => { const pluginOptions = assign({}, options[0]); pluginOptions.__composerExtend = (c) => { extendComposerInstance(c, getComposer(i18n)); return () => { }; }; if (i18n.mode === "legacy") { pluginOptions.__vueI18nExtend = (vueI18n) => { extendComposerInstance(vueI18n, getComposer(vueI18n)); return () => { }; }; } Reflect.apply(installI18n, i18n, [app, pluginOptions]); const globalComposer = getComposer(i18n); scope.run(() => { extendComposer(globalComposer); if (i18n.mode === "legacy" && "__composer" in i18n.global) { extendComposerInstance(i18n.global, getComposer(i18n.global)); } }); if (i18n.mode === "composition" && app.config.globalProperties.$i18n != null) { extendComposerInstance(app.config.globalProperties.$i18n, globalComposer); } if (app.unmount) { const unmountApp = app.unmount.bind(app); app.unmount = () => { scope.stop(); unmountApp(); }; } }; }