UNPKG

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