本文整理汇总了TypeScript中i18next-browser-languagedetector.addDetector函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addDetector函数的具体用法?TypeScript addDetector怎么用?TypeScript addDetector使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addDetector函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: lookup
// cache user language on
caches: ['localStorage', 'cookie'],
// optional expire and domain for set cookie
cookieMinutes: 10,
cookieDomain: 'myDomain'
};
var myDetector = {
name: 'myDetectorsName',
lookup(options: Object) {
// options -> are passed in options
return 'en';
},
cacheUserLanguage(lng: string, options: Object) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
}
};
i18next.use(LngDetector).init({
detection: options
});
const lngDetector = new LngDetector(null, options);
lngDetector.init(options);
lngDetector.addDetector(myDetector);
示例2: lookup
lookup(options: LngDetector.DetectorOptions) {
// options -> are passed in options
return "en";
},
cacheUserLanguage(lng: string, options: LngDetector.DetectorOptions) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
}
};
const customDetector2: LngDetector.CustomDetector = {
name: "myDetectorsName",
lookup(options: LngDetector.DetectorOptions) {
return undefined;
}
};
const lngDetector = new LngDetector(null, options);
lngDetector.init(options);
lngDetector.addDetector(customDetector);
i18next
.use(lngDetector)
.init({
detection: options
});