import cookie from 'cookie'; type Detections = D extends undefined ? T : T | U; interface BaseDetector = Record, U extends Record = Record> { name: string; resolveLng: (options: { lookup: any; lngs: string[]; } & T) => string | undefined | null; persistLng?: (lng: string, options: { lookup: any; } & U) => void; } type ResolveDetectorName$1 = T['name']; type ResolveDetectorLookup$1 = Parameters[0]['lookup']; type Detector$1 = BaseDetector<{ request: Request; }, { headers: Headers; }>; declare class Cookie$1 implements Detector$1 { name: "cookie"; resolveLng(options: { lookup: string; request: Request; }): string | null | undefined; persistLng(lng: string, options: { lookup: string; attribute?: cookie.SerializeOptions; headers: Headers; }): void; } declare class Header implements Detector$1 { name: "header"; resolveLng(options: { request: Request; lngs: string[]; }): string | null | undefined; } declare class Path$1 implements Detector$1 { name: "path"; resolveLng(options: { lookup?: number; request: Request; }): string | undefined; } declare class QueryString$1 implements Detector$1 { name: "querystring"; resolveLng(options: { lookup: string; request: Request; }): string | null; } type Detector = BaseDetector, { lngs: string[]; }>; interface CookieAttributes { /** * Define when the cookie will be removed. Value can be a Number * which will be interpreted as days from time of creation or a * Date instance. If omitted, the cookie becomes a session cookie. */ expires?: number | Date | undefined; /** * Define the path where the cookie is available. Defaults to '/' */ path?: string | undefined; /** * Define the domain where the cookie is available. Defaults to * the domain of the page where the cookie was created. */ domain?: string | undefined; /** * A Boolean indicating if the cookie transmission requires a * secure protocol (https). Defaults to false. */ secure?: boolean | undefined; /** * Asserts that a cookie must not be sent with cross-origin requests, * providing some protection against cross-site request forgery * attacks (CSRF) */ sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined; /** * An attribute which will be serialized, conformably to RFC 6265 * section 5.2. */ [property: string]: any; } declare class Cookie implements Detector { name: "cookie"; resolveLng(options: { lookup: string; }): string | null; persistLng(lng: string, options: { lookup: string; attributes?: CookieAttributes; }): string | undefined; } declare class HtmlTag implements Detector { name: "htmlTag"; resolveLng(options: { lookup: string; }): string | null | undefined; persistLng(lng: string, options: { lookup: string; }): void; } declare class LocalStorage implements Detector { name: "localStorage"; resolveLng(options: { lookup: string; }): string | null; persistLng(lng: string, options: { lookup: string; }): void; } declare class Navigator implements Detector { name: "navigator"; resolveLng: (options: { lngs: string[]; }) => string | undefined; } declare class Path implements Detector { name: "path"; resolveLng(options: { lookup: number; }): string | undefined; persistLng(lng: string, options: { lookup: number | string; lngs: string[]; }): void; } declare class QueryString implements Detector { name: "querystring"; resolveLng(options: { lookup: string; }): string | null; persistLng(lng: string, options: { lookup: string; }): void; } declare class SessionStorage implements Detector { name: "sessionStorage"; resolveLng(options: { lookup: string; }): string | null; persistLng(lng: string, options: { lookup: string; }): void; } type LogLevel = 'debug' | 'log' | 'warn' | 'error' | 'silent'; type ResolveDetectorName = T['name']; type ResolveDetectorLookup = Parameters[0]['lookup']; interface I18nAllyClientOptions { /** * @description * Specify language to use * * 指定当前使用的语言 */ lng?: string; /** * @description * Specify languages to use * * 指定当前使用的语言列表。默认从vite插件中获取 */ lngs?: string[]; /** * @description * Namespaces to load * * 指定当前使用的命名空间列表 */ ns?: string[]; /** * @description * If no resource for current language, fallback to `fallbackLng` * * 如果当前语言没有资源,则回退到`fallbackLng` */ fallbackLng: string; /** * @description * Language will be lowercased eg. en-US --> en-us * * 是否将语言转换为小写字母 * @default false */ lowerCaseLng?: boolean; /** * logLevel * @description * Log level for i18n-ally * * @default 'log' */ logLevel?: LogLevel; /** * @description * Before i18n-ally is initialized * * i18n-ally初始化之前的回调 */ onBeforeInit?: (current: { lng: string; ns: string[]; }, all: { lngs: string[]; ns: { [lng: string]: string[]; }; }) => Promise | void; /** * @description * i18n-ally initialized * * i18n-ally初始化完成的回调 */ onInited?: (current: { lng: string; ns: string[]; }, all: { lngs: string[]; ns: { [lng: string]: string[]; }; }) => Promise | void; /** * @description * resources loaded callback * * i18n 资源加载完成的回调 */ onResourceLoaded?: (resources: { [key in string]: string; }, current: { lng: string; ns: string | undefined; }) => Promise | void; /** * @description * Detect and cache user language on html tag / querystring / cookie / localStorage / sessionStorage etc. * * Like `i18next-browser-languagedetector` * * The order of detection determines the priority of language detection. The earlier it appears, the higher the priority. * * 探测和缓存用户语言的方式,支持html标签、查询字符串、cookie、本地存储、会话存储等 * * 和`i18next-browser-languagedetector`类似 * 数组顺序决定了语言探测的优先级,越前的优先级越高 */ detection?: Detections<{ detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; } | { detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; } | { detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; attributes?: CookieAttributes; } | { detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; } | { detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; } | { detect: ResolveDetectorName; } | { detect: ResolveDetectorName; /** * @description * The path index to get language * * 路径中获取语言的索引 * * @example * '/en-US/...' => 0 * '/prefix/en-US' => 1 */ lookup?: ResolveDetectorLookup; cache?: boolean; }, D extends Detector[] ? { detect: ResolveDetectorName; lookup?: ResolveDetectorLookup; cache?: boolean; } : undefined, D>[]; /** * @description * Custom detectors * * 自定义探测器 */ customDetectors?: D; } type I18nAllyServerOptions = Pick & { detection?: Detections<{ detect: ResolveDetectorName$1; lookup: ResolveDetectorLookup$1; attributes?: Cookies.CookieAttributes; cache?: boolean; } | { detect: ResolveDetectorName$1
; } | { detect: ResolveDetectorName$1; lookup?: ResolveDetectorLookup$1; } | { detect: ResolveDetectorName$1; lookup: ResolveDetectorLookup$1; }, D extends Detector$1[] ? { detect: ResolveDetectorName$1; lookup?: ResolveDetectorLookup$1; } : undefined, D>[]; }; declare class I18nAllyServer { private readonly options; private detectorMap; lngs: string[]; fallbackLng: string; supportedLngs: string[]; constructor(options: I18nAllyServerOptions); detect(request: Request): string; persistLng(lng: string, headers: Headers): void; static getSupportedLngs(): string[]; static getSupportedNs(): { [k: string]: string[]; }; private formatLngs; } export { Cookie$1 as Cookie, type Detector$1 as Detector, Header, I18nAllyServer, type I18nAllyServerOptions, Path$1 as Path, QueryString$1 as QueryString };