UNPKG

2.1 kBTypeScriptView Raw
1import * as i18next from 'i18next';
2
3interface CookieOptions {
4 maxAge?: number;
5 expires?: Date;
6 httpOnly?: boolean;
7 path?: string;
8 domain?: string;
9 secure?: boolean;
10 sameSite?: boolean | 'lax' | 'strict' | 'none';
11}
12
13interface DetectorOptions {
14 /**
15 * order and from where user language should be detected
16 */
17 order?: Array<
18 'querystring' | 'cookie' | 'sessionStorage' | 'localStorage' | 'navigator' | 'htmlTag' | string
19 >;
20
21 /**
22 * keys or params to lookup language from
23 */
24 lookupQuerystring?: string;
25 lookupCookie?: string;
26 lookupSessionStorage?: string;
27 lookupLocalStorage?: string;
28 lookupFromPathIndex?: number;
29 lookupFromSubdomainIndex?: number;
30
31 /**
32 * cache user language on
33 */
34 caches?: string[];
35
36 /**
37 * languages to not persist (cookie, localStorage)
38 */
39 excludeCacheFor?: string[];
40
41 /**
42 * optional expire for set cookie
43 * @default 10
44 */
45 cookieMinutes?: number;
46
47 /**
48 * optional domain for set cookie
49 */
50 cookieDomain?: string;
51
52 /**
53 * optional cookie options
54 */
55 cookieOptions?: CookieOptions
56
57 /**
58 * optional htmlTag with lang attribute
59 * @default document.documentElement
60 */
61 htmlTag?: HTMLElement | null;
62}
63
64interface CustomDetector {
65 name: string;
66 cacheUserLanguage?(lng: string, options: DetectorOptions): void;
67 lookup(options: DetectorOptions): string | string[] | undefined;
68}
69
70export default class I18nextBrowserLanguageDetector implements i18next.LanguageDetectorModule {
71 constructor(services?: any, options?: DetectorOptions);
72 /**
73 * Adds detector.
74 */
75 addDetector(detector: CustomDetector): I18nextBrowserLanguageDetector;
76
77 /**
78 * Initializes detector.
79 */
80 init(services?: any, options?: DetectorOptions): void;
81
82 detect(detectionOrder?: DetectorOptions['order']): string | string[] | undefined;
83
84 cacheUserLanguage(lng: string, caches?: string[]): void;
85
86 type: 'languageDetector';
87 detectors: { [key: string]: any };
88 services: any;
89 i18nOptions: any;
90}
91
92declare module 'i18next' {
93 interface PluginOptions {
94 detection?: DetectorOptions;
95 }
96}