nuxt-intlayer
Version:
Easily internationalize i18n your Nuxt applications with type-safe multilingual content management.
1 lines • 2 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/runtime/intlayer-plugin.ts"],"sourcesContent":["// @ts-nocheck -- Nuxt runtime types are provided at application level\nimport { defineNuxtPlugin } from '#app';\nimport { useRoute } from '#imports';\nimport { Locales } from '@intlayer/config';\nimport { createIntlayerClient, installIntlayer } from 'vue-intlayer';\n\n/**\n * Nuxt client plugin injected by `nuxt-intlayer` module.\n * It installs the Intlayer Vue composables in the current Nuxt application and keeps\n * the active locale in sync with the current route (e.g. `/fr/about` → `fr`).\n */\nexport default defineNuxtPlugin((nuxtApp) => {\n /**\n * Register the Intlayer provider. We don't pass an explicit locale here so it\n * will fallback to the `defaultLocale` defined in the user configuration.\n * We will synchronise the active locale afterwards, once the current route\n * information is reliably available.\n */\n installIntlayer(nuxtApp.vueApp);\n\n // Obtain a reference to the singleton Intlayer client so we can update the\n // locale reactively whenever the route changes.\n const { setLocale } = createIntlayerClient();\n\n const route = useRoute();\n\n // Helper that applies the `:locale` route param (if any) to Intlayer.\n const syncLocale = () => {\n const localeParam = route.params.locale as Locales | undefined;\n if (localeParam) setLocale(localeParam);\n };\n\n // Initial sync (client & server) once the plugin is executed.\n syncLocale();\n\n // Keep Intlayer locale in sync on every navigation.\n nuxtApp.hook('page:start', () => {\n syncLocale();\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAiC;AACjC,qBAAyB;AAEzB,0BAAsD;AAOtD,IAAO,8BAAQ,6BAAiB,CAAC,YAAY;AAO3C,2CAAgB,QAAQ,MAAM;AAI9B,QAAM,EAAE,UAAU,QAAI,0CAAqB;AAE3C,QAAM,YAAQ,yBAAS;AAGvB,QAAM,aAAa,MAAM;AACvB,UAAM,cAAc,MAAM,OAAO;AACjC,QAAI,YAAa,WAAU,WAAW;AAAA,EACxC;AAGA,aAAW;AAGX,UAAQ,KAAK,cAAc,MAAM;AAC/B,eAAW;AAAA,EACb,CAAC;AACH,CAAC;","names":[]}