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.
120 lines (119 loc) • 10 kB
TypeScript
import type { RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric, RouteLocationNamedRaw } from 'vue-router';
import { useTranslationHelper } from '@i18n-micro/core';
import type { Locale, I18nRouteParams, Params, Translations, CleanTranslation, MissingHandler } from '@i18n-micro/types';
declare const _default: import("nuxt/app").Plugin<{
i18n: undefined;
__micro: boolean;
getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
getLocaleName: () => string | null;
defaultLocale: () => string | undefined;
getLocales: () => Locale[];
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
t: (key: string, params?: Params, defaultValue?: string | null, route?: RouteLocationNormalizedLoaded) => CleanTranslation;
ts: (key: string, params?: Params, defaultValue?: string, route?: RouteLocationNormalizedLoaded) => string;
_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
_ts: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string) => string;
tc: (key: string, params: number | Params, defaultValue?: string) => string;
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
has: (key: string, route?: RouteLocationNormalizedLoaded) => boolean;
mergeTranslations: (newTranslations: Translations) => void;
mergeGlobalTranslations: (newTranslations: Translations) => void;
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
clearCache: () => void;
switchLocalePath: (toLocale: string) => string;
switchLocale: (toLocale: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
localeRoute: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => RouteLocationResolved;
localePath: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => string;
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
loadPageTranslations: (locale: string, routeName: string, translations: Translations) => Promise<void>;
setMissingHandler: (handler: MissingHandler | null) => void;
helper: {
hasCache(locale: string, page: string): boolean;
getCache(locale: string, routeName: string): Map<string, unknown> | undefined;
setCache(locale: string, routeName: string, cache: Map<string, Translations | unknown>): void;
mergeTranslation(locale: string, routeName: string, newTranslations: Translations, force?: boolean): void;
mergeGlobalTranslation(locale: string, newTranslations: Translations, force?: boolean): void;
hasGeneralTranslation(locale: string): boolean;
hasPageTranslation(locale: string, routeName: string): boolean;
hasTranslation: (locale: string, key: import("@i18n-micro/types").TranslationKey) => boolean;
getTranslation: <T = unknown>(locale: string, routeName: string, key: import("@i18n-micro/types").TranslationKey) => T | null;
loadPageTranslations(locale: string, routeName: string, translations: Translations): Promise<void>;
loadTranslations(locale: string, translations: Translations): Promise<void>;
clearCache(): void;
};
}> & import("nuxt/app").ObjectPlugin<{
i18n: undefined;
__micro: boolean;
getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
getLocaleName: () => string | null;
defaultLocale: () => string | undefined;
getLocales: () => Locale[];
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
t: (key: string, params?: Params, defaultValue?: string | null, route?: RouteLocationNormalizedLoaded) => CleanTranslation;
ts: (key: string, params?: Params, defaultValue?: string, route?: RouteLocationNormalizedLoaded) => string;
_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
_ts: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string) => string;
tc: (key: string, params: number | Params, defaultValue?: string) => string;
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
has: (key: string, route?: RouteLocationNormalizedLoaded) => boolean;
mergeTranslations: (newTranslations: Translations) => void;
mergeGlobalTranslations: (newTranslations: Translations) => void;
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
clearCache: () => void;
switchLocalePath: (toLocale: string) => string;
switchLocale: (toLocale: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) => string | false | void | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric | Promise<false | void | import("vue-router").NavigationFailure>;
localeRoute: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => RouteLocationResolved;
localePath: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => string;
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
loadPageTranslations: (locale: string, routeName: string, translations: Translations) => Promise<void>;
setMissingHandler: (handler: MissingHandler | null) => void;
helper: {
hasCache(locale: string, page: string): boolean;
getCache(locale: string, routeName: string): Map<string, unknown> | undefined;
setCache(locale: string, routeName: string, cache: Map<string, Translations | unknown>): void;
mergeTranslation(locale: string, routeName: string, newTranslations: Translations, force?: boolean): void;
mergeGlobalTranslation(locale: string, newTranslations: Translations, force?: boolean): void;
hasGeneralTranslation(locale: string): boolean;
hasPageTranslation(locale: string, routeName: string): boolean;
hasTranslation: (locale: string, key: import("@i18n-micro/types").TranslationKey) => boolean;
getTranslation: <T = unknown>(locale: string, routeName: string, key: import("@i18n-micro/types").TranslationKey) => T | null;
loadPageTranslations(locale: string, routeName: string, translations: Translations): Promise<void>;
loadTranslations(locale: string, translations: Translations): Promise<void>;
clearCache(): void;
};
}>;
export default _default;
export interface PluginsInjections {
$getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
$getLocaleName: () => string | null;
$getLocales: () => Locale[];
$defaultLocale: () => string | undefined;
$getRouteName: (route?: RouteLocationNamedRaw | RouteLocationResolvedGeneric, locale?: string) => string;
$t: (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
$_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
$ts: (key: string, params?: Params, defaultValue?: string) => string;
$_ts: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => string;
$tc: (key: string, params: number | Params, defaultValue?: string) => string;
$tn: (value: number, options?: Intl.NumberFormatOptions) => string;
$td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
$tdr: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
$has: (key: string) => boolean;
$mergeTranslations: (newTranslations: Translations) => void;
$mergeGlobalTranslations: (newTranslations: Translations) => void;
$switchLocaleRoute: (locale: string) => RouteLocationRaw;
$switchLocalePath: (locale: string) => string;
$switchLocale: (locale: string) => void;
$switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
$localeRoute: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => RouteLocationResolved;
$localePath: (to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string) => string;
$setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
$loadPageTranslations: (locale: string, routeName: string, translations: Translations) => Promise<void>;
$setMissingHandler: (handler: MissingHandler | null) => void;
helper: ReturnType<typeof useTranslationHelper>;
}