react-i18next 15.6.1 → 15.7.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 15.7.1
2
+
3
+ - Fix: \_EnableSelector type (for compatibility, enableSelector does not exist in TypeOptions) [1858](https://github.com/i18next/react-i18next/pull/1858)
4
+
5
+ ### 15.7.0
6
+
7
+ - add new selector API to improve TypeScript IDE performance [1852](https://github.com/i18next/react-i18next/pull/1852)
8
+ - read more about it [here](https://github.com/i18next/i18next/blob/master/CHANGELOG.md#2540)
9
+
1
10
  ### 15.6.1
2
11
 
3
12
  avoid exception when passing bindI18n: false [1856](https://github.com/i18next/react-i18next/pull/1856)
@@ -1,9 +1,23 @@
1
- import type { i18n, ParseKeys, Namespace, TypeOptions, TOptions, TFunction } from 'i18next';
1
+ import type {
2
+ i18n,
3
+ ApplyTarget,
4
+ ConstrainTarget,
5
+ GetSource,
6
+ ParseKeys,
7
+ Namespace,
8
+ SelectorFn,
9
+ TypeOptions,
10
+ TOptions,
11
+ TFunction,
12
+ } from 'i18next';
2
13
  import * as React from 'react';
3
14
 
4
15
  type _DefaultNamespace = TypeOptions['defaultNS'];
16
+ type _EnableSelector = TypeOptions['enableSelector'];
5
17
 
6
18
  type TransChild = React.ReactNode | Record<string, unknown>;
19
+ type $NoInfer<T> = [T][T extends T ? 0 : never];
20
+
7
21
  export type TransProps<
8
22
  Key extends ParseKeys<Ns, TOpt, KPrefix>,
9
23
  Ns extends Namespace = _DefaultNamespace,
@@ -27,14 +41,56 @@ export type TransProps<
27
41
  t?: TFunction<Ns, KPrefix>;
28
42
  };
29
43
 
30
- export function Trans<
31
- Key extends ParseKeys<Ns, TOpt, KPrefix>,
44
+ export interface TransLegacy {
45
+ <
46
+ Key extends ParseKeys<Ns, TOpt, KPrefix>,
47
+ Ns extends Namespace = _DefaultNamespace,
48
+ KPrefix = undefined,
49
+ TContext extends string | undefined = undefined,
50
+ TOpt extends TOptions & { context?: TContext } = { context: TContext },
51
+ E = React.HTMLProps<HTMLDivElement>,
52
+ >(
53
+ props: TransProps<Key, Ns, KPrefix, TContext, TOpt, E>,
54
+ ): React.ReactElement;
55
+ }
56
+
57
+ export interface TransSelectorProps<
58
+ Key,
32
59
  Ns extends Namespace = _DefaultNamespace,
33
60
  KPrefix = undefined,
34
61
  TContext extends string | undefined = undefined,
35
62
  TOpt extends TOptions & { context?: TContext } = { context: TContext },
36
- E = React.HTMLProps<HTMLDivElement>,
37
- >(props: TransProps<Key, Ns, KPrefix, TContext, TOpt, E>): React.ReactElement;
63
+ > {
64
+ children?: TransChild | readonly TransChild[];
65
+ components?: readonly React.ReactElement[] | { readonly [tagName: string]: React.ReactElement };
66
+ count?: number;
67
+ context?: TContext;
68
+ defaults?: string;
69
+ i18n?: i18n;
70
+ i18nKey?: Key;
71
+ ns?: Ns;
72
+ parent?: string | React.ComponentType<any> | null; // used in React.createElement if not null
73
+ tOptions?: TOpt;
74
+ values?: {};
75
+ shouldUnescape?: boolean;
76
+ t?: TFunction<Ns, KPrefix>;
77
+ }
78
+
79
+ export interface TransSelector {
80
+ <
81
+ Target extends ConstrainTarget<TOpt>,
82
+ Key extends SelectorFn<GetSource<$NoInfer<Ns>, KPrefix>, ApplyTarget<Target, TOpt>, TOpt>,
83
+ const Ns extends Namespace = _DefaultNamespace,
84
+ KPrefix = undefined,
85
+ TContext extends string | undefined = undefined,
86
+ TOpt extends TOptions & { context?: TContext } = { context: TContext },
87
+ E = React.HTMLProps<HTMLDivElement>,
88
+ >(
89
+ props: TransSelectorProps<Key, Ns, KPrefix, TContext, TOpt> & E,
90
+ ): React.ReactElement;
91
+ }
92
+
93
+ export const Trans: _EnableSelector extends true | 'optimize' ? TransSelector : TransLegacy;
38
94
 
39
95
  export type ErrorCode =
40
96
  | 'NO_I18NEXT_INSTANCE'
@@ -1 +1 @@
1
- {"type":"module","version":"15.6.1"}
1
+ {"type":"module","version":"15.7.1"}
package/index.d.ts CHANGED
@@ -67,7 +67,10 @@ type _DefaultNamespace = TypeOptions['defaultNS'];
67
67
 
68
68
  export function useSSR(initialI18nStore: Resource, initialLanguage: string): void;
69
69
 
70
- export interface UseTranslationOptions<KPrefix> {
70
+ // If the version is earlier than i18next v25.4.0, enableSelector does not exist in TypeOptions, so a conditional type is used to maintain type compatibility.
71
+ type _EnableSelector = TypeOptions extends { enableSelector: infer U } ? U : false;
72
+
73
+ export type UseTranslationOptions<KPrefix> = {
71
74
  i18n?: i18n;
72
75
  useSuspense?: boolean;
73
76
  keyPrefix?: KPrefix;
@@ -75,7 +78,7 @@ export interface UseTranslationOptions<KPrefix> {
75
78
  nsMode?: 'fallback' | 'default';
76
79
  lng?: string;
77
80
  // other of these options might also work: https://github.com/i18next/i18next/blob/master/index.d.ts#L127
78
- }
81
+ };
79
82
 
80
83
  export type UseTranslationResponse<Ns extends Namespace, KPrefix> = [
81
84
  t: TFunction<Ns, KPrefix>,
@@ -96,13 +99,29 @@ export type FallbackNs<Ns> = Ns extends undefined
96
99
  ? Ns
97
100
  : _DefaultNamespace;
98
101
 
99
- export function useTranslation<
100
- const Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
101
- const KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
102
- >(
103
- ns?: Ns,
104
- options?: UseTranslationOptions<KPrefix>,
105
- ): UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
102
+ export const useTranslation: _EnableSelector extends true | 'optimize'
103
+ ? UseTranslationSelector
104
+ : UseTranslationLegacy;
105
+
106
+ interface UseTranslationLegacy {
107
+ <
108
+ const Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
109
+ const KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
110
+ >(
111
+ ns?: Ns,
112
+ options?: UseTranslationOptions<KPrefix>,
113
+ ): UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
114
+ }
115
+
116
+ interface UseTranslationSelector {
117
+ <
118
+ const Ns extends FlatNamespace | $Tuple<FlatNamespace> | undefined = undefined,
119
+ const KPrefix = undefined,
120
+ >(
121
+ ns?: Ns,
122
+ options?: UseTranslationOptions<KPrefix>,
123
+ ): UseTranslationResponse<FallbackNs<Ns>, KPrefix>;
124
+ }
106
125
 
107
126
  // Need to see usage to improve this
108
127
  export function withSSR(): <Props>(WrappedComponent: React.ComponentType<Props>) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "15.6.1",
3
+ "version": "15.7.1",
4
4
  "description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "types": "./index.d.mts",
@@ -68,7 +68,7 @@
68
68
  "html-parse-stringify": "^3.0.1"
69
69
  },
70
70
  "peerDependencies": {
71
- "i18next": ">= 23.2.3",
71
+ "i18next": ">= 23.4.0",
72
72
  "react": ">= 16.8.0",
73
73
  "typescript": "^5"
74
74
  },
@@ -123,7 +123,7 @@
123
123
  "eslint-plugin-testing-library": "^6.5.0",
124
124
  "happy-dom": "^14.12.3",
125
125
  "husky": "^9.1.7",
126
- "i18next": "^25.3.0",
126
+ "i18next": "^25.4.0",
127
127
  "lint-staged": "^15.5.2",
128
128
  "mkdirp": "^3.0.1",
129
129
  "prettier": "^3.6.2",