language detector used in browser environment for i18next
Installations
npm install i18next-browser-languagedetector
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
22.14.0
NPM Version
10.9.2
Score
100
Supply Chain
34.5
Quality
88.4
Maintenance
100
Vulnerability
0
License
Releases
Unable to fetch releases
Contributors
Languages
JavaScript (94.61%)
TypeScript (5.39%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
i18next
Download Statistics
Total Downloads
227,184,967
Last Day
73,513
Last Week
1,953,318
Last Month
7,884,933
Last Year
83,222,296
GitHub Statistics
MIT License
887 Stars
254 Commits
90 Forks
9 Watchers
93 Branches
27 Contributors
Updated on Feb 15, 2025
Bundle Size
6.14 kB
Minified
2.15 kB
Minified + Gzipped
Package Meta Information
Latest Version
8.0.3
Package Id
i18next-browser-languagedetector@8.0.3
Unpacked Size
81.85 kB
Size
13.03 kB
File Count
17
NPM Version
10.9.2
Node Version
22.14.0
Published on
Feb 14, 2025
Total Downloads
Cumulative downloads
Total Downloads
227,184,967
Last Day
-7.9%
73,513
Compared to previous day
Last Week
2.3%
1,953,318
Compared to previous week
Last Month
32.7%
7,884,933
Compared to previous month
Last Year
51.1%
83,222,296
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
27
Introduction
This is an i18next language detection plugin used to detect user language in the browser, with support for:
- cookie (set cookie i18next=LANGUAGE)
- sessionStorage (set key i18nextLng=LANGUAGE)
- localStorage (set key i18nextLng=LANGUAGE)
- navigator (set browser language)
- querystring (append
?lng=LANGUAGE
to URL) - htmlTag (add html language tag <html lang="LANGUAGE" ...)
- path (http://my.site.com/LANGUAGE/...)
- subdomain (http://LANGUAGE.site.com/...)
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.use(LanguageDetector).init({ 5 supportedLngs: ['de', 'en', 'fr'], 6 ...i18nextOptions 7});
As with all modules you can either pass the constructor function (class) to the i18next.use
or to a concrete instance.
supportedLngs
is optional, but allows i18next to pick the best match from the list of detected languages. If it's not set then language
will be set to the first detected language, regardless of whether your application has translations for that language or not.
Detector Options
The default options can be found here.
1{ 2 // order and from where user language should be detected 3 order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag', 'path', 'subdomain'], 4 5 // keys or params to lookup language from 6 lookupQuerystring: 'lng', 7 lookupCookie: 'i18next', 8 lookupLocalStorage: 'i18nextLng', 9 lookupSessionStorage: 'i18nextLng', 10 lookupFromPathIndex: 0, 11 lookupFromSubdomainIndex: 0, 12 13 // cache user language on 14 caches: ['localStorage', 'cookie'], 15 excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage) 16 17 // optional expiry and domain for set cookie 18 cookieMinutes: 10, 19 cookieDomain: 'myDomain', 20 21 // optional htmlTag with lang attribute, the default is: 22 htmlTag: document.documentElement, 23 24 // optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) 25 cookieOptions: { path: '/', sameSite: 'strict' }, 26 27 // optional conversion function used to modify the detected language code 28 convertDetectedLanguage: 'Iso15897', 29 convertDetectedLanguage: (lng) => lng.replace('-', '_') 30}
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.use(LanguageDetector).init({ 5 detection: options, 6});
on construction:
1import LanguageDetector from 'i18next-browser-languagedetector'; 2const languageDetector = new LanguageDetector(null, options);
via calling init:
1import LanguageDetector from 'i18next-browser-languagedetector'; 2const languageDetector = new LanguageDetector(); 3languageDetector.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 // store it 13 }, 14};
adding it
1import LanguageDetector from 'i18next-browser-languagedetector'; 2const languageDetector = new LanguageDetector(); 3languageDetector.addDetector(myDetector); 4 5i18next.use(languageDetector).init({ 6 detection: options, 7});
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
localization as a service - locize.com
Needing a translation management? Want to edit your translations with an InContext Editor? Use the orginal provided to you by the maintainers of i18next!
With using locize you directly support the future of i18next and react-i18next.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 6/23 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
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'
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
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
2.5
/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 MoreOther packages similar to i18next-browser-languagedetector
@types/i18next-browser-languagedetector
Stub TypeScript definitions entry for i18next-browser-languagedetector, which provides its own types definitions
@ryancavanaugh/i18next-browser-languagedetector
Type definitions for i18next-browser-languagedetector 0.0.14 from https://www.github.com/DefinitelyTyped/DefinitelyTyped
i18next-browser-languagedetector-async
language detector used in browser environment for i18next
@byhuz/i18next-browser-languagedetector
language detector used in browser environment for i18next