@intlayer/i18next 9.0.0-canary.13 → 9.0.0-canary.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getIntlayer } from "@intlayer/core/interpreter";
|
|
2
2
|
import { navigatePath, resolveMessage } from "@intlayer/core/messageFormat";
|
|
3
|
+
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
3
4
|
|
|
4
5
|
//#region src/resolveTranslation.ts
|
|
5
6
|
/**
|
|
@@ -36,6 +37,26 @@ const CONTROL_OPTION_KEYS = new Set([
|
|
|
36
37
|
/** Maximum `$t()` nesting recursion depth. */
|
|
37
38
|
const MAX_NESTING_DEPTH = 5;
|
|
38
39
|
/**
|
|
40
|
+
* Canonical key of the single dictionary produced when a JSON source pattern
|
|
41
|
+
* has no `{{key}}` segment (one file holds the whole namespace, e.g.
|
|
42
|
+
* `./src/i18n/{{locale}}.json`). Used as the fallback namespace so i18next's
|
|
43
|
+
* default `translation` namespace resolves against the whole-file dictionary.
|
|
44
|
+
*/
|
|
45
|
+
const ROOT_DICTIONARY_KEY = "index";
|
|
46
|
+
/**
|
|
47
|
+
* Reads a dictionary from the runtime registry, returning `undefined` when the
|
|
48
|
+
* namespace is not a registered dictionary.
|
|
49
|
+
*
|
|
50
|
+
* `getIntlayer` never throws for a missing key — in development it returns a
|
|
51
|
+
* path-stringifying fallback proxy — so a plain `getIntlayer` call cannot tell
|
|
52
|
+
* "missing namespace" apart from "resolved content". The registry membership
|
|
53
|
+
* check makes the distinction explicit before resolving.
|
|
54
|
+
*/
|
|
55
|
+
const getDictionaryOrUndefined = (namespace, locale) => {
|
|
56
|
+
if (!(namespace in getDictionaries())) return void 0;
|
|
57
|
+
return getIntlayer(namespace, locale);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
39
60
|
* Builds the ordered list of key candidates following i18next's resolution
|
|
40
61
|
* order: context + plural → context → plural → exact key.
|
|
41
62
|
*/
|
|
@@ -92,12 +113,13 @@ const resolveTranslation = ({ locale, namespace, key, options, keySeparator = ".
|
|
|
92
113
|
const count = typeof options?.count === "number" ? options.count : void 0;
|
|
93
114
|
const context = options?.context !== void 0 ? String(options.context) : void 0;
|
|
94
115
|
const ordinal = options?.ordinal === true;
|
|
116
|
+
const resolvedLocale = options?.lng ?? locale;
|
|
95
117
|
let dictionary;
|
|
96
118
|
if (dictionaryContent !== void 0 && targetNamespace === namespace && options?.lng === void 0) dictionary = dictionaryContent;
|
|
97
|
-
else
|
|
98
|
-
dictionary =
|
|
99
|
-
|
|
100
|
-
return;
|
|
119
|
+
else {
|
|
120
|
+
dictionary = getDictionaryOrUndefined(targetNamespace, resolvedLocale);
|
|
121
|
+
if (dictionary === void 0 && targetNamespace === namespace && targetNamespace !== ROOT_DICTIONARY_KEY) dictionary = getDictionaryOrUndefined(ROOT_DICTIONARY_KEY, resolvedLocale);
|
|
122
|
+
if (dictionary === void 0) return void 0;
|
|
101
123
|
}
|
|
102
124
|
let resolvedValue;
|
|
103
125
|
for (const candidate of buildKeyCandidates(path, options?.lng ?? locale, count, context, ordinal)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTranslation.mjs","names":[],"sources":["../../src/resolveTranslation.ts"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n navigatePath,\n resolveMessage,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\n\n/**\n * Shared i18next-dialect translation resolution.\n *\n * Implements the i18next lookup pipeline on top of intlayer dictionaries:\n * namespace prefix (`ns:key`), `ns` option override, plural suffixes\n * (`key_one`, `key_other`, …) via `Intl.PluralRules`, context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation.\n *\n * Used by `@intlayer/i18next` (instance `t`) and `@intlayer/react-i18next`\n * (`useTranslation`, `<Trans>`).\n */\n\n/** Option keys that are control flags, never interpolation values. */\nconst CONTROL_OPTION_KEYS = new Set([\n 'defaultValue',\n 'ns',\n 'lng',\n 'lngs',\n 'fallbackLng',\n 'returnObjects',\n 'returnDetails',\n 'keySeparator',\n 'nsSeparator',\n 'ordinal',\n 'postProcess',\n 'postProcessPassResolved',\n 'interpolation',\n 'replace',\n 'joinArrays',\n 'nsMode',\n 'keyPrefix',\n]);\n\n/** Maximum `$t()` nesting recursion depth. */\nconst MAX_NESTING_DEPTH = 5;\n\n/**\n * Builds the ordered list of key candidates following i18next's resolution\n * order: context + plural → context → plural → exact key.\n */\nconst buildKeyCandidates = (\n path: string,\n locale: string,\n count: number | undefined,\n context: string | undefined,\n ordinal: boolean\n): string[] => {\n const candidates: string[] = [];\n\n const pluralCategory =\n count === undefined\n ? undefined\n : new Intl.PluralRules(locale, {\n type: ordinal ? 'ordinal' : 'cardinal',\n }).select(count);\n\n if (context) {\n if (pluralCategory) {\n if (ordinal) {\n candidates.push(`${path}_${context}_ordinal_${pluralCategory}`);\n }\n candidates.push(`${path}_${context}_${pluralCategory}`);\n if (count !== 1) candidates.push(`${path}_${context}_plural`);\n }\n candidates.push(`${path}_${context}`);\n }\n\n if (pluralCategory) {\n if (ordinal) candidates.push(`${path}_ordinal_${pluralCategory}`);\n candidates.push(`${path}_${pluralCategory}`);\n // Legacy i18next v3 JSON suffix\n if (count !== 1) candidates.push(`${path}_plural`);\n }\n\n candidates.push(path);\n\n return candidates;\n};\n\n/** Extracts interpolation values from i18next `t()` options. */\nexport const getInterpolationValues = (options?: TOptions): MessageValues => {\n if (!options || typeof options !== 'object') return {};\n\n const replace = (options as { replace?: MessageValues }).replace;\n if (replace) {\n // `count` and `context` are always interpolatable, even with `replace`\n const values: MessageValues = { ...replace };\n if (options.count !== undefined) values.count ??= options.count;\n if (options.context !== undefined) values.context ??= options.context;\n return values;\n }\n\n const values: MessageValues = {};\n for (const [optionKey, optionValue] of Object.entries(options)) {\n if (!CONTROL_OPTION_KEYS.has(optionKey)) values[optionKey] = optionValue;\n }\n return values;\n};\n\nexport type ResolveTranslationParams = {\n /** Locale to resolve against. */\n locale: LocalesValues;\n /** Default namespace (dictionary key) when the key has no `ns:` prefix. */\n namespace: string;\n /** The translation key, possibly `ns:path.to.key`. */\n key: string;\n /** i18next `t()` options (interpolation values, count, context, …). */\n options?: TOptions;\n /** Custom key separator (`init({ keySeparator })`). */\n keySeparator?: string | false;\n /** Custom namespace separator (`init({ nsSeparator })`). */\n nsSeparator?: string | false;\n /** Internal `$t()` nesting recursion depth. */\n depth?: number;\n /**\n * Pre-resolved content of the `namespace` dictionary for `locale`.\n *\n * Supplied by the build-optimized `useDictionary` / `getDictionary`\n * variants, where the dictionary is imported at build time instead of read\n * from the runtime registry. Only used when the call resolves to the\n * default `namespace` without a locale override — cross-namespace\n * (`other:key`, `{ ns }`) and `{ lng }` lookups still go through\n * `getIntlayer`.\n */\n dictionaryContent?: unknown;\n};\n\n/**\n * Resolves a single translation key the i18next way against intlayer\n * dictionaries.\n *\n * Returns the resolved value: a string in the common case, or an\n * object/array when `returnObjects: true`. Returns `undefined` when the key\n * cannot be resolved (caller decides between `defaultValue`, fallback keys\n * and key echo).\n */\nexport const resolveTranslation = ({\n locale,\n namespace,\n key,\n options,\n keySeparator = '.',\n nsSeparator = ':',\n depth = 0,\n dictionaryContent,\n}: ResolveTranslationParams): unknown => {\n // Namespace resolution: `ns:` prefix > `ns` option > default namespace\n let targetNamespace = namespace;\n let path = key;\n\n if (nsSeparator !== false && key.includes(nsSeparator)) {\n const separatorIndex = key.indexOf(nsSeparator);\n targetNamespace = key.slice(0, separatorIndex);\n path = key.slice(separatorIndex + nsSeparator.length);\n } else if (options?.ns) {\n targetNamespace = Array.isArray(options.ns)\n ? (options.ns[0] as string)\n : (options.ns as string);\n }\n\n const count = typeof options?.count === 'number' ? options.count : undefined;\n const context =\n options?.context !== undefined ? String(options.context) : undefined;\n const ordinal = options?.ordinal === true;\n\n let dictionary: unknown;\n if (\n dictionaryContent !== undefined &&\n targetNamespace === namespace &&\n options?.lng === undefined\n ) {\n dictionary = dictionaryContent;\n } else {\n try {\n dictionary = getIntlayer(\n targetNamespace as DictionaryKeys,\n ((options?.lng as string) ?? locale) as LocalesValues\n );\n } catch {\n return undefined;\n }\n }\n\n let resolvedValue: unknown;\n for (const candidate of buildKeyCandidates(\n path,\n (options?.lng as string) ?? (locale as string),\n count,\n context,\n ordinal\n )) {\n const value = navigatePath(dictionary, candidate, keySeparator);\n if (value !== null && value !== undefined) {\n resolvedValue = value;\n break;\n }\n }\n\n if (resolvedValue === null || resolvedValue === undefined) return undefined;\n\n // `returnObjects: true` — return the raw subtree\n if (\n options?.returnObjects &&\n typeof resolvedValue === 'object' &&\n resolvedValue !== null\n ) {\n return resolvedValue;\n }\n\n const values = getInterpolationValues(options);\n\n let resolved = resolveMessage(\n resolvedValue,\n values,\n ((options?.lng as string) ?? locale) as LocalesValues,\n 'i18next'\n );\n\n // `$t(key)` nesting\n if (depth < MAX_NESTING_DEPTH && resolved.includes('$t(')) {\n resolved = resolved.replace(\n /\\$t\\(\\s*([^),]+?)\\s*(?:,[^)]*)?\\)/g,\n (match, nestedKey: string) => {\n const nestedValue = resolveTranslation({\n locale,\n namespace: targetNamespace,\n key: nestedKey.trim(),\n options,\n keySeparator,\n nsSeparator,\n depth: depth + 1,\n dictionaryContent:\n targetNamespace === namespace ? dictionaryContent : undefined,\n });\n return typeof nestedValue === 'string' ? nestedValue : match;\n }\n );\n }\n\n return resolved;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAM,sBAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAM,oBAAoB;;;;;AAM1B,MAAM,sBACJ,MACA,QACA,OACA,SACA,YACa;CACb,MAAM,aAAuB,CAAC;CAE9B,MAAM,iBACJ,UAAU,SAC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,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"resolveTranslation.mjs","names":[],"sources":["../../src/resolveTranslation.ts"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n navigatePath,\n resolveMessage,\n} from '@intlayer/core/messageFormat';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\n\n/**\n * Shared i18next-dialect translation resolution.\n *\n * Implements the i18next lookup pipeline on top of intlayer dictionaries:\n * namespace prefix (`ns:key`), `ns` option override, plural suffixes\n * (`key_one`, `key_other`, …) via `Intl.PluralRules`, context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation.\n *\n * Used by `@intlayer/i18next` (instance `t`) and `@intlayer/react-i18next`\n * (`useTranslation`, `<Trans>`).\n */\n\n/** Option keys that are control flags, never interpolation values. */\nconst CONTROL_OPTION_KEYS = new Set([\n 'defaultValue',\n 'ns',\n 'lng',\n 'lngs',\n 'fallbackLng',\n 'returnObjects',\n 'returnDetails',\n 'keySeparator',\n 'nsSeparator',\n 'ordinal',\n 'postProcess',\n 'postProcessPassResolved',\n 'interpolation',\n 'replace',\n 'joinArrays',\n 'nsMode',\n 'keyPrefix',\n]);\n\n/** Maximum `$t()` nesting recursion depth. */\nconst MAX_NESTING_DEPTH = 5;\n\n/**\n * Canonical key of the single dictionary produced when a JSON source pattern\n * has no `{{key}}` segment (one file holds the whole namespace, e.g.\n * `./src/i18n/{{locale}}.json`). Used as the fallback namespace so i18next's\n * default `translation` namespace resolves against the whole-file dictionary.\n */\nconst ROOT_DICTIONARY_KEY = 'index';\n\n/**\n * Reads a dictionary from the runtime registry, returning `undefined` when the\n * namespace is not a registered dictionary.\n *\n * `getIntlayer` never throws for a missing key — in development it returns a\n * path-stringifying fallback proxy — so a plain `getIntlayer` call cannot tell\n * \"missing namespace\" apart from \"resolved content\". The registry membership\n * check makes the distinction explicit before resolving.\n */\nconst getDictionaryOrUndefined = (\n namespace: DictionaryKeys,\n locale: LocalesValues\n): unknown => {\n if (!(namespace in getDictionaries())) return undefined;\n\n return getIntlayer(namespace, locale);\n};\n\n/**\n * Builds the ordered list of key candidates following i18next's resolution\n * order: context + plural → context → plural → exact key.\n */\nconst buildKeyCandidates = (\n path: string,\n locale: string,\n count: number | undefined,\n context: string | undefined,\n ordinal: boolean\n): string[] => {\n const candidates: string[] = [];\n\n const pluralCategory =\n count === undefined\n ? undefined\n : new Intl.PluralRules(locale, {\n type: ordinal ? 'ordinal' : 'cardinal',\n }).select(count);\n\n if (context) {\n if (pluralCategory) {\n if (ordinal) {\n candidates.push(`${path}_${context}_ordinal_${pluralCategory}`);\n }\n candidates.push(`${path}_${context}_${pluralCategory}`);\n if (count !== 1) candidates.push(`${path}_${context}_plural`);\n }\n candidates.push(`${path}_${context}`);\n }\n\n if (pluralCategory) {\n if (ordinal) candidates.push(`${path}_ordinal_${pluralCategory}`);\n candidates.push(`${path}_${pluralCategory}`);\n // Legacy i18next v3 JSON suffix\n if (count !== 1) candidates.push(`${path}_plural`);\n }\n\n candidates.push(path);\n\n return candidates;\n};\n\n/** Extracts interpolation values from i18next `t()` options. */\nexport const getInterpolationValues = (options?: TOptions): MessageValues => {\n if (!options || typeof options !== 'object') return {};\n\n const replace = (options as { replace?: MessageValues }).replace;\n if (replace) {\n // `count` and `context` are always interpolatable, even with `replace`\n const values: MessageValues = { ...replace };\n if (options.count !== undefined) values.count ??= options.count;\n if (options.context !== undefined) values.context ??= options.context;\n return values;\n }\n\n const values: MessageValues = {};\n for (const [optionKey, optionValue] of Object.entries(options)) {\n if (!CONTROL_OPTION_KEYS.has(optionKey)) values[optionKey] = optionValue;\n }\n return values;\n};\n\nexport type ResolveTranslationParams = {\n /** Locale to resolve against. */\n locale: LocalesValues;\n /** Default namespace (dictionary key) when the key has no `ns:` prefix. */\n namespace: string;\n /** The translation key, possibly `ns:path.to.key`. */\n key: string;\n /** i18next `t()` options (interpolation values, count, context, …). */\n options?: TOptions;\n /** Custom key separator (`init({ keySeparator })`). */\n keySeparator?: string | false;\n /** Custom namespace separator (`init({ nsSeparator })`). */\n nsSeparator?: string | false;\n /** Internal `$t()` nesting recursion depth. */\n depth?: number;\n /**\n * Pre-resolved content of the `namespace` dictionary for `locale`.\n *\n * Supplied by the build-optimized `useDictionary` / `getDictionary`\n * variants, where the dictionary is imported at build time instead of read\n * from the runtime registry. Only used when the call resolves to the\n * default `namespace` without a locale override — cross-namespace\n * (`other:key`, `{ ns }`) and `{ lng }` lookups still go through\n * `getIntlayer`.\n */\n dictionaryContent?: unknown;\n};\n\n/**\n * Resolves a single translation key the i18next way against intlayer\n * dictionaries.\n *\n * Returns the resolved value: a string in the common case, or an\n * object/array when `returnObjects: true`. Returns `undefined` when the key\n * cannot be resolved (caller decides between `defaultValue`, fallback keys\n * and key echo).\n */\nexport const resolveTranslation = ({\n locale,\n namespace,\n key,\n options,\n keySeparator = '.',\n nsSeparator = ':',\n depth = 0,\n dictionaryContent,\n}: ResolveTranslationParams): unknown => {\n // Namespace resolution: `ns:` prefix > `ns` option > default namespace\n let targetNamespace = namespace;\n let path = key;\n\n if (nsSeparator !== false && key.includes(nsSeparator)) {\n const separatorIndex = key.indexOf(nsSeparator);\n targetNamespace = key.slice(0, separatorIndex);\n path = key.slice(separatorIndex + nsSeparator.length);\n } else if (options?.ns) {\n targetNamespace = Array.isArray(options.ns)\n ? (options.ns[0] as string)\n : (options.ns as string);\n }\n\n const count = typeof options?.count === 'number' ? options.count : undefined;\n const context =\n options?.context !== undefined ? String(options.context) : undefined;\n const ordinal = options?.ordinal === true;\n\n const resolvedLocale = ((options?.lng as string) ?? locale) as LocalesValues;\n\n let dictionary: unknown;\n if (\n dictionaryContent !== undefined &&\n targetNamespace === namespace &&\n options?.lng === undefined\n ) {\n dictionary = dictionaryContent;\n } else {\n dictionary = getDictionaryOrUndefined(\n targetNamespace as DictionaryKeys,\n resolvedLocale\n );\n\n // i18next's default namespace is `translation`, but a single-file JSON\n // source (no `{{key}}` segment) is loaded as the root `index` dictionary.\n // When the *default* namespace is not itself a registered dictionary, fall\n // back to `index` so `t('login.heroSubtitle')` resolves against the\n // whole-file dictionary. Explicit `ns:` prefixes / `ns` options never fall\n // back, so a genuinely missing namespace still returns `undefined`.\n if (\n dictionary === undefined &&\n targetNamespace === namespace &&\n targetNamespace !== ROOT_DICTIONARY_KEY\n ) {\n dictionary = getDictionaryOrUndefined(\n ROOT_DICTIONARY_KEY as DictionaryKeys,\n resolvedLocale\n );\n }\n\n if (dictionary === undefined) return undefined;\n }\n\n let resolvedValue: unknown;\n for (const candidate of buildKeyCandidates(\n path,\n (options?.lng as string) ?? (locale as string),\n count,\n context,\n ordinal\n )) {\n const value = navigatePath(dictionary, candidate, keySeparator);\n if (value !== null && value !== undefined) {\n resolvedValue = value;\n break;\n }\n }\n\n if (resolvedValue === null || resolvedValue === undefined) return undefined;\n\n // `returnObjects: true` — return the raw subtree\n if (\n options?.returnObjects &&\n typeof resolvedValue === 'object' &&\n resolvedValue !== null\n ) {\n return resolvedValue;\n }\n\n const values = getInterpolationValues(options);\n\n let resolved = resolveMessage(\n resolvedValue,\n values,\n ((options?.lng as string) ?? locale) as LocalesValues,\n 'i18next'\n );\n\n // `$t(key)` nesting\n if (depth < MAX_NESTING_DEPTH && resolved.includes('$t(')) {\n resolved = resolved.replace(\n /\\$t\\(\\s*([^),]+?)\\s*(?:,[^)]*)?\\)/g,\n (match, nestedKey: string) => {\n const nestedValue = resolveTranslation({\n locale,\n namespace: targetNamespace,\n key: nestedKey.trim(),\n options,\n keySeparator,\n nsSeparator,\n depth: depth + 1,\n dictionaryContent:\n targetNamespace === namespace ? dictionaryContent : undefined,\n });\n return typeof nestedValue === 'string' ? nestedValue : match;\n }\n );\n }\n\n return resolved;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,MAAM,sBAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;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,OAAO;CAGlE,IACE,SAAS,iBACT,OAAO,kBAAkB,YACzB,kBAAkB,MAElB,OAAO;CAGT,MAAM,SAAS,uBAAuB,OAAO;CAE7C,IAAI,WAAW,eACb,eACA,QACE,SAAS,OAAkB,QAC7B,SACF;CAGA,IAAI,QAAQ,qBAAqB,SAAS,SAAS,KAAK,GACtD,WAAW,SAAS,QAClB,uCACC,OAAO,cAAsB;EAC5B,MAAM,cAAc,mBAAmB;GACrC;GACA,WAAW;GACX,KAAK,UAAU,KAAK;GACpB;GACA;GACA;GACA,OAAO,QAAQ;GACf,mBACE,oBAAoB,YAAY,oBAAoB;EACxD,CAAC;EACD,OAAO,OAAO,gBAAgB,WAAW,cAAc;CACzD,CACF;CAGF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTranslation.d.ts","names":[],"sources":["../../src/resolveTranslation.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"resolveTranslation.d.ts","names":[],"sources":["../../src/resolveTranslation.ts"],"mappings":";;;;;;cAuHa,sBAAA,GAA0B,OAAA,GAAU,QAAA,KAAW,aAiB3D;AAAA,KAEW,wBAAA;EAFX,iCAIC,MAAA,EAAQ,aAAA,EAJT;EAMC,SAAA,UAvBqC;EAyBrC,GAAA,UARD;EAUC,OAAA,GAAU,QAAQ,EARR;EAUV,YAAA;EAEA,WAAA,mBAVA;EAYA,KAAA;EAVA;;;;;;;;;AAqBiB;EAAjB,iBAAA;AAAA;;;;;;;;;;cAYW,kBAAA;EAAsB,MAAA;EAAA,SAAA;EAAA,GAAA;EAAA,OAAA;EAAA,YAAA;EAAA,WAAA;EAAA,KAAA;EAAA;AAAA,GAShC,wBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/i18next",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "i18next API adapter for intlayer — drop-in compatibility layer that exposes the i18next interface while using @intlayer/core under the hood",
|
|
6
6
|
"keywords": [
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@intlayer/config": "9.0.0-canary.
|
|
78
|
-
"@intlayer/core": "9.0.0-canary.
|
|
79
|
-
"@intlayer/dictionaries-entry": "9.0.0-canary.
|
|
80
|
-
"@intlayer/engine": "9.0.0-canary.
|
|
81
|
-
"@intlayer/types": "9.0.0-canary.
|
|
82
|
-
"vite-intlayer": "9.0.0-canary.
|
|
77
|
+
"@intlayer/config": "9.0.0-canary.15",
|
|
78
|
+
"@intlayer/core": "9.0.0-canary.15",
|
|
79
|
+
"@intlayer/dictionaries-entry": "9.0.0-canary.15",
|
|
80
|
+
"@intlayer/engine": "9.0.0-canary.15",
|
|
81
|
+
"@intlayer/types": "9.0.0-canary.15",
|
|
82
|
+
"vite-intlayer": "9.0.0-canary.15"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@types/node": "25.9.4",
|