UNPKG

nuxt-i18n-micro

Version:

Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.

22 lines (21 loc) 873 B
import { useLocaleHead } from "../composables/useLocaleHead.js"; import { useRequestURL, useHead, defineNuxtPlugin, useRuntimeConfig } from "#imports"; const host = process.env.HOST ?? "localhost"; const port = process.env.PORT ?? "host"; export default defineNuxtPlugin((nuxtApp) => { const config = useRuntimeConfig(); const i18nConfig = config.public.i18nConfig; const schema = port === "443" ? "https" : "http"; const defaultUrl = port === "80" || port === "443" ? `${schema}://${host}` : `${schema}://${host}:${port}`; nuxtApp.hook("app:rendered", (_context) => { const url = useRequestURL(); const baseUrl = (i18nConfig.metaBaseUrl || url.origin || defaultUrl).toString(); const head = useLocaleHead({ addDirAttribute: true, identifierAttribute: "id", addSeoAttributes: true, baseUrl }); useHead(head); }); });