@intlayer/react-i18next 9.5.0 → 9.5.2

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,5 @@
1
1
  import { getHTMLTextDir } from "@intlayer/core/localization";
2
- import { resolveMessage } from "@intlayer/core/messageFormat";
2
+ import { resolveMessageNodeToString } from "@intlayer/core/messageFormat";
3
3
  import { getInterpolationValues, resolveTranslation } from "@intlayer/i18next";
4
4
 
5
5
  //#region src/createTranslationApi.ts
@@ -33,7 +33,7 @@ const createTranslationApi = ({ locale, setLocale, availableLocales, namespace,
33
33
  if (resolved !== void 0) return resolved;
34
34
  }
35
35
  const defaultValue = translateOptions.defaultValue;
36
- if (typeof defaultValue === "string") return resolveMessage(defaultValue, getInterpolationValues(translateOptions), locale, "i18next");
36
+ if (typeof defaultValue === "string") return resolveMessageNodeToString(defaultValue, getInterpolationValues(translateOptions), locale);
37
37
  return keys[keys.length - 1];
38
38
  };
39
39
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"createTranslationApi.mjs","names":[],"sources":["../../src/createTranslationApi.ts"],"sourcesContent":["import { getHTMLTextDir } from '@intlayer/core/localization';\nimport { resolveMessage } from '@intlayer/core/messageFormat';\nimport {\n getInterpolationValues,\n resolveTranslation,\n type TypedTFunction,\n} from '@intlayer/i18next';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\n\n/** Untyped runtime `t()` produced by {@link createTranslationApi}. */\nexport type TranslateFunction = (\n key: string | string[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n) => string;\n\n/**\n * The `i18n` facade with `t` and `getFixedT` typed against the dictionary the\n * hook is bound to: `t` is the hook's translate function type `TFn`, and\n * `getFixedT` returns a fully-typed `t()` for the requested namespace (or the\n * hook's own `t()` when no namespace is given).\n */\nexport type TypedI18nFacade<TFn = TranslateFunction> = Omit<\n I18nFacade,\n 't' | 'getFixedT'\n> & {\n t: TFn;\n getFixedT: {\n <N extends DictionaryKeys>(\n language: string | null | undefined,\n fixedNamespace: N\n ): TypedTFunction<N>;\n (language?: string | null, fixedNamespace?: null): TFn;\n };\n};\n\n/** Result shape of the typed translation hooks: `{ t, i18n, ready }`. */\nexport type TypedTranslationResult<TFn = TranslateFunction> = {\n t: TFn;\n i18n: TypedI18nFacade<TFn>;\n ready: true;\n};\n\n/** `i18n` facade shape produced by {@link createTranslationApi}. */\nexport type I18nFacade = {\n language: string;\n languages: string[];\n resolvedLanguage: string;\n isInitialized: boolean;\n changeLanguage: (newLanguage: string) => Promise<void>;\n dir: (language?: string) => 'ltr' | 'rtl';\n exists: (key: string, existsOptions?: TOptions) => boolean;\n t: TranslateFunction;\n getFixedT: (\n language?: string | null,\n fixedNamespace?: string | null\n ) => (key: string, fixedOptions?: TOptions) => string;\n};\n\nexport type CreateTranslationApiParams = {\n /** Active locale. */\n locale: LocalesValues;\n /** Locale setter backing `i18n.changeLanguage`. */\n setLocale: (newLocale: LocalesValues) => void;\n /** Configured locales backing `i18n.languages`. */\n availableLocales: LocalesValues[];\n /** Default namespace (dictionary key) for `t()` lookups. */\n namespace: string;\n /** Optional prefix prepended to every `t()` key. */\n keyPrefix?: string;\n /**\n * Pre-resolved dictionary content for `namespace` — supplied by the\n * build-optimized `useDictionary` / `useDictionaryDynamic` variants so\n * lookups skip the runtime registry.\n */\n dictionaryContent?: unknown;\n};\n\n/**\n * Builds the `{ t, i18n }` pair shared by `useTranslation` (runtime\n * registry lookup) and `useDictionary` / `useDictionaryDynamic`\n * (build-time-imported dictionary content).\n *\n * Translation lookup goes through the shared i18next-dialect resolver:\n * namespace prefixes (`ns:key`), the `ns` option, plural suffixes\n * (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation\n * are all supported.\n */\nexport const createTranslationApi = ({\n locale,\n setLocale,\n availableLocales,\n namespace,\n keyPrefix,\n dictionaryContent,\n}: CreateTranslationApiParams): {\n translate: TranslateFunction;\n i18n: I18nFacade;\n} => {\n const resolveSingleKey = (\n key: string,\n translateOptions?: TOptions\n ): unknown =>\n resolveTranslation({\n locale,\n namespace,\n key: keyPrefix ? `${keyPrefix}.${key}` : key,\n options: translateOptions,\n dictionaryContent,\n });\n\n const translate: TranslateFunction = (\n key,\n optionsOrDefaultValue,\n extraOptions\n ) => {\n const translateOptions: TOptions =\n typeof optionsOrDefaultValue === 'string'\n ? { defaultValue: optionsOrDefaultValue, ...extraOptions }\n : (optionsOrDefaultValue ?? {});\n\n const keys = Array.isArray(key) ? key : [key];\n\n for (const candidateKey of keys) {\n const resolved = resolveSingleKey(candidateKey, translateOptions);\n if (resolved !== undefined) return resolved as string;\n }\n\n const defaultValue = translateOptions.defaultValue;\n if (typeof defaultValue === 'string') {\n return resolveMessage(\n defaultValue,\n getInterpolationValues(translateOptions),\n locale,\n 'i18next'\n );\n }\n\n return keys[keys.length - 1] as string;\n };\n\n const i18n: I18nFacade = {\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n resolvedLanguage: locale as string,\n isInitialized: true,\n changeLanguage: async (newLanguage: string) => {\n setLocale(newLanguage as LocalesValues);\n },\n dir: (language?: string): 'ltr' | 'rtl' => {\n const direction = getHTMLTextDir((language ?? locale) as LocalesValues);\n return direction === 'rtl' ? 'rtl' : 'ltr';\n },\n exists: (key: string, existsOptions?: TOptions): boolean =>\n resolveTranslation({\n locale,\n namespace,\n key,\n options: existsOptions,\n dictionaryContent,\n }) !== undefined,\n t: translate,\n getFixedT:\n (language?: string | null, fixedNamespace?: string | null) =>\n (key: string, fixedOptions?: TOptions): string => {\n const resolved = resolveTranslation({\n locale: (language ?? locale) as LocalesValues,\n namespace: fixedNamespace ?? namespace,\n key,\n options: fixedOptions,\n dictionaryContent:\n (language ?? locale) === locale &&\n (fixedNamespace ?? namespace) === namespace\n ? dictionaryContent\n : undefined,\n });\n return resolved !== undefined ? (resolved as string) : key;\n },\n };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3B"}
1
+ {"version":3,"file":"createTranslationApi.mjs","names":[],"sources":["../../src/createTranslationApi.ts"],"sourcesContent":["import { getHTMLTextDir } from '@intlayer/core/localization';\nimport { resolveMessageNodeToString } from '@intlayer/core/messageFormat';\nimport {\n getInterpolationValues,\n resolveTranslation,\n type TypedTFunction,\n} from '@intlayer/i18next';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { TOptions } from 'i18next';\n\n/** Untyped runtime `t()` produced by {@link createTranslationApi}. */\nexport type TranslateFunction = (\n key: string | string[],\n optionsOrDefaultValue?: TOptions | string,\n extraOptions?: TOptions\n) => string;\n\n/**\n * The `i18n` facade with `t` and `getFixedT` typed against the dictionary the\n * hook is bound to: `t` is the hook's translate function type `TFn`, and\n * `getFixedT` returns a fully-typed `t()` for the requested namespace (or the\n * hook's own `t()` when no namespace is given).\n */\nexport type TypedI18nFacade<TFn = TranslateFunction> = Omit<\n I18nFacade,\n 't' | 'getFixedT'\n> & {\n t: TFn;\n getFixedT: {\n <N extends DictionaryKeys>(\n language: string | null | undefined,\n fixedNamespace: N\n ): TypedTFunction<N>;\n (language?: string | null, fixedNamespace?: null): TFn;\n };\n};\n\n/** Result shape of the typed translation hooks: `{ t, i18n, ready }`. */\nexport type TypedTranslationResult<TFn = TranslateFunction> = {\n t: TFn;\n i18n: TypedI18nFacade<TFn>;\n ready: true;\n};\n\n/** `i18n` facade shape produced by {@link createTranslationApi}. */\nexport type I18nFacade = {\n language: string;\n languages: string[];\n resolvedLanguage: string;\n isInitialized: boolean;\n changeLanguage: (newLanguage: string) => Promise<void>;\n dir: (language?: string) => 'ltr' | 'rtl';\n exists: (key: string, existsOptions?: TOptions) => boolean;\n t: TranslateFunction;\n getFixedT: (\n language?: string | null,\n fixedNamespace?: string | null\n ) => (key: string, fixedOptions?: TOptions) => string;\n};\n\nexport type CreateTranslationApiParams = {\n /** Active locale. */\n locale: LocalesValues;\n /** Locale setter backing `i18n.changeLanguage`. */\n setLocale: (newLocale: LocalesValues) => void;\n /** Configured locales backing `i18n.languages`. */\n availableLocales: LocalesValues[];\n /** Default namespace (dictionary key) for `t()` lookups. */\n namespace: string;\n /** Optional prefix prepended to every `t()` key. */\n keyPrefix?: string;\n /**\n * Pre-resolved dictionary content for `namespace` — supplied by the\n * build-optimized `useDictionary` / `useDictionaryDynamic` variants so\n * lookups skip the runtime registry.\n */\n dictionaryContent?: unknown;\n};\n\n/**\n * Builds the `{ t, i18n }` pair shared by `useTranslation` (runtime\n * registry lookup) and `useDictionary` / `useDictionaryDynamic`\n * (build-time-imported dictionary content).\n *\n * Translation lookup goes through the shared i18next-dialect resolver:\n * namespace prefixes (`ns:key`), the `ns` option, plural suffixes\n * (`key_one`/`key_other` via `Intl.PluralRules`), context suffixes\n * (`key_male`), `$t()` nesting, `defaultValue` and `{{var}}` interpolation\n * are all supported.\n */\nexport const createTranslationApi = ({\n locale,\n setLocale,\n availableLocales,\n namespace,\n keyPrefix,\n dictionaryContent,\n}: CreateTranslationApiParams): {\n translate: TranslateFunction;\n i18n: I18nFacade;\n} => {\n const resolveSingleKey = (\n key: string,\n translateOptions?: TOptions\n ): unknown =>\n resolveTranslation({\n locale,\n namespace,\n key: keyPrefix ? `${keyPrefix}.${key}` : key,\n options: translateOptions,\n dictionaryContent,\n });\n\n const translate: TranslateFunction = (\n key,\n optionsOrDefaultValue,\n extraOptions\n ) => {\n const translateOptions: TOptions =\n typeof optionsOrDefaultValue === 'string'\n ? { defaultValue: optionsOrDefaultValue, ...extraOptions }\n : (optionsOrDefaultValue ?? {});\n\n const keys = Array.isArray(key) ? key : [key];\n\n for (const candidateKey of keys) {\n const resolved = resolveSingleKey(candidateKey, translateOptions);\n if (resolved !== undefined) return resolved as string;\n }\n\n const defaultValue = translateOptions.defaultValue;\n if (typeof defaultValue === 'string') {\n return resolveMessageNodeToString(\n defaultValue,\n getInterpolationValues(translateOptions),\n locale\n );\n }\n\n return keys[keys.length - 1] as string;\n };\n\n const i18n: I18nFacade = {\n language: locale as string,\n languages: (availableLocales ?? []) as string[],\n resolvedLanguage: locale as string,\n isInitialized: true,\n changeLanguage: async (newLanguage: string) => {\n setLocale(newLanguage as LocalesValues);\n },\n dir: (language?: string): 'ltr' | 'rtl' => {\n const direction = getHTMLTextDir((language ?? locale) as LocalesValues);\n return direction === 'rtl' ? 'rtl' : 'ltr';\n },\n exists: (key: string, existsOptions?: TOptions): boolean =>\n resolveTranslation({\n locale,\n namespace,\n key,\n options: existsOptions,\n dictionaryContent,\n }) !== undefined,\n t: translate,\n getFixedT:\n (language?: string | null, fixedNamespace?: string | null) =>\n (key: string, fixedOptions?: TOptions): string => {\n const resolved = resolveTranslation({\n locale: (language ?? locale) as LocalesValues,\n namespace: fixedNamespace ?? namespace,\n key,\n options: fixedOptions,\n dictionaryContent:\n (language ?? locale) === locale &&\n (fixedNamespace ?? namespace) === namespace\n ? dictionaryContent\n : undefined,\n });\n return resolved !== undefined ? (resolved as string) : key;\n },\n };\n\n return { translate, i18n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA6FA,MAAa,wBAAwB,EACnC,QACA,WACA,kBACA,WACA,WACA,wBAIG;CACH,MAAM,oBACJ,KACA,qBAEA,mBAAmB;EACjB;EACA;EACA,KAAK,YAAY,GAAG,UAAU,GAAG,QAAQ;EACzC,SAAS;EACT;CACF,CAAC;CAEH,MAAM,aACJ,KACA,uBACA,iBACG;EACH,MAAM,mBACJ,OAAO,0BAA0B,WAC7B;GAAE,cAAc;GAAuB,GAAG;EAAa,IACtD,yBAAyB,CAAC;EAEjC,MAAM,OAAO,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;EAE5C,KAAK,MAAM,gBAAgB,MAAM;GAC/B,MAAM,WAAW,iBAAiB,cAAc,gBAAgB;GAChE,IAAI,aAAa,QAAW,OAAO;EACrC;EAEA,MAAM,eAAe,iBAAiB;EACtC,IAAI,OAAO,iBAAiB,UAC1B,OAAO,2BACL,cACA,uBAAuB,gBAAgB,GACvC,MACF;EAGF,OAAO,KAAK,KAAK,SAAS;CAC5B;CAyCA,OAAO;EAAE;EAAW;GAtClB,UAAU;GACV,WAAY,oBAAoB,CAAC;GACjC,kBAAkB;GAClB,eAAe;GACf,gBAAgB,OAAO,gBAAwB;IAC7C,UAAU,WAA4B;GACxC;GACA,MAAM,aAAqC;IAEzC,OADkB,eAAgB,YAAY,MAC/B,MAAM,QAAQ,QAAQ;GACvC;GACA,SAAS,KAAa,kBACpB,mBAAmB;IACjB;IACA;IACA;IACA,SAAS;IACT;GACF,CAAC,MAAM;GACT,GAAG;GACH,YACG,UAA0B,oBAC1B,KAAa,iBAAoC;IAChD,MAAM,WAAW,mBAAmB;KAClC,QAAS,YAAY;KACrB,WAAW,kBAAkB;KAC7B;KACA,SAAS;KACT,oBACG,YAAY,YAAY,WACxB,kBAAkB,eAAe,YAC9B,oBACA;IACR,CAAC;IACD,OAAO,aAAa,SAAa,WAAsB;GACzD;EAGmB;CAAE;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/react-i18next",
3
- "version": "9.5.0",
3
+ "version": "9.5.2",
4
4
  "private": false,
5
5
  "description": "react-i18next API adapter for intlayer — useTranslation, Trans, withTranslation, I18nextProvider backed by react-intlayer",
6
6
  "keywords": [
@@ -76,17 +76,17 @@
76
76
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
77
77
  },
78
78
  "dependencies": {
79
- "@intlayer/config": "9.5.0",
80
- "@intlayer/core": "9.5.0",
81
- "@intlayer/engine": "9.5.0",
82
- "@intlayer/i18next": "9.5.0",
83
- "@intlayer/types": "9.5.0",
84
- "react-intlayer": "9.5.0",
85
- "vite-intlayer": "9.5.0"
79
+ "@intlayer/config": "9.5.2",
80
+ "@intlayer/core": "9.5.2",
81
+ "@intlayer/engine": "9.5.2",
82
+ "@intlayer/i18next": "9.5.2",
83
+ "@intlayer/types": "9.5.2",
84
+ "react-intlayer": "9.5.2",
85
+ "vite-intlayer": "9.5.2"
86
86
  },
87
87
  "devDependencies": {
88
- "@types/node": "26.5.0",
89
- "@types/react": "19.2.18",
88
+ "@types/node": "^22",
89
+ "@types/react": "19.3.0",
90
90
  "@utils/ts-config": "1.0.4",
91
91
  "@utils/ts-config-types": "1.0.4",
92
92
  "@utils/tsdown-config": "1.0.4",
@@ -95,7 +95,7 @@
95
95
  "rimraf": "6.1.3",
96
96
  "tsdown": "0.23.0",
97
97
  "typescript": "7.0.2",
98
- "vite": "8.2.2",
98
+ "vite": "8.3.0",
99
99
  "vitest": "5.0.0"
100
100
  },
101
101
  "peerDependencies": {