1
0
Fork 0

Changed stuff, added filter for statistics module

This commit is contained in:
Techognito 2025-09-02 16:37:06 +02:00
parent 4a91ae2bf9
commit fe87374e47
251 changed files with 3295 additions and 1705 deletions

View file

@ -433,6 +433,27 @@ var postProcessor = {
}
};
const PATH_KEY = Symbol('i18next/PATH_KEY');
function createProxy() {
const state = [];
const handler = Object.create(null);
let proxy;
handler.get = (target, key) => {
proxy?.revoke?.();
if (key === PATH_KEY) return state;
state.push(key);
proxy = Proxy.revocable(target, handler);
return proxy.proxy;
};
return Proxy.revocable(Object.create(null), handler).proxy;
}
function keysFromSelector(selector, opts) {
const {
[PATH_KEY]: path
} = selector(createProxy());
return path.join(opts?.keySeparator ?? '.');
}
const checkedLoadedFor = {};
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
class Translator extends EventEmitter {
@ -489,11 +510,15 @@ class Translator extends EventEmitter {
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
opt = this.options.overloadTranslationOptionHandler(arguments);
}
if (typeof options === 'object') opt = {
if (typeof opt === 'object') opt = {
...opt
};
if (!opt) opt = {};
if (keys == null) return '';
if (typeof keys === 'function') keys = keysFromSelector(keys, {
...this.options,
...opt
});
if (!Array.isArray(keys)) keys = [String(keys)];
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@ -771,22 +796,22 @@ class Translator extends EventEmitter {
const zeroSuffix = `${this.options.pluralSeparator}zero`;
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
if (needsPluralHandling) {
finalKeys.push(key + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(key + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(key + zeroSuffix);
}
}
if (needsContextHandling) {
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
finalKeys.push(contextKey);
if (needsPluralHandling) {
finalKeys.push(contextKey + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(contextKey + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(contextKey + zeroSuffix);
}
@ -1105,7 +1130,7 @@ class Interpolator {
};
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
}
interpolate(str, data, lng, options) {
let match;
@ -1750,7 +1775,7 @@ class I18n extends EventEmitter {
});
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
if (usingLegacyFormatFunction) {
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
}
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
s.formatter = createClassOnDemand(formatter);
@ -1984,8 +2009,18 @@ class I18n extends EventEmitter {
const keySeparator = this.options.keySeparator || '.';
let resultKey;
if (o.keyPrefix && Array.isArray(key)) {
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
resultKey = key.map(k => {
if (typeof k === 'function') k = keysFromSelector(k, {
...this.options,
...opts
});
return `${o.keyPrefix}${keySeparator}${k}`;
});
} else {
if (typeof key === 'function') key = keysFromSelector(key, {
...this.options,
...opts
});
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
}
return this.t(resultKey, o);

View file

@ -431,6 +431,27 @@ var postProcessor = {
}
};
const PATH_KEY = Symbol('i18next/PATH_KEY');
function createProxy() {
const state = [];
const handler = Object.create(null);
let proxy;
handler.get = (target, key) => {
proxy?.revoke?.();
if (key === PATH_KEY) return state;
state.push(key);
proxy = Proxy.revocable(target, handler);
return proxy.proxy;
};
return Proxy.revocable(Object.create(null), handler).proxy;
}
function keysFromSelector(selector, opts) {
const {
[PATH_KEY]: path
} = selector(createProxy());
return path.join(opts?.keySeparator ?? '.');
}
const checkedLoadedFor = {};
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
class Translator extends EventEmitter {
@ -487,11 +508,15 @@ class Translator extends EventEmitter {
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
opt = this.options.overloadTranslationOptionHandler(arguments);
}
if (typeof options === 'object') opt = {
if (typeof opt === 'object') opt = {
...opt
};
if (!opt) opt = {};
if (keys == null) return '';
if (typeof keys === 'function') keys = keysFromSelector(keys, {
...this.options,
...opt
});
if (!Array.isArray(keys)) keys = [String(keys)];
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@ -769,22 +794,22 @@ class Translator extends EventEmitter {
const zeroSuffix = `${this.options.pluralSeparator}zero`;
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
if (needsPluralHandling) {
finalKeys.push(key + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(key + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(key + zeroSuffix);
}
}
if (needsContextHandling) {
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
finalKeys.push(contextKey);
if (needsPluralHandling) {
finalKeys.push(contextKey + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(contextKey + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(contextKey + zeroSuffix);
}
@ -1103,7 +1128,7 @@ class Interpolator {
};
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
}
interpolate(str, data, lng, options) {
let match;
@ -1748,7 +1773,7 @@ class I18n extends EventEmitter {
});
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
if (usingLegacyFormatFunction) {
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
}
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
s.formatter = createClassOnDemand(formatter);
@ -1982,8 +2007,18 @@ class I18n extends EventEmitter {
const keySeparator = this.options.keySeparator || '.';
let resultKey;
if (o.keyPrefix && Array.isArray(key)) {
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
resultKey = key.map(k => {
if (typeof k === 'function') k = keysFromSelector(k, {
...this.options,
...opts
});
return `${o.keyPrefix}${keySeparator}${k}`;
});
} else {
if (typeof key === 'function') key = keysFromSelector(key, {
...this.options,
...opts
});
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
}
return this.t(resultKey, o);

View file

@ -431,6 +431,27 @@ var postProcessor = {
}
};
const PATH_KEY = Symbol('i18next/PATH_KEY');
function createProxy() {
const state = [];
const handler = Object.create(null);
let proxy;
handler.get = (target, key) => {
proxy?.revoke?.();
if (key === PATH_KEY) return state;
state.push(key);
proxy = Proxy.revocable(target, handler);
return proxy.proxy;
};
return Proxy.revocable(Object.create(null), handler).proxy;
}
function keysFromSelector(selector, opts) {
const {
[PATH_KEY]: path
} = selector(createProxy());
return path.join(opts?.keySeparator ?? '.');
}
const checkedLoadedFor = {};
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
class Translator extends EventEmitter {
@ -487,11 +508,15 @@ class Translator extends EventEmitter {
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
opt = this.options.overloadTranslationOptionHandler(arguments);
}
if (typeof options === 'object') opt = {
if (typeof opt === 'object') opt = {
...opt
};
if (!opt) opt = {};
if (keys == null) return '';
if (typeof keys === 'function') keys = keysFromSelector(keys, {
...this.options,
...opt
});
if (!Array.isArray(keys)) keys = [String(keys)];
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@ -769,22 +794,22 @@ class Translator extends EventEmitter {
const zeroSuffix = `${this.options.pluralSeparator}zero`;
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
if (needsPluralHandling) {
finalKeys.push(key + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(key + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(key + zeroSuffix);
}
}
if (needsContextHandling) {
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
finalKeys.push(contextKey);
if (needsPluralHandling) {
finalKeys.push(contextKey + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(contextKey + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(contextKey + zeroSuffix);
}
@ -1103,7 +1128,7 @@ class Interpolator {
};
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
}
interpolate(str, data, lng, options) {
let match;
@ -1748,7 +1773,7 @@ class I18n extends EventEmitter {
});
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
if (usingLegacyFormatFunction) {
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
}
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
s.formatter = createClassOnDemand(formatter);
@ -1982,8 +2007,18 @@ class I18n extends EventEmitter {
const keySeparator = this.options.keySeparator || '.';
let resultKey;
if (o.keyPrefix && Array.isArray(key)) {
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
resultKey = key.map(k => {
if (typeof k === 'function') k = keysFromSelector(k, {
...this.options,
...opts
});
return `${o.keyPrefix}${keySeparator}${k}`;
});
} else {
if (typeof key === 'function') key = keysFromSelector(key, {
...this.options,
...opts
});
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
}
return this.t(resultKey, o);

View file

@ -1 +1 @@
{"type":"module","version":"25.3.2"}
{"type":"module","version":"25.4.2"}

View file

@ -437,6 +437,27 @@
}
};
const PATH_KEY = Symbol('i18next/PATH_KEY');
function createProxy() {
const state = [];
const handler = Object.create(null);
let proxy;
handler.get = (target, key) => {
proxy?.revoke?.();
if (key === PATH_KEY) return state;
state.push(key);
proxy = Proxy.revocable(target, handler);
return proxy.proxy;
};
return Proxy.revocable(Object.create(null), handler).proxy;
}
function keysFromSelector(selector, opts) {
const {
[PATH_KEY]: path
} = selector(createProxy());
return path.join(opts?.keySeparator ?? '.');
}
const checkedLoadedFor = {};
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
class Translator extends EventEmitter {
@ -493,11 +514,15 @@
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
opt = this.options.overloadTranslationOptionHandler(arguments);
}
if (typeof options === 'object') opt = {
if (typeof opt === 'object') opt = {
...opt
};
if (!opt) opt = {};
if (keys == null) return '';
if (typeof keys === 'function') keys = keysFromSelector(keys, {
...this.options,
...opt
});
if (!Array.isArray(keys)) keys = [String(keys)];
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@ -775,22 +800,22 @@
const zeroSuffix = `${this.options.pluralSeparator}zero`;
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
if (needsPluralHandling) {
finalKeys.push(key + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(key + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(key + zeroSuffix);
}
}
if (needsContextHandling) {
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
finalKeys.push(contextKey);
if (needsPluralHandling) {
finalKeys.push(contextKey + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(contextKey + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(contextKey + zeroSuffix);
}
@ -1109,7 +1134,7 @@
};
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
}
interpolate(str, data, lng, options) {
let match;
@ -1754,7 +1779,7 @@
});
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
if (usingLegacyFormatFunction) {
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
}
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
s.formatter = createClassOnDemand(formatter);
@ -1988,8 +2013,18 @@
const keySeparator = this.options.keySeparator || '.';
let resultKey;
if (o.keyPrefix && Array.isArray(key)) {
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
resultKey = key.map(k => {
if (typeof k === 'function') k = keysFromSelector(k, {
...this.options,
...opts
});
return `${o.keyPrefix}${keySeparator}${k}`;
});
} else {
if (typeof key === 'function') key = keysFromSelector(key, {
...this.options,
...opts
});
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
}
return this.t(resultKey, o);

File diff suppressed because one or more lines are too long

49
node_modules/i18next/i18next.js generated vendored
View file

@ -437,6 +437,27 @@
}
};
const PATH_KEY = Symbol('i18next/PATH_KEY');
function createProxy() {
const state = [];
const handler = Object.create(null);
let proxy;
handler.get = (target, key) => {
proxy?.revoke?.();
if (key === PATH_KEY) return state;
state.push(key);
proxy = Proxy.revocable(target, handler);
return proxy.proxy;
};
return Proxy.revocable(Object.create(null), handler).proxy;
}
function keysFromSelector(selector, opts) {
const {
[PATH_KEY]: path
} = selector(createProxy());
return path.join(opts?.keySeparator ?? '.');
}
const checkedLoadedFor = {};
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
class Translator extends EventEmitter {
@ -493,11 +514,15 @@
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
opt = this.options.overloadTranslationOptionHandler(arguments);
}
if (typeof options === 'object') opt = {
if (typeof opt === 'object') opt = {
...opt
};
if (!opt) opt = {};
if (keys == null) return '';
if (typeof keys === 'function') keys = keysFromSelector(keys, {
...this.options,
...opt
});
if (!Array.isArray(keys)) keys = [String(keys)];
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@ -775,22 +800,22 @@
const zeroSuffix = `${this.options.pluralSeparator}zero`;
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
if (needsPluralHandling) {
finalKeys.push(key + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(key + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(key + zeroSuffix);
}
}
if (needsContextHandling) {
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
finalKeys.push(contextKey);
if (needsPluralHandling) {
finalKeys.push(contextKey + pluralSuffix);
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
}
finalKeys.push(contextKey + pluralSuffix);
if (needsZeroSuffixLookup) {
finalKeys.push(contextKey + zeroSuffix);
}
@ -1109,7 +1134,7 @@
};
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
}
interpolate(str, data, lng, options) {
let match;
@ -1754,7 +1779,7 @@
});
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
if (usingLegacyFormatFunction) {
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
}
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
s.formatter = createClassOnDemand(formatter);
@ -1988,8 +2013,18 @@
const keySeparator = this.options.keySeparator || '.';
let resultKey;
if (o.keyPrefix && Array.isArray(key)) {
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
resultKey = key.map(k => {
if (typeof k === 'function') k = keysFromSelector(k, {
...this.options,
...opts
});
return `${o.keyPrefix}${keySeparator}${k}`;
});
} else {
if (typeof key === 'function') key = keysFromSelector(key, {
...this.options,
...opts
});
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
}
return this.t(resultKey, o);

File diff suppressed because one or more lines are too long

3
node_modules/i18next/package.json generated vendored
View file

@ -1,6 +1,6 @@
{
"name": "i18next",
"version": "25.3.2",
"version": "25.4.2",
"description": "i18next internationalization framework",
"main": "./dist/cjs/i18next.js",
"module": "./dist/esm/i18next.js",
@ -60,6 +60,7 @@
}
},
"devDependencies": {
"@arktype/attest": "^0.46.0",
"@babel/core": "^7.27.4",
"@babel/plugin-transform-async-generator-functions": "^7.27.1",
"@babel/plugin-transform-modules-commonjs": "^7.27.1",

View file

@ -6,6 +6,15 @@ export type $SpecialObject = object | Array<string | object>;
// Types Operators
export type $Prune<T> =
| never
| { [K in keyof T as [keyof T[K]] extends [never] ? never : K]: T[K] };
/** All the way down. */
export interface $Turtles {
[x: string]: $Turtles;
}
export type $MergeBy<T, K> = Omit<T, keyof K> & K;
export type $OmitArrayKeys<Arr> = Arr extends readonly any[] ? Omit<Arr, keyof any[]> : Arr;

View file

@ -95,6 +95,24 @@ export type TypeOptions = $MergeBy<
/** @see {InterpolationOptions.unescapeSuffix} */
unescapeSuffix: '';
/**
* Use a proxy-based selector to select a translation.
*
* Enables features like go-to definition, and better DX/faster autocompletion
* for TypeScript developers.
*
* If you're working with an especially large set of translations and aren't
* using context, you set `enableSelector` to `"optimize"` and i18next won't do
* any type-level processing of your translations at all.
*
* With `enableSelector` set to `"optimize"`, i18next is capable of supporting
* arbitrarily large/deep translation sets without causing any IDE slowdown
* whatsoever.
*
* @default false
*/
enableSelector: false;
},
CustomTypeOptions
>;

View file

@ -5,6 +5,8 @@ import type {
$SpecialObject,
$StringKeyPathToRecord,
$NoInfer,
$Prune,
$Turtles,
} from './helpers.js';
import type {
TypeOptions,
@ -12,6 +14,7 @@ import type {
FlatNamespace,
DefaultNamespace,
TOptions,
TOptionsBase,
} from './options.js';
/** @todo consider to replace {} with Record<string, never> */
@ -33,6 +36,7 @@ type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
type _UnescapePrefix = TypeOptions['unescapePrefix'];
type _UnescapeSuffix = TypeOptions['unescapeSuffix'];
type _StrictKeyChecks = TypeOptions['strictKeyChecks'];
type _EnableSelector = TypeOptions['enableSelector'];
type $IsResourcesDefined = [keyof _Resources] extends [never] ? false : true;
type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends true
@ -63,6 +67,12 @@ type TrimSpaces<T extends string, Acc extends string = ''> = T extends `${infer
? Acc
: never;
interface Branded<Ns extends Namespace> {
$TFunctionBrand: $IsResourcesDefined extends true
? `${Ns extends readonly any[] ? Ns[0] : Ns}`
: never;
}
/** ****************************************************
* Build all keys and key prefixes based on Resources *
***************************************************** */
@ -212,12 +222,14 @@ type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallba
>;
type TReturnOptionalNull = _ReturnNull extends true ? null : never;
type TReturnOptionalObjects<TOpt extends TOptions> = _ReturnObjects extends true
type TReturnOptionalObjects<TOpt extends { returnObjects?: unknown }> = _ReturnObjects extends true
? $SpecialObject | string
: TOpt['returnObjects'] extends true
? $SpecialObject
: string;
type DefaultTReturn<TOpt extends TOptions> = TReturnOptionalObjects<TOpt> | TReturnOptionalNull;
type DefaultTReturn<TOpt extends { returnObjects?: unknown }> =
| TReturnOptionalObjects<TOpt>
| TReturnOptionalNull;
export type KeyWithContext<Key, TOpt extends TOptions> = TOpt['context'] extends string
? `${Key & string}${_ContextSeparator}${TOpt['context']}`
@ -280,8 +292,8 @@ type AppendKeyPrefix<Key, KPrefix> = KPrefix extends string
* T function declaration *
************************* */
interface TFunctionStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined> {
$TFunctionBrand: $IsResourcesDefined extends true ? `${$FirstNamespace<Ns>}` : never;
interface TFunctionStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>
extends Branded<Ns> {
<
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
const TOpt extends TOptions,
@ -301,8 +313,8 @@ interface TFunctionStrict<Ns extends Namespace = DefaultNamespace, KPrefix = und
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, never>, TOpt>;
}
interface TFunctionNonStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined> {
$TFunctionBrand: $IsResourcesDefined extends true ? `${$FirstNamespace<Ns>}` : never;
interface TFunctionNonStrict<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>
extends Branded<Ns> {
<
const Key extends ParseKeys<Ns, TOpt, KPrefix> | TemplateStringsArray,
const TOpt extends TOptions,
@ -320,9 +332,134 @@ interface TFunctionNonStrict<Ns extends Namespace = DefaultNamespace, KPrefix =
type TFunctionSignature<
Ns extends Namespace = DefaultNamespace,
KPrefix = undefined,
> = _StrictKeyChecks extends true ? TFunctionStrict<Ns, KPrefix> : TFunctionNonStrict<Ns, KPrefix>;
> = _EnableSelector extends true | 'optimize'
? TFunctionSelector<Ns, KPrefix, GetSource<Ns, KPrefix>>
: _StrictKeyChecks extends true
? TFunctionStrict<Ns, KPrefix>
: TFunctionNonStrict<Ns, KPrefix>;
export interface TFunction<Ns extends Namespace = DefaultNamespace, KPrefix = undefined>
extends TFunctionSignature<Ns, KPrefix> {}
export type KeyPrefix<Ns extends Namespace> = ResourceKeys<true>[$FirstNamespace<Ns>] | undefined;
/// ////////////// ///
/// ↆ selector ↆ ///
/// ////////////// ///
interface TFunctionSelector<Ns extends Namespace, KPrefix, Source> extends Branded<Ns> {
<
Target extends ConstrainTarget<Opts>,
const Opts extends SelectorOptions<NewNs>,
NewNs extends Namespace,
NewSrc extends GetSource<NewNs, KPrefix>,
>(
selector: SelectorFn<NewSrc, ApplyTarget<Target, Opts>, Opts>,
options: Opts & InterpolationMap<Target> & { ns: NewNs },
): SelectorReturn<Target, Opts>;
<Target extends ConstrainTarget<Opts>, const Opts extends SelectorOptions<Ns>>(
selector: SelectorFn<Source, ApplyTarget<Target, Opts>, Opts>,
options?: Opts & InterpolationMap<Target>,
): SelectorReturn<Target, Opts>;
}
interface SelectorOptions<Ns = Namespace>
extends Omit<TOptionsBase, 'ns' | 'nsSeparator'>,
$Dictionary {
ns?: Ns;
}
type SelectorReturn<
Target,
Opts extends { defaultValue?: unknown; returnObjects?: boolean },
> = $IsResourcesDefined extends true
? TFunctionReturnOptionalDetails<ProcessReturnValue<Target, Opts['defaultValue']>, Opts>
: DefaultTReturn<Opts>;
interface SelectorFn<Source, Target, Opts extends SelectorOptions<unknown>> {
(translations: Select<Source, Opts['context']>): Target;
}
type ApplyKeyPrefix<
T extends [any],
KPrefix,
> = KPrefix extends `${infer Head}${_KeySeparator}${infer Tail}`
? ApplyKeyPrefix<[T[0][Head]], Tail>
: T[0][KPrefix & string];
type ApplyTarget<
Target,
Opts extends { returnObjects?: unknown },
> = Opts['returnObjects'] extends true ? unknown : Target;
type ConstrainTarget<Opts extends SelectorOptions<any>> = _ReturnObjects extends true
? unknown
: Opts['returnObjects'] extends true
? unknown
: $IsResourcesDefined extends false
? unknown
: string;
type ProcessReturnValue<Target, DefaultValue> = $Turtles extends Target
? string
: [DefaultValue] extends [never]
? Target
: unknown extends DefaultValue
? Target
: Target | DefaultValue;
type PickNamespaces<T, K extends keyof any> = {
[P in K as P extends keyof T ? P : never]: T[P & keyof T];
};
type GetSource<
Ns extends Namespace,
KPrefix,
Res = Ns extends readonly [keyof Resources, any, ...any]
? Resources[Ns[0]] & PickNamespaces<Resources, Ns[number]>
: Resources[$FirstNamespace<Ns>],
> = KPrefix extends keyof Res
? Res[KPrefix]
: undefined extends KPrefix
? Res
: ApplyKeyPrefix<[Res], KPrefix>;
type Select<T, Context> = $IsResourcesDefined extends false
? $Turtles
: [_EnableSelector] extends ['optimize']
? T
: FilterKeys<T, Context>;
type FilterKeys<T, Context> = never | T extends readonly any[]
? { [I in keyof T]: FilterKeys<T[I], Context> }
: $Prune<
{
[K in keyof T as T[K] extends object
? K
: Context extends string
? never
: K extends `${string}${_PluralSeparator}${PluralSuffix}`
? never
: K]: T[K] extends object ? FilterKeys<T[K], Context> : T[K];
} & {
[K in keyof T as T[K] extends object
? never
: Context extends string
? never
: K extends
| `${infer Prefix}${_PluralSeparator}${PluralSuffix}`
| `${infer Prefix}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`
? Prefix
: never]: T[K] extends object ? FilterKeys<T[K], Context> : T[K];
} & {
[K in keyof T as T[K] extends object
? never
: Context extends string
? K extends
| `${infer Prefix}${_ContextSeparator}${Context}`
| `${infer Prefix}${_ContextSeparator}${Context}${_PluralSeparator}${PluralSuffix}`
? Prefix
: never
: never]: T[K] extends object ? FilterKeys<T[K], Context> : T[K];
}
>;