Installations
npm install i18next-browser-languagedetector-async
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
10.16.0
NPM Version
6.9.0
Score
74.2
Supply Chain
99
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.75%)
TypeScript (6.25%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
imdreamrunner
Download Statistics
Total Downloads
1,465
Last Day
4
Last Week
14
Last Month
63
Last Year
404
GitHub Statistics
MIT License
121 Commits
1 Watchers
92 Branches
1 Contributors
Updated on Aug 02, 2019
Bundle Size
7.11 kB
Minified
2.30 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.4
Package Id
i18next-browser-languagedetector-async@0.0.4
Unpacked Size
81.87 kB
Size
17.81 kB
File Count
40
NPM Version
6.9.0
Node Version
10.16.0
Total Downloads
Cumulative downloads
Total Downloads
1,465
Last Day
100%
4
Compared to previous day
Last Week
16.7%
14
Compared to previous week
Last Month
65.8%
63
Compared to previous month
Last Year
86.2%
404
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
22
Introduction
This is a i18next language detection plugin use to detect user language in the browser with support for:
- cookie
- localStorage
- navigator
- querystring (append
?lng=LANGUAGE
to URL) - htmlTag
- path
- subdomain
Getting started
Source can be loaded via npm, bower or downloaded from this repo.
# npm package
$ npm install i18next-browser-languagedetector
# bower
$ bower install i18next-browser-languagedetector
- If you don't use a module loader it will be added to
window.i18nextBrowserLanguageDetector
Wiring up:
1import i18next from 'i18next'; 2import LanguageDetector from 'i18next-browser-languagedetector'; 3 4i18next 5 .use(LanguageDetector) 6 .init(i18nextOptions);
As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
Detector Options
1{ 2 // order and from where user language should be detected 3 order: ['querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'], 4 5 // keys or params to lookup language from 6 lookupQuerystring: 'lng', 7 lookupCookie: 'i18next', 8 lookupLocalStorage: 'i18nextLng', 9 lookupFromPathIndex: 0, 10 lookupFromSubdomainIndex: 0, 11 12 // cache user language on 13 caches: ['localStorage', 'cookie'], 14 excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage) 15 16 // optional expire and domain for set cookie 17 cookieMinutes: 10, 18 cookieDomain: 'myDomain', 19 20 // optional htmlTag with lang attribute, the default is: 21 htmlTag: document.documentElement 22}
Options can be passed in:
preferred - by setting options.detection in i18next.init:
1import i18next from 'i18next'; 2import LanguageDetector from 'i18next-browser-languagedetector'; 3 4i18next 5 .use(LanguageDetector) 6 .init({ 7 detection: options 8 });
on construction:
1 import LanguageDetector from 'i18next-browser-languagedetector'; 2 const languageDetector = new LanguageDetector(null, options);
via calling init:
1 import LanguageDetector from 'i18next-browser-languagedetector'; 2 const languageDetector = new LanguageDetector(); 3 lngDetector.init(options);
Adding own detection functionality
interface
1export default { 2 name: 'myDetectorsName', 3 4 lookup(options) { 5 // options -> are passed in options 6 return 'en'; 7 }, 8 9 cacheUserLanguage(lng, options) { 10 // options -> are passed in options 11 // lng -> current language, will be called after init and on changeLanguage 12 13 // store it 14 } 15};
adding it
1 import LanguageDetector from 'i18next-browser-languagedetector'; 2 const languageDetector = new LanguageDetector(); 3 languageDetector.addDetector(myDetector); 4 5 i18next 6 .use(languageDetector) 7 .init({ 8 detection: options 9 });
Don't forget: You have to add the name of your detector (myDetectorsName
in this case) to the order
array in your options
object. Without that, your detector won't be used. See the Detector Options section for more.
Gold Sponsors

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More