Skip to content

Commit

Permalink
add optional pretest in hasLoadedNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed Jun 17, 2020
1 parent b455100 commit d85dcb6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class I18n extends EventEmitter {
this.options.defaultNS = ns;
}

hasLoadedNamespace(ns) {
hasLoadedNamespace(ns, options = {}) {
if (!this.isInitialized) {
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
return false;
Expand All @@ -335,6 +335,12 @@ class I18n extends EventEmitter {
return loadState === -1 || loadState === 2;
};

// optional injected check
if (options.precheck) {
const preResult = options.precheck(this, loadNotPending);
if (preResult !== undefined) return preResult;
}

// loaded -> SUCCESS
if (this.hasResourceBundle(lng, ns)) return true;

Expand Down

0 comments on commit d85dcb6

Please sign in to comment.