Gathering detailed insights and metrics for i18next-http-event
NPM was acquired by GitHub in March 2020.
Gathering detailed insights and metrics for i18next-http-event
NPM was acquired by GitHub in March 2020.
npm install i18next-http-event
57.8
Supply Chain
98
Quality
80.8
Maintenance
100
Vulnerability
100
License
453 Stars
271 Commits
70 Forks
7 Watching
1 Branches
29 Contributors
Updated on 22 Nov 2024
JavaScript (70.13%)
HTML (14.67%)
TypeScript (9.36%)
Vue (4.31%)
CSS (1.45%)
Less (0.08%)
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
0%
6
Compared to previous week
Last month
-82.8%
20
Compared to previous month
Last year
0%
2,677
Compared to previous year
1
23
This is a simple i18next backend to be used in Node.js, in the browser and for Deno. It will load resources from a backend server using the XMLHttpRequest or the fetch API.
Get a first idea on how it is used in this i18next crash course video.
It's based on the deprecated i18next-xhr-backend and can mostly be used as a drop-in replacement.
Why i18next-xhr-backend was deprecated?
If you don't like to manage your translation files manually or are simply looking for a better management solution, take a look at i18next-locize-backend. The i18next backed plugin for 🌐 locize ☁️.
To see i18next-locize-backend in a working app example, check out:
Make sure you set the debug
option of i18next to true
. This will maybe log more information in the developer console.
Seeing failed http requests, like 404?
Are you using a language detector plugin that detects region specific languages you are not providing? i.e. you provide 'en'
translations but you see a 'en-US'
request first?
This is because of the default load
option set to 'all'
.
Try to set the load
option to 'languageOnly'
1i18next.init({ 2 load: 'languageOnly', 3 // other options 4})
Source can be loaded via npm or downloaded from this repo.
There's also the possibility to directly import it via a CDN like jsdelivr or unpkg or similar.
1# npm package 2$ npm install i18next-http-backend
Wiring up:
1import i18next from 'i18next'; 2import HttpApi from 'i18next-http-backend'; 3 4i18next.use(HttpApi).init(i18nextOptions);
for Deno:
1import i18next from 'https://deno.land/x/i18next/index.js' 2import Backend from 'https://deno.land/x/i18next_http_backend/index.js' 3 4i18next.use(Backend).init(i18nextOptions);
for plain browser:
1<script src="https://cdn.jsdelivr.net/npm/i18next-http-backend@1.3.1/i18nextHttpBackend.min.js"></script> 2<!-- an example can be found in example/jquery/index.html -->
1i18next.use(i18nextHttpBackend).init(i18nextOptions);
window.i18nextHttpBackend
1{ 2 // path where resources get loaded from, or a function 3 // returning a path: 4 // function(lngs, namespaces) { return customPath; } 5 // the returned path will interpolate lng, ns if provided like giving a static path 6 // the function might return a promise 7 // returning falsy will abort the download 8 // 9 // If not used with i18next-multiload-backend-adapter, lngs and namespaces will have only one element each, 10 // If used with i18next-multiload-backend-adapter, lngs and namespaces can have multiple elements 11 // and also your server needs to support multiloading 12 // /locales/resources.json?lng=de+en&ns=ns1+ns2 13 // Adapter is needed to enable MultiLoading https://github.com/i18next/i18next-multiload-backend-adapter 14 // Returned JSON structure in this case is 15 // { 16 // lang : { 17 // namespaceA: {}, 18 // namespaceB: {}, 19 // ...etc 20 // } 21 // } 22 loadPath: '/locales/{{lng}}/{{ns}}.json', 23 24 // path to post missing resources, or a function 25 // function(lng, namespace) { return customPath; } 26 // the returned path will interpolate lng, ns if provided like giving a static path 27 // 28 // note that this only works when initialized with { saveMissing: true } 29 // (see https://www.i18next.com/overview/configuration-options) 30 addPath: '/locales/add/{{lng}}/{{ns}}', 31 32 // parse data after it has been fetched 33 // in example use https://www.npmjs.com/package/json5 or https://www.npmjs.com/package/jsonc-parser 34 // here it removes the letter a from the json (bad idea) 35 parse: function(data) { return data.replace(/a/g, ''); }, 36 37 // parse data before it has been sent by addPath 38 parsePayload: function(namespace, key, fallbackValue) { return { key: fallbackValue || "" } }, 39 40 // parse data before it has been sent by loadPath 41 // if value returned it will send a POST request 42 parseLoadPayload: function(languages, namespaces) { return undefined }, 43 44 // allow cross domain requests 45 crossDomain: false, 46 47 // allow credentials on cross domain requests 48 withCredentials: false, 49 50 // overrideMimeType sets request.overrideMimeType("application/json") 51 overrideMimeType: false, 52 53 // custom request headers sets request.setRequestHeader(key, value) 54 customHeaders: { 55 authorization: 'foo', 56 // ... 57 }, 58 // can also be a function, that returns the headers 59 customHeaders: () => ({ 60 authorization: 'foo', 61 // ... 62 }), 63 64 requestOptions: { // used for fetch, can also be a function (payload) => ({ method: 'GET' }) 65 mode: 'cors', 66 credentials: 'same-origin', 67 cache: 'default' 68 }, 69 70 // define a custom request function 71 // can be used to support XDomainRequest in IE 8 and 9 72 // 73 // 'options' will be this entire options object 74 // 'url' will be passed the value of 'loadPath' 75 // 'payload' will be a key:value object used when saving missing translations 76 // 'callback' is a function that takes two parameters, 'err' and 'res'. 77 // 'err' should be an error 78 // 'res' should be an object with a 'status' property and a 'data' property containing a stringified object instance beeing the key:value translation pairs for the 79 // requested language and namespace, or null in case of an error. 80 request: function (options, url, payload, callback) {}, 81 82 // adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5' 83 queryStringParams: { v: '1.3.5' }, 84 85 reloadInterval: false // can be used to reload resources in a specific interval (milliseconds) (useful in server environments) 86}
Options can be passed in:
preferred - by setting options.backend in i18next.init:
1import i18next from 'i18next'; 2import HttpApi from 'i18next-http-backend'; 3 4i18next.use(HttpApi).init({ 5 backend: options, 6});
on construction:
1import HttpApi from 'i18next-http-backend'; 2const HttpApi = new HttpApi(null, options);
via calling init:
1import HttpApi from 'i18next-http-backend'; 2const HttpApi = new HttpApi(); 3HttpApi.init(null, options);
To properly type the backend options, you can import the HttpBackendOptions
interface and use it as a generic type parameter to the i18next's init
method, e.g.:
1import i18n from 'i18next' 2import HttpBackend, { HttpBackendOptions } from 'i18next-http-backend' 3 4i18n 5 .use(HttpBackend) 6 .init<HttpBackendOptions>({ 7 backend: { 8 // http backend options 9 }, 10 11 // other i18next options 12 })
From the creators of i18next: localization as a service - locize.com
A translation management system built around the i18next ecosystem - locize.com.
With using locize you directly support the future of i18next.
No vulnerabilities found.
Reason
18 commit(s) and 9 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/27 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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 2024-11-18
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