@lingui/react 4.10.0 → 4.11.0

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.
@@ -9,26 +9,23 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
9
9
  const React__default = /*#__PURE__*/_interopDefaultCompat(React);
10
10
 
11
11
  function TransRsc(props) {
12
- const i18n = server.getI18n();
13
- if (!i18n) {
12
+ const ctx = server.getI18n();
13
+ if (!ctx) {
14
14
  throw new Error(
15
- "You tried to use `Trans` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in root of your page"
15
+ "You tried to use `Trans` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
16
16
  );
17
17
  }
18
- return /* @__PURE__ */ React__default.createElement(TransNoContext.TransNoContext, { ...props, lingui: { i18n } });
18
+ return /* @__PURE__ */ React__default.createElement(TransNoContext.TransNoContext, { ...props, lingui: ctx });
19
19
  }
20
20
 
21
21
  function useLingui() {
22
- const i18n = server.getI18n();
23
- if (!i18n) {
22
+ const ctx = server.getI18n();
23
+ if (!ctx) {
24
24
  throw new Error(
25
- "You tried to use `useLingui` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in root of your page"
25
+ "You tried to use `useLingui` in a Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
26
26
  );
27
27
  }
28
- return {
29
- i18n,
30
- _: i18n.t.bind(i18n)
31
- };
28
+ return ctx;
32
29
  }
33
30
 
34
31
  exports.Trans = TransRsc;
@@ -1,6 +1,5 @@
1
- import { T as TransProps } from './shared/react.a673be03.cjs';
2
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.cjs';
3
- import { b as I18nContext } from './shared/react.db09d9c7.cjs';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.e5f95de8.cjs';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.cjs';
4
3
  import React from 'react';
5
4
  import '@lingui/core';
6
5
 
@@ -1,6 +1,5 @@
1
- import { T as TransProps } from './shared/react.a673be03.mjs';
2
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.mjs';
3
- import { b as I18nContext } from './shared/react.145db227.mjs';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.e5f95de8.mjs';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.mjs';
4
3
  import React from 'react';
5
4
  import '@lingui/core';
6
5
 
@@ -1,6 +1,5 @@
1
- import { T as TransProps } from './shared/react.a673be03.js';
2
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.js';
3
- import { b as I18nContext } from './shared/react.80f80298.js';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.e5f95de8.js';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.js';
4
3
  import React from 'react';
5
4
  import '@lingui/core';
6
5
 
@@ -3,26 +3,23 @@ import { T as TransNoContext } from './shared/react.1d406965.mjs';
3
3
  import React from 'react';
4
4
 
5
5
  function TransRsc(props) {
6
- const i18n = getI18n();
7
- if (!i18n) {
6
+ const ctx = getI18n();
7
+ if (!ctx) {
8
8
  throw new Error(
9
- "You tried to use `Trans` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in root of your page"
9
+ "You tried to use `Trans` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
10
10
  );
11
11
  }
12
- return /* @__PURE__ */ React.createElement(TransNoContext, { ...props, lingui: { i18n } });
12
+ return /* @__PURE__ */ React.createElement(TransNoContext, { ...props, lingui: ctx });
13
13
  }
14
14
 
15
15
  function useLingui() {
16
- const i18n = getI18n();
17
- if (!i18n) {
16
+ const ctx = getI18n();
17
+ if (!ctx) {
18
18
  throw new Error(
19
- "You tried to use `useLingui` in Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in root of your page"
19
+ "You tried to use `useLingui` in a Server Component, but i18n instance for RSC hasn't been setup.\nMake sure to call `setI18n` in the root of your page."
20
20
  );
21
21
  }
22
- return {
23
- i18n,
24
- _: i18n.t.bind(i18n)
25
- };
22
+ return ctx;
26
23
  }
27
24
 
28
25
  export { TransRsc as Trans, useLingui };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, u as useLingui } from './shared/react.db09d9c7.cjs';
1
+ import { T as TransProps } from './shared/react.e5f95de8.cjs';
2
+ export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, d as TransRenderCallbackOrComponent, c as TransRenderProps, u as useLingui } from './shared/react.e5f95de8.cjs';
2
3
  import React from 'react';
3
- import { T as TransProps } from './shared/react.a673be03.cjs';
4
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.cjs';
5
4
  import '@lingui/core';
6
5
 
7
6
  declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, u as useLingui } from './shared/react.145db227.mjs';
1
+ import { T as TransProps } from './shared/react.e5f95de8.mjs';
2
+ export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, d as TransRenderCallbackOrComponent, c as TransRenderProps, u as useLingui } from './shared/react.e5f95de8.mjs';
2
3
  import React from 'react';
3
- import { T as TransProps } from './shared/react.a673be03.mjs';
4
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.mjs';
5
4
  import '@lingui/core';
6
5
 
7
6
  declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, u as useLingui } from './shared/react.80f80298.js';
1
+ import { T as TransProps } from './shared/react.e5f95de8.js';
2
+ export { b as I18nContext, I as I18nProvider, a as I18nProviderProps, L as LinguiContext, d as TransRenderCallbackOrComponent, c as TransRenderProps, u as useLingui } from './shared/react.e5f95de8.js';
2
3
  import React from 'react';
3
- import { T as TransProps } from './shared/react.a673be03.js';
4
- export { b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.js';
5
4
  import '@lingui/core';
6
5
 
7
6
  declare function Trans(props: TransProps): React.ReactElement<any, any> | null;
package/dist/server.cjs CHANGED
@@ -10,17 +10,23 @@ const React__default = /*#__PURE__*/_interopDefaultCompat(React);
10
10
  let cache = null;
11
11
  const getLinguiCache = () => {
12
12
  if (!cache) {
13
- cache = React__default.cache(() => ({
14
- current: null
15
- }));
13
+ cache = React__default.cache(
14
+ () => ({
15
+ current: null
16
+ })
17
+ );
16
18
  }
17
19
  return cache();
18
20
  };
19
- function setI18n(i18n) {
20
- getLinguiCache().current = i18n;
21
+ function setI18n(i18n, defaultComponent) {
22
+ getLinguiCache().current = {
23
+ i18n,
24
+ _: i18n._.bind(i18n),
25
+ defaultComponent
26
+ };
21
27
  }
22
28
  function getI18n() {
23
- return getLinguiCache().current;
29
+ return getLinguiCache()?.current;
24
30
  }
25
31
 
26
32
  exports.TransNoContext = TransNoContext.TransNoContext;
package/dist/server.d.cts CHANGED
@@ -1,12 +1,13 @@
1
- export { c as TransNoContext, T as TransProps, b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.cjs';
1
+ import { b as I18nContext } from './shared/react.e5f95de8.cjs';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.cjs';
2
3
  import { I18n } from '@lingui/core';
3
4
  import 'react';
4
5
 
5
6
  /**
6
7
  * This is an entry point for React Server Components (RSC)
7
8
  *
8
- * The RSC uses a static analysis to find any non-valid function calls in the import graph.
9
- * That means this entry point and it's children should not have any Provider/Context calls.
9
+ * RSC uses static analysis to find any non-valid function calls in the import graph.
10
+ * That means this entry point and its children must not have any Provider/Context calls.
10
11
  */
11
12
 
12
13
  /**
@@ -25,7 +26,7 @@ import 'react';
25
26
  * setI18n(i18n);
26
27
  * ```
27
28
  */
28
- declare function setI18n(i18n: I18n): void;
29
+ declare function setI18n(i18n: I18n, defaultComponent?: I18nContext["defaultComponent"]): void;
29
30
  /**
30
31
  * Get Lingui's i18n instance saved for RSC
31
32
  *
@@ -39,6 +40,6 @@ declare function setI18n(i18n: I18n): void;
39
40
  * }
40
41
  * ```
41
42
  */
42
- declare function getI18n(): I18n | null;
43
+ declare function getI18n(): I18nContext | null;
43
44
 
44
45
  export { getI18n, setI18n };
package/dist/server.d.mts CHANGED
@@ -1,12 +1,13 @@
1
- export { c as TransNoContext, T as TransProps, b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.mjs';
1
+ import { b as I18nContext } from './shared/react.e5f95de8.mjs';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.mjs';
2
3
  import { I18n } from '@lingui/core';
3
4
  import 'react';
4
5
 
5
6
  /**
6
7
  * This is an entry point for React Server Components (RSC)
7
8
  *
8
- * The RSC uses a static analysis to find any non-valid function calls in the import graph.
9
- * That means this entry point and it's children should not have any Provider/Context calls.
9
+ * RSC uses static analysis to find any non-valid function calls in the import graph.
10
+ * That means this entry point and its children must not have any Provider/Context calls.
10
11
  */
11
12
 
12
13
  /**
@@ -25,7 +26,7 @@ import 'react';
25
26
  * setI18n(i18n);
26
27
  * ```
27
28
  */
28
- declare function setI18n(i18n: I18n): void;
29
+ declare function setI18n(i18n: I18n, defaultComponent?: I18nContext["defaultComponent"]): void;
29
30
  /**
30
31
  * Get Lingui's i18n instance saved for RSC
31
32
  *
@@ -39,6 +40,6 @@ declare function setI18n(i18n: I18n): void;
39
40
  * }
40
41
  * ```
41
42
  */
42
- declare function getI18n(): I18n | null;
43
+ declare function getI18n(): I18nContext | null;
43
44
 
44
45
  export { getI18n, setI18n };
package/dist/server.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export { c as TransNoContext, T as TransProps, b as TransRenderCallbackOrComponent, a as TransRenderProps } from './shared/react.a673be03.js';
1
+ import { b as I18nContext } from './shared/react.e5f95de8.js';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.e5f95de8.js';
2
3
  import { I18n } from '@lingui/core';
3
4
  import 'react';
4
5
 
5
6
  /**
6
7
  * This is an entry point for React Server Components (RSC)
7
8
  *
8
- * The RSC uses a static analysis to find any non-valid function calls in the import graph.
9
- * That means this entry point and it's children should not have any Provider/Context calls.
9
+ * RSC uses static analysis to find any non-valid function calls in the import graph.
10
+ * That means this entry point and its children must not have any Provider/Context calls.
10
11
  */
11
12
 
12
13
  /**
@@ -25,7 +26,7 @@ import 'react';
25
26
  * setI18n(i18n);
26
27
  * ```
27
28
  */
28
- declare function setI18n(i18n: I18n): void;
29
+ declare function setI18n(i18n: I18n, defaultComponent?: I18nContext["defaultComponent"]): void;
29
30
  /**
30
31
  * Get Lingui's i18n instance saved for RSC
31
32
  *
@@ -39,6 +40,6 @@ declare function setI18n(i18n: I18n): void;
39
40
  * }
40
41
  * ```
41
42
  */
42
- declare function getI18n(): I18n | null;
43
+ declare function getI18n(): I18nContext | null;
43
44
 
44
45
  export { getI18n, setI18n };
package/dist/server.mjs CHANGED
@@ -4,17 +4,23 @@ import React from 'react';
4
4
  let cache = null;
5
5
  const getLinguiCache = () => {
6
6
  if (!cache) {
7
- cache = React.cache(() => ({
8
- current: null
9
- }));
7
+ cache = React.cache(
8
+ () => ({
9
+ current: null
10
+ })
11
+ );
10
12
  }
11
13
  return cache();
12
14
  };
13
- function setI18n(i18n) {
14
- getLinguiCache().current = i18n;
15
+ function setI18n(i18n, defaultComponent) {
16
+ getLinguiCache().current = {
17
+ i18n,
18
+ _: i18n._.bind(i18n),
19
+ defaultComponent
20
+ };
15
21
  }
16
22
  function getI18n() {
17
- return getLinguiCache().current;
23
+ return getLinguiCache()?.current;
18
24
  }
19
25
 
20
26
  export { getI18n, setI18n };
@@ -1,4 +1,4 @@
1
- import React, { ComponentType } from 'react';
1
+ import React, { ComponentType, FunctionComponent } from 'react';
2
2
  import { MessageOptions, I18n } from '@lingui/core';
3
3
 
4
4
  type TransRenderProps = {
@@ -42,4 +42,16 @@ declare function TransNoContext(props: TransProps & {
42
42
  };
43
43
  }): React.ReactElement<any, any> | null;
44
44
 
45
- export { type TransProps as T, type TransRenderProps as a, type TransRenderCallbackOrComponent as b, TransNoContext as c };
45
+ type I18nContext = {
46
+ i18n: I18n;
47
+ _: I18n["_"];
48
+ defaultComponent?: ComponentType<TransRenderProps>;
49
+ };
50
+ type I18nProviderProps = Omit<I18nContext, "_"> & {
51
+ children?: React.ReactNode;
52
+ };
53
+ declare const LinguiContext: React.Context<I18nContext | null>;
54
+ declare function useLingui(): I18nContext;
55
+ declare const I18nProvider: FunctionComponent<I18nProviderProps>;
56
+
57
+ export { I18nProvider as I, LinguiContext as L, type TransProps as T, type I18nProviderProps as a, type I18nContext as b, type TransRenderProps as c, type TransRenderCallbackOrComponent as d, TransNoContext as e, useLingui as u };
@@ -1,4 +1,4 @@
1
- import React, { ComponentType } from 'react';
1
+ import React, { ComponentType, FunctionComponent } from 'react';
2
2
  import { MessageOptions, I18n } from '@lingui/core';
3
3
 
4
4
  type TransRenderProps = {
@@ -42,4 +42,16 @@ declare function TransNoContext(props: TransProps & {
42
42
  };
43
43
  }): React.ReactElement<any, any> | null;
44
44
 
45
- export { type TransProps as T, type TransRenderProps as a, type TransRenderCallbackOrComponent as b, TransNoContext as c };
45
+ type I18nContext = {
46
+ i18n: I18n;
47
+ _: I18n["_"];
48
+ defaultComponent?: ComponentType<TransRenderProps>;
49
+ };
50
+ type I18nProviderProps = Omit<I18nContext, "_"> & {
51
+ children?: React.ReactNode;
52
+ };
53
+ declare const LinguiContext: React.Context<I18nContext | null>;
54
+ declare function useLingui(): I18nContext;
55
+ declare const I18nProvider: FunctionComponent<I18nProviderProps>;
56
+
57
+ export { I18nProvider as I, LinguiContext as L, type TransProps as T, type I18nProviderProps as a, type I18nContext as b, type TransRenderProps as c, type TransRenderCallbackOrComponent as d, TransNoContext as e, useLingui as u };
@@ -1,4 +1,4 @@
1
- import React, { ComponentType } from 'react';
1
+ import React, { ComponentType, FunctionComponent } from 'react';
2
2
  import { MessageOptions, I18n } from '@lingui/core';
3
3
 
4
4
  type TransRenderProps = {
@@ -42,4 +42,16 @@ declare function TransNoContext(props: TransProps & {
42
42
  };
43
43
  }): React.ReactElement<any, any> | null;
44
44
 
45
- export { type TransProps as T, type TransRenderProps as a, type TransRenderCallbackOrComponent as b, TransNoContext as c };
45
+ type I18nContext = {
46
+ i18n: I18n;
47
+ _: I18n["_"];
48
+ defaultComponent?: ComponentType<TransRenderProps>;
49
+ };
50
+ type I18nProviderProps = Omit<I18nContext, "_"> & {
51
+ children?: React.ReactNode;
52
+ };
53
+ declare const LinguiContext: React.Context<I18nContext | null>;
54
+ declare function useLingui(): I18nContext;
55
+ declare const I18nProvider: FunctionComponent<I18nProviderProps>;
56
+
57
+ export { I18nProvider as I, LinguiContext as L, type TransProps as T, type I18nProviderProps as a, type I18nContext as b, type TransRenderProps as c, type TransRenderCallbackOrComponent as d, TransNoContext as e, useLingui as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/react",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "sideEffects": false,
5
5
  "description": "React components for translations",
6
6
  "main": "./dist/index.cjs",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@babel/runtime": "^7.20.13",
78
- "@lingui/core": "4.10.0"
78
+ "@lingui/core": "4.11.0"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@lingui/jest-mocks": "*",
@@ -87,5 +87,5 @@
87
87
  "react-dom": "^18.2.0",
88
88
  "unbuild": "2.0.0"
89
89
  },
90
- "gitHead": "5088feb92de2a669659e85067c2849331122e830"
90
+ "gitHead": "8668ba8ef405d99d496949ff9681247deb97063d"
91
91
  }
@@ -1,17 +0,0 @@
1
- import React, { ComponentType, FunctionComponent } from 'react';
2
- import { I18n } from '@lingui/core';
3
- import { a as TransRenderProps } from './react.a673be03.mjs';
4
-
5
- type I18nContext = {
6
- i18n: I18n;
7
- _: I18n["_"];
8
- defaultComponent?: ComponentType<TransRenderProps>;
9
- };
10
- type I18nProviderProps = Omit<I18nContext, "_"> & {
11
- children?: React.ReactNode;
12
- };
13
- declare const LinguiContext: React.Context<I18nContext | null>;
14
- declare function useLingui(): I18nContext;
15
- declare const I18nProvider: FunctionComponent<I18nProviderProps>;
16
-
17
- export { I18nProvider as I, LinguiContext as L, type I18nProviderProps as a, type I18nContext as b, useLingui as u };
@@ -1,17 +0,0 @@
1
- import React, { ComponentType, FunctionComponent } from 'react';
2
- import { I18n } from '@lingui/core';
3
- import { a as TransRenderProps } from './react.a673be03.js';
4
-
5
- type I18nContext = {
6
- i18n: I18n;
7
- _: I18n["_"];
8
- defaultComponent?: ComponentType<TransRenderProps>;
9
- };
10
- type I18nProviderProps = Omit<I18nContext, "_"> & {
11
- children?: React.ReactNode;
12
- };
13
- declare const LinguiContext: React.Context<I18nContext | null>;
14
- declare function useLingui(): I18nContext;
15
- declare const I18nProvider: FunctionComponent<I18nProviderProps>;
16
-
17
- export { I18nProvider as I, LinguiContext as L, type I18nProviderProps as a, type I18nContext as b, useLingui as u };
@@ -1,17 +0,0 @@
1
- import React, { ComponentType, FunctionComponent } from 'react';
2
- import { I18n } from '@lingui/core';
3
- import { a as TransRenderProps } from './react.a673be03.cjs';
4
-
5
- type I18nContext = {
6
- i18n: I18n;
7
- _: I18n["_"];
8
- defaultComponent?: ComponentType<TransRenderProps>;
9
- };
10
- type I18nProviderProps = Omit<I18nContext, "_"> & {
11
- children?: React.ReactNode;
12
- };
13
- declare const LinguiContext: React.Context<I18nContext | null>;
14
- declare function useLingui(): I18nContext;
15
- declare const I18nProvider: FunctionComponent<I18nProviderProps>;
16
-
17
- export { I18nProvider as I, LinguiContext as L, type I18nProviderProps as a, type I18nContext as b, useLingui as u };