Skip to content

Commit

Permalink
update example deps
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jun 15, 2023
1 parent 76ba008 commit f27dee9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"typescript": "^5.1.3"
},
"dependencies": {
"i18next": "^22.5.1"
"i18next": "^23.0.0"
}
}
10 changes: 8 additions & 2 deletions i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@
}
return current;
}
function getCleanedCode(code) {
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
return code;
}

class ResourceStore extends EventEmitter {
constructor(data) {
Expand Down Expand Up @@ -793,6 +797,7 @@
this.logger = baseLogger.create('languageUtils');
}
getScriptPartFromCode(code) {
code = getCleanedCode(code);
if (!code || code.indexOf('-') < 0) return null;
const p = code.split('-');
if (p.length === 2) return null;
Expand All @@ -801,6 +806,7 @@
return this.formatLanguageCode(p.join('-'));
}
getLanguagePartFromCode(code) {
code = getCleanedCode(code);
if (!code || code.indexOf('-') < 0) return code;
const p = code.split('-');
return this.formatLanguageCode(p[0]);
Expand Down Expand Up @@ -879,7 +885,7 @@
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
}
};
if (typeof code === 'string' && code.indexOf('-') > -1) {
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
Expand Down Expand Up @@ -1095,7 +1101,7 @@
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.shouldUseIntlApi()) {
try {
return new Intl.PluralRules(code, {
return new Intl.PluralRules(getCleanedCode(code), {
type: options.ordinal ? 'ordinal' : 'cardinal'
});
} catch {
Expand Down
2 changes: 1 addition & 1 deletion i18next.min.js

Large diffs are not rendered by default.

0 comments on commit f27dee9

Please sign in to comment.