{"id":13527014,"url":"https://github.com/i18next/i18next-xhr-backend","last_synced_at":"2025-05-15T18:11:22.939Z","repository":{"id":1876681,"uuid":"45098050","full_name":"i18next/i18next-xhr-backend","owner":"i18next","description":"[deprecated] can be replaced with i18next-http-backend","archived":false,"fork":false,"pushed_at":"2022-02-12T07:34:24.000Z","size":475,"stargazers_count":253,"open_issues_count":12,"forks_count":75,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T22:22:37.514Z","etag":null,"topics":["backend","i18next","plugin","xhr"],"latest_commit_sha":null,"homepage":"https://github.com/i18next/i18next-http-backend","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i18next.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-28T08:15:17.000Z","updated_at":"2024-09-18T10:59:53.000Z","dependencies_parsed_at":"2022-08-06T11:15:24.510Z","dependency_job_id":null,"html_url":"https://github.com/i18next/i18next-xhr-backend","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-xhr-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-xhr-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-xhr-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-xhr-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i18next","download_url":"https://codeload.github.com/i18next/i18next-xhr-backend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744335,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","i18next","plugin","xhr"],"created_at":"2024-08-01T06:01:39.307Z","updated_at":"2025-04-07T23:11:34.375Z","avatar_url":"https://github.com/i18next.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# DEPRECATED\n\nCan be replaced with: [i18next-http-backend](https://github.com/i18next/i18next-http-backend)\n\n**[Why?](https://github.com/i18next/i18next-xhr-backend/issues/348#issuecomment-663060275)**\n\n---\n\n# Introduction\n\n[![Travis](https://img.shields.io/travis/i18next/i18next-xhr-backend/master.svg?style=flat-square)](https://travis-ci.org/i18next/i18next-xhr-backend)\n[![Coveralls](https://img.shields.io/coveralls/i18next/i18next-xhr-backend/master.svg?style=flat-square)](https://coveralls.io/github/i18next/i18next-xhr-backend)\n[![npm version](https://img.shields.io/npm/v/i18next-xhr-backend.svg?style=flat-square)](https://www.npmjs.com/package/i18next-xhr-backend)\n[![Bower](https://img.shields.io/bower/v/i18next-xhr-backend.svg)]()\n[![David](https://img.shields.io/david/i18next/i18next-xhr-backend.svg?style=flat-square)](https://david-dm.org/i18next/i18next-xhr-backend)\n\nThis is a simple i18next backend to be used in the browser. It will load resources from a backend server using the xhr API.\n\n# Getting started\n\nSource can be loaded via [npm](https://www.npmjs.com/package/i18next-xhr-backend), bower or [downloaded](https://github.com/i18next/i18next-xhr-backend/blob/master/i18nextXHRBackend.min.js) from this repo.\n\n```\n# npm package\n$ npm install i18next-xhr-backend\n\n# bower\n$ bower install i18next-xhr-backend\n```\n\nWiring up:\n\n```js\nimport i18next from 'i18next';\nimport XHR from 'i18next-xhr-backend';\n\ni18next.use(XHR).init(i18nextOptions);\n```\n\n- As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.\n- If you don't use a module loader it will be added to `window.i18nextXHRBackend`\n\n## Backend Options\n\n```js\n{\n  // path where resources get loaded from, or a function\n  // returning a path:\n  // function(lngs, namespaces) { return customPath; }\n  // the returned path will interpolate lng, ns if provided like giving a static path\n  loadPath: '/locales/{{lng}}/{{ns}}.json',\n\n  // path to post missing resources\n  addPath: 'locales/add/{{lng}}/{{ns}}',\n\n  // your backend server supports multiloading\n  // /locales/resources.json?lng=de+en\u0026ns=ns1+ns2\n  // Adapter is needed to enable MultiLoading https://github.com/i18next/i18next-multiload-backend-adapter\n  // Returned JSON structure in this case is\n  // {\n  //  lang : {\n  //   namespaceA: {},\n  //   namespaceB: {},\n  //   ...etc\n  //  }\n  // }\n  allowMultiLoading: false, // set loadPath: '/locales/resources.json?lng={{lng}}\u0026ns={{ns}}' to adapt to multiLoading\n\n  // parse data after it has been fetched\n  // in example use https://www.npmjs.com/package/json5\n  // here it removes the letter a from the json (bad idea)\n  parse: function(data) { return data.replace(/a/g, ''); },\n\n  //parse data before it has been sent by addPath\n  parsePayload: function(namespace, key, fallbackValue) { return { key } },\n\n  // allow cross domain requests\n  crossDomain: false,\n\n  // allow credentials on cross domain requests\n  withCredentials: false,\n\n  // overrideMimeType sets request.overrideMimeType(\"application/json\")\n  overrideMimeType: false,\n\n  // custom request headers sets request.setRequestHeader(key, value)\n  customHeaders: {\n    authorization: 'foo',\n    // ...\n  },\n\n  // define a custom xhr function\n  // can be used to support XDomainRequest in IE 8 and 9\n  //\n  // 'url' will be passed the value of 'loadPath'\n  // 'options' will be this entire options object\n  // 'callback' is a function that takes two parameters, 'data' and 'xhr'.\n  //            'data' should be the key:value translation pairs for the\n  //            requested language and namespace, or null in case of an error.\n  //            'xhr' should be a status object, e.g. { status: 200 }\n  // 'data' will be a key:value object used when saving missing translations\n  ajax: function (url, options, callback, data) {},\n\n  // adds parameters to resource URL. 'example.com' -\u003e 'example.com?v=1.3.5'\n  queryStringParams: { v: '1.3.5' }\n}\n```\n\nOptions can be passed in:\n\n**preferred** - by setting options.backend in i18next.init:\n\n```js\nimport i18next from 'i18next';\nimport XHR from 'i18next-xhr-backend';\n\ni18next.use(XHR).init({\n  backend: options,\n});\n```\n\non construction:\n\n```js\nimport XHR from 'i18next-xhr-backend';\nconst xhr = new XHR(null, options);\n```\n\nvia calling init:\n\n```js\nimport XHR from 'i18next-xhr-backend';\nconst xhr = new XHR();\nxhr.init(null, options);\n```\n\n## Misc\n\n#### TypeScript definitions\n\n- Install from `@types` (for TypeScript v2 and later):\n\n        npm install --save-dev @types/i18next-xhr-backend\n\n- Install from `typings`:\n\n        typings install --save --global dt~i18next-xhr-backend\n\n---\n\n\u003ch3 align=\"center\"\u003eGold Sponsors\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://locize.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif\" width=\"240px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-xhr-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi18next%2Fi18next-xhr-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-xhr-backend/lists"}