Skip to content

Commit

Permalink
typescript fix for i18next v22
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Oct 26, 2022
1 parent 2e87494 commit 8a1a496
Show file tree
Hide file tree
Showing 8 changed files with 6,828 additions and 2,702 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### 4.0.0

- typescript fix for i18next v22

### 3.1.0

- pass down options to create function
Expand Down
15 changes: 0 additions & 15 deletions i18nextChainedBackend.js
Expand Up @@ -19,7 +19,6 @@
Object.defineProperty(target, descriptor.key, descriptor);
}
}

function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Expand Down Expand Up @@ -53,47 +52,37 @@
handleEmptyResourcesAsFailed: true
};
}

var Backend = /*#__PURE__*/function () {
function Backend(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

_classCallCheck(this, Backend);

this.backends = [];
this.type = 'backend';
this.init(services, options);
}

_createClass(Backend, [{
key: "init",
value: function init(services) {
var _this = this;

var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var i18nextOptions = arguments.length > 2 ? arguments[2] : undefined;
this.services = services;
this.options = defaults(options, this.options || {}, getDefaults());
this.options.backends && this.options.backends.forEach(function (b, i) {
_this.backends[i] = _this.backends[i] || createClassOnDemand(b);

_this.backends[i].init(services, _this.options.backendOptions && _this.options.backendOptions[i] || {}, i18nextOptions);
});
}
}, {
key: "read",
value: function read(language, namespace, callback) {
var _this2 = this;

var bLen = this.backends.length;

var loadPosition = function loadPosition(pos) {
if (pos >= bLen) return callback(new Error('non of the backend loaded data;', true)); // failed pass retry flag

var isLastBackend = pos === bLen - 1;
var lengthCheckAmount = _this2.options.handleEmptyResourcesAsFailed && !isLastBackend ? 0 : -1;
var backend = _this2.backends[pos];

if (backend.read) {
backend.read(language, namespace, function (err, data) {
if (!err && data && Object.keys(data).length > lengthCheckAmount) {
Expand All @@ -111,15 +100,13 @@
var savePosition = function savePosition(pos, data) {
if (pos < 0) return;
var backend = _this2.backends[pos];

if (backend.save) {
backend.save(language, namespace, data);
savePosition(pos - 1, data);
} else {
savePosition(pos - 1, data);
}
};

loadPosition(0);
}
}, {
Expand All @@ -130,10 +117,8 @@
});
}
}]);

return Backend;
}();

Backend.type = 'backend';

return Backend;
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -38,7 +38,7 @@ export default class I18NextChainedBackend {
}

declare module "i18next" {
interface PluginOptions {
interface CustomPluginOptions {
backend?: I18NextChainedBackend.BackendOptions;
}
}

0 comments on commit 8a1a496

Please sign in to comment.