@os-team/i18next-tld-language-detector
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -5,8 +5,11 @@ export declare const tldLocaleMap: { | ||
}; | ||
export declare const detectLanguageByHost: (host: string) => string; | ||
declare const tldLanguageDetector: { | ||
export declare const detectLanguageByHost: (host: string) => string | undefined; | ||
export declare const browserTldLanguageDetector: { | ||
name: string; | ||
lookup: () => string | undefined; | ||
}; | ||
export default tldLanguageDetector; | ||
export declare const httpTldLanguageDetector: { | ||
name: string; | ||
lookup: (req: any) => string | undefined; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.detectLanguageByHost = exports.tldLocaleMap = void 0; | ||
exports.httpTldLanguageDetector = exports.browserTldLanguageDetector = exports.detectLanguageByHost = exports.tldLocaleMap = void 0; | ||
exports.tldLocaleMap = { | ||
@@ -13,11 +13,10 @@ com: 'en', | ||
exports.detectLanguageByHost = detectLanguageByHost; | ||
const tldLanguageDetector = { | ||
exports.browserTldLanguageDetector = { | ||
name: 'tld', | ||
lookup: () => { | ||
if (typeof window === 'undefined') | ||
return undefined; | ||
return exports.detectLanguageByHost(window.location.hostname); | ||
}, | ||
lookup: () => exports.detectLanguageByHost(window.location.hostname), | ||
}; | ||
exports.default = tldLanguageDetector; | ||
exports.httpTldLanguageDetector = { | ||
name: 'tld', | ||
lookup: (req) => exports.detectLanguageByHost(req.get('Host')), | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@os-team/i18next-tld-language-detector", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -19,3 +19,3 @@ "repository": "git@gitlab.com:os-team/libs/utils.git", | ||
}, | ||
"gitHead": "b9ce08aaa962a7a5a348e5d4ac3aeb49933dcd0f" | ||
"gitHead": "065385374e73c868b677fda16f0d0c19dab42885" | ||
} |
@@ -13,13 +13,13 @@ # @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) | ||
Example of usage: | ||
### Client-side usage example | ||
```ts | ||
import i18next from 'i18next'; | ||
import HttpBackend from 'i18next-http-backend'; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
import HttpBackend from 'i18next-http-backend'; | ||
import { browserTldLanguageDetector } from '@os-team/i18next-tld-language-detector'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import tldLanguageDetector from '@os-team/i18next-tld-language-detector'; | ||
const languageDetector = new LanguageDetector(); | ||
languageDetector.addDetector(tldLanguageDetector); // Add tldLanguageDetector | ||
languageDetector.addDetector(browserTldLanguageDetector); // Add tldLanguageDetector | ||
@@ -40,1 +40,28 @@ i18next | ||
``` | ||
### Server-side usage example | ||
```ts | ||
import i18next from 'i18next'; | ||
import FsBackend from 'i18next-fs-backend'; | ||
import { LanguageDetector } from 'i18next-http-middleware'; | ||
import { httpTldLanguageDetector } from '@os-team/i18next-tld-language-detector'; | ||
import path from 'path'; | ||
const languageDetector = new LanguageDetector(); | ||
languageDetector.addDetector(httpTldLanguageDetector); // Add tldLanguageDetector | ||
i18next | ||
.use(FsBackend) | ||
.use(languageDetector) | ||
.init({ | ||
fallbackLng: 'en', | ||
ns: ['validation'], | ||
backend: { | ||
loadPath: path.join(__dirname, '../locales/{{lng}}/{{ns}}.json'), | ||
}, | ||
detection: { | ||
order: ['tld'], // Add tld | ||
}, | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5631
33
66