Gathering detailed insights and metrics for @byhuz/i18next-browser-languagedetector
Gathering detailed insights and metrics for @byhuz/i18next-browser-languagedetector
Gathering detailed insights and metrics for @byhuz/i18next-browser-languagedetector
Gathering detailed insights and metrics for @byhuz/i18next-browser-languagedetector
language detector used in browser environment for i18next
npm install @byhuz/i18next-browser-languagedetector
Typescript
Module System
Node Version
NPM Version
72.8
Supply Chain
99.4
Quality
80.1
Maintenance
100
Vulnerability
100
License
JavaScript (94.91%)
TypeScript (5.09%)
Total Downloads
5,194
Last Day
2
Last Week
11
Last Month
21
Last Year
271
MIT License
901 Stars
264 Commits
92 Forks
8 Watchers
93 Branches
29 Contributors
Updated on Apr 30, 2025
Minified
Minified + Gzipped
Latest Version
4.2.2
Package Id
@byhuz/i18next-browser-languagedetector@4.2.2
Unpacked Size
50.59 kB
Size
9.84 kB
File Count
8
NPM Version
6.14.4
Node Version
12.16.1
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
266.7%
11
Compared to previous week
Last Month
5%
21
Compared to previous month
Last Year
-62.8%
271
Compared to previous year
1
26
This is a i18next language detection plugin use to detect user language in the browser with support for:
?lng=LANGUAGE
to URL)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
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.
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 23 // only detect languages that are in the whitelist 24 checkWhitelist: true, 25 26 // fallback to a similar whitelist language 27 // Example 1: Browser language is 'es' 28 // if 'es' is not found in whitelist, first fallback to any whitelist language that starts with 'es-', then fallback to fallbackLng ('es' -> 'es-*' -> fallbackLng) 29 // Example 2: Browser language is 'es-MX' 30 // if 'es-MX' is not found in whitelist, first fallback to 'es', then fallback to 'es-*', then fallback to fallbackLng ('es-MX' -> 'es' -> 'es-*' -> fallbackLng) 31 checkForSimilarInWhitelist: false, 32 33 // optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) 34 cookieOptions: {path:'/'} 35}
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);
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};
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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
14 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
Found 8/23 approved changesets -- score normalized to 3
Reason
8 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
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