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.

24 lines (23 loc) 1.12 kB
import { isEnabledLocale } from "@i18n-micro/utils/active-locales"; import { resolveI18nConfigWithRuntimeOverrides } from "@i18n-micro/utils/runtime-config"; import { createError, defineEventHandler, getRouterParam, send, setResponseHeader } from "h3"; import { getI18nConfig } from "#i18n-internal/strategy"; import { useRuntimeConfig } from "#imports"; import { loadTranslationsFromServer } from "../utils/server-loader.js"; export default defineEventHandler(async (event) => { const page = getRouterParam(event, "page"); const locale = getRouterParam(event, "locale"); if (!locale || !page) { throw createError({ statusCode: 400, statusMessage: "Missing locale or page" }); } const config = resolveI18nConfigWithRuntimeOverrides( getI18nConfig(), useRuntimeConfig(event).public ); if (!isEnabledLocale(config.locales, locale)) { throw createError({ statusCode: 404, statusMessage: "Locale not found" }); } const { json } = await loadTranslationsFromServer(locale, page); setResponseHeader(event, "Content-Type", "application/json; charset=utf-8"); return send(event, json); });