UNPKG

@pulzar/core

Version:

Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support

99 lines 2.56 kB
import { TFunction, i18n } from "i18next"; import type { FastifyRequest, FastifyPluginAsync } from "fastify"; export interface I18nOptions { defaultLanguage: string; supportedLanguages: string[]; localesPath: string; fallbackLanguage?: string; loadPath?: string; addPath?: string; enableHotReload?: boolean; detectionOrder?: ("query" | "header" | "cookie" | "session" | "path" | "subdomain")[]; cookieName?: string; queryParameter?: string; headerName?: string; sessionKey?: string; pathIndex?: number; subdomainIndex?: number; caching?: boolean; preload?: string[]; debug?: boolean; } export interface I18nContext { language: string; t: TFunction; i18n: i18n; detectLanguage(): string; changeLanguage(language: string): Promise<TFunction>; getLanguages(): string[]; getResourceBundle(language: string, namespace?: string): any; } export declare class I18nManager { private i18n; private options; private watcher?; private initialized; constructor(options?: Partial<I18nOptions>); /** * Initialize the i18n system */ initialize(): Promise<void>; /** * Setup hot reload for locale files */ private setupHotReload; /** * Detect language from request */ detectLanguageFromRequest(request: FastifyRequest): string; /** * Parse Accept-Language header */ private parseAcceptLanguage; /** * Parse cookies header */ private parseCookies; /** * Check if language is supported */ private isLanguageSupported; /** * Create i18n context for a request */ createContext(request: FastifyRequest): I18nContext; /** * Get main i18n instance */ getInstance(): i18n; /** * Get supported languages */ getSupportedLanguages(): string[]; /** * Get default language */ getDefaultLanguage(): string; /** * Add new language support */ addLanguage(language: string, resources?: any): Promise<void>; /** * Remove language support */ removeLanguage(language: string): void; /** * Shutdown i18n system */ shutdown(): Promise<void>; } /** * Fastify plugin for i18n */ export declare function createI18nPlugin(options?: Partial<I18nOptions>): FastifyPluginAsync; /** * Create default locale structure */ export declare function createDefaultLocales(): Record<string, any>; export default I18nManager; //# sourceMappingURL=i18n.d.ts.map