@os-team/i18next-tld-language-detector
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -1,8 +0,7 @@ | ||
import { Request } from 'express'; | ||
export declare const detectLanguageByHost: (host: string) => string; | ||
declare const tldLanguageDetector: { | ||
name: string; | ||
lookup: (req: Request) => string | undefined; | ||
lookup: () => string | undefined; | ||
}; | ||
export default tldLanguageDetector; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,9 +15,6 @@ "use strict"; | ||
name: 'tld', | ||
lookup: (req) => { | ||
const host = typeof window === 'undefined' | ||
? req.get('host') | ||
: window.location.hostname; | ||
if (!host) | ||
lookup: () => { | ||
if (typeof window === 'undefined') | ||
return undefined; | ||
return exports.detectLanguageByHost(host); | ||
return exports.detectLanguageByHost(window.location.hostname); | ||
}, | ||
@@ -24,0 +21,0 @@ }; |
{ | ||
"name": "@os-team/i18next-tld-language-detector", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -19,9 +19,3 @@ "repository": "git@gitlab.com:os-team/libs/utils.git", | ||
}, | ||
"devDependencies": { | ||
"express": ">=4" | ||
}, | ||
"peerDependencies": { | ||
"express": ">=4" | ||
}, | ||
"gitHead": "266d38393491ea50d7b724d3e6808f86edcf05e0" | ||
"gitHead": "cb2a918fa5bc8c3391dd57c72c6dfd6b94f9d142" | ||
} |
@@ -13,19 +13,27 @@ # @os-team/i18next-tld-language-detector [![NPM version](https://img.shields.io/npm/v/@os-team/i18next-tld-language-detector)](https://yarnpkg.com/package/@os-team/i18next-tld-language-detector) [![BundlePhobia](https://img.shields.io/bundlephobia/minzip/@os-team/i18next-tld-language-detector)](https://bundlephobia.com/result?p=@os-team/i18next-tld-language-detector) | ||
If you use [next-i18next](https://github.com/isaachinman/next-i18next), add the language detector to the `customDetectors` and include the `tld` detector to `detection.order`. | ||
Example of usage: | ||
```ts | ||
import NextI18Next from 'next-i18next'; | ||
import path from 'path'; | ||
import i18next from 'i18next'; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
import HttpBackend from 'i18next-http-backend'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import tldLanguageDetector from '@os-team/i18next-tld-language-detector'; | ||
const i18Next = new NextI18Next({ | ||
defaultLanguage: 'en', | ||
otherLanguages: ['ru'], | ||
localePath: path.resolve('./public/static/locales'), | ||
fallbackLng: false, | ||
customDetectors: [tldLanguageDetector], | ||
detection: { | ||
order: ['tld'], | ||
}, | ||
}); | ||
const languageDetector = new LanguageDetector(); | ||
languageDetector.addDetector(tldLanguageDetector); // Add tldLanguageDetector | ||
i18next | ||
.use(HttpBackend) | ||
.use(languageDetector) | ||
.use(initReactI18next) | ||
.init({ | ||
detection: { | ||
order: ['cookie', 'tld'], // Add tld | ||
lookupCookie: 'lng', | ||
caches: ['cookie'], | ||
}, | ||
}); | ||
export default i18next; | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
0
0
39
4512
27