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.
36 lines (35 loc) • 1.17 kB
JavaScript
import { useNuxtApp } from "#imports";
export function useI18n() {
const nuxtApp = useNuxtApp();
const injections = {
$defaultLocale: nuxtApp.$defaultLocale,
$getLocale: nuxtApp.$getLocale,
$getLocaleName: nuxtApp.$getLocaleName,
$getLocales: nuxtApp.$getLocales,
$getRouteName: nuxtApp.$getRouteName,
$t: nuxtApp.$t,
$ts: nuxtApp.$ts,
$tn: nuxtApp.$tn,
$td: nuxtApp.$td,
$tdr: nuxtApp.$tdr,
$has: nuxtApp.$has,
$tc: nuxtApp.$tc,
$mergeTranslations: nuxtApp.$mergeTranslations,
$mergeGlobalTranslations: nuxtApp.$mergeGlobalTranslations,
$setI18nRouteParams: nuxtApp.$setI18nRouteParams,
$switchLocaleRoute: nuxtApp.$switchLocaleRoute,
$switchLocalePath: nuxtApp.$switchLocalePath,
$switchLocale: nuxtApp.$switchLocale,
$switchRoute: nuxtApp.$switchRoute,
$localeRoute: nuxtApp.$localeRoute,
$localePath: nuxtApp.$localePath,
$loadPageTranslations: nuxtApp.$loadPageTranslations
};
const noDollarInjections = Object.fromEntries(
Object.entries(injections).map(([key, value]) => [key.slice(1), value])
);
return {
...injections,
...noDollarInjections
};
}