UNPKG

nuxt-intlayer

Version:

Easily internationalize i18n your Nuxt applications with type-safe multilingual content management.

95 lines 3.52 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var module_exports = {}; __export(module_exports, { module: () => module2 }); module.exports = __toCommonJS(module_exports); var import_chokidar = require("@intlayer/chokidar"); var import_config = require("@intlayer/config"); var import_kit = require("@nuxt/kit"); var import_path = require("path"); var import_vite_intlayer = require("vite-intlayer"); const import_meta = {}; const module2 = (0, import_kit.defineNuxtModule)({ meta: { name: "nuxt-intlayer" }, setup({}, nuxt) { const configuration = (0, import_config.getConfiguration)(); const { optimize } = configuration.build; const resolver = (0, import_kit.createResolver)(import_meta.url); (0, import_kit.addPlugin)({ src: resolver.resolve("./runtime/intlayer-plugin"), mode: "all" }); (0, import_kit.addPlugin)({ src: resolver.resolve("./runtime/html-lang"), mode: "all" }); nuxt.hook("vite:extendConfig", (viteConfig, { isServer }) => { if (isServer) { (viteConfig.plugins ?? []).push((0, import_vite_intlayer.intlayerMiddleware)()); } if (optimize) { viteConfig.plugins?.push((0, import_vite_intlayer.intlayerPrune)(configuration)); } }); nuxt.hook("build:before", async () => (0, import_chokidar.prepareIntlayer)(configuration)); nuxt.hook("ready", async () => { if (configuration.content.watch) { (0, import_chokidar.watch)({ configuration }); } }); nuxt.options.alias = { ...nuxt.options.alias, ...(0, import_config.getAlias)({ configuration, formatter: (value) => (0, import_path.resolve)(value) }) }; nuxt.hook("pages:extend", (pages) => { const { internationalization: { locales, defaultLocale }, middleware: { prefixDefault, noPrefix } } = configuration; if (noPrefix) return; const filteredLocales = prefixDefault ? locales : locales.filter((locale) => locale !== defaultLocale); const localeGroupRegex = filteredLocales.map(String).join("|"); if (!localeGroupRegex) return; const originalPages = [...pages]; for (const page of originalPages) { if (page.path.startsWith("/:locale")) continue; const dynPathPrefix = `/:locale(${localeGroupRegex})`; const isIndex = page.path === "/"; const prefixedPath = isIndex ? `${dynPathPrefix}` : `${dynPathPrefix}${page.path}`; pages.push({ ...page, path: prefixedPath, name: page.name ? `${page.name}___i18n` : void 0 }); } }); } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { module }); //# sourceMappingURL=module.cjs.map