@lingui/react 4.11.4 → 5.0.0-next.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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const server = require('./server.cjs');
4
- const TransNoContext = require('./shared/react.fdbc1485.cjs');
4
+ const TransNoContext = require('./shared/react.3eab4fb8.cjs');
5
5
  const React = require('react');
6
6
 
7
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.b2b749a9.cjs';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.cjs';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.b2b749a9.mjs';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.mjs';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps, b as I18nContext } from './shared/react.b2b749a9.js';
2
+ export { d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.js';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { getI18n } from './server.mjs';
2
- import { T as TransNoContext } from './shared/react.ac956f45.mjs';
2
+ import { T as TransNoContext } from './shared/react.1807f7b5.mjs';
3
3
  import React from 'react';
4
4
 
5
5
  function TransRsc(props) {
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const React = require('react');
5
- const TransNoContext = require('./shared/react.fdbc1485.cjs');
5
+ const TransNoContext = require('./shared/react.3eab4fb8.cjs');
6
6
 
7
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
8
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps } from './shared/react.b2b749a9.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.b2b749a9.cjs';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps } from './shared/react.b2b749a9.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.b2b749a9.mjs';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { T as TransProps } from './shared/react.b2b749a9.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.b2b749a9.js';
3
3
  import React from 'react';
4
4
  import '@lingui/core';
5
5
 
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import React from 'react';
3
- import { T as TransNoContext } from './shared/react.ac956f45.mjs';
3
+ import { T as TransNoContext } from './shared/react.1807f7b5.mjs';
4
4
 
5
5
  const LinguiContext = React.createContext(null);
6
6
  const useLinguiInternal = (devErrorMessage) => {
package/dist/server.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const TransNoContext = require('./shared/react.fdbc1485.cjs');
3
+ const TransNoContext = require('./shared/react.3eab4fb8.cjs');
4
4
  const React = require('react');
5
5
 
6
6
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { b as I18nContext } from './shared/react.b2b749a9.cjs';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.cjs';
3
3
  import { I18n } from '@lingui/core';
4
4
  import 'react';
5
5
 
package/dist/server.d.mts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { b as I18nContext } from './shared/react.b2b749a9.mjs';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.mjs';
3
3
  import { I18n } from '@lingui/core';
4
4
  import 'react';
5
5
 
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { b as I18nContext } from './shared/react.b2b749a9.js';
2
+ export { e as TransNoContext, T as TransProps, d as TransRenderCallbackOrComponent, c as TransRenderProps } from './shared/react.b2b749a9.js';
3
3
  import { I18n } from '@lingui/core';
4
4
  import 'react';
5
5
 
package/dist/server.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { T as TransNoContext } from './shared/react.ac956f45.mjs';
1
+ export { T as TransNoContext } from './shared/react.1807f7b5.mjs';
2
2
  import React from 'react';
3
3
 
4
4
  let cache = null;
@@ -82,12 +82,11 @@ function TransNoContext(props) {
82
82
  const components = { ...props.components };
83
83
  if (values) {
84
84
  Object.keys(values).forEach((key) => {
85
- const value = values[key];
86
- const valueIsReactEl = React.isValidElement(value) || Array.isArray(value) && value.every(React.isValidElement);
87
- if (!valueIsReactEl)
88
- return;
89
85
  const index = Object.keys(components).length;
90
- components[index] = value;
86
+ if (typeof values[key] === "string" || typeof values[key] === "number") {
87
+ return;
88
+ }
89
+ components[index] = /* @__PURE__ */ React.createElement(React.Fragment, null, values[key]);
91
90
  values[key] = `<${index}/>`;
92
91
  });
93
92
  }
@@ -101,8 +100,6 @@ function TransNoContext(props) {
101
100
  id,
102
101
  message,
103
102
  translation,
104
- // TODO vonovak - remove isTranslated prop in v5 release
105
- isTranslated: id !== translation && message !== translation,
106
103
  children: translation
107
104
  // for type-compatibility with `component` prop
108
105
  };
@@ -88,12 +88,11 @@ function TransNoContext(props) {
88
88
  const components = { ...props.components };
89
89
  if (values) {
90
90
  Object.keys(values).forEach((key) => {
91
- const value = values[key];
92
- const valueIsReactEl = React__default.isValidElement(value) || Array.isArray(value) && value.every(React__default.isValidElement);
93
- if (!valueIsReactEl)
94
- return;
95
91
  const index = Object.keys(components).length;
96
- components[index] = value;
92
+ if (typeof values[key] === "string" || typeof values[key] === "number") {
93
+ return;
94
+ }
95
+ components[index] = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, values[key]);
97
96
  values[key] = `<${index}/>`;
98
97
  });
99
98
  }
@@ -107,8 +106,6 @@ function TransNoContext(props) {
107
106
  id,
108
107
  message,
109
108
  translation,
110
- // TODO vonovak - remove isTranslated prop in v5 release
111
- isTranslated: id !== translation && message !== translation,
112
109
  children: translation
113
110
  // for type-compatibility with `component` prop
114
111
  };
@@ -6,10 +6,6 @@ type TransRenderProps = {
6
6
  translation: React.ReactNode;
7
7
  children: React.ReactNode;
8
8
  message?: string | null;
9
- /**
10
- * @deprecated isTranslated prop is undocumented and buggy. It'll be removed in v5 release.
11
- * */
12
- isTranslated: boolean;
13
9
  };
14
10
  type TransRenderCallbackOrComponent = {
15
11
  component?: undefined;
@@ -6,10 +6,6 @@ type TransRenderProps = {
6
6
  translation: React.ReactNode;
7
7
  children: React.ReactNode;
8
8
  message?: string | null;
9
- /**
10
- * @deprecated isTranslated prop is undocumented and buggy. It'll be removed in v5 release.
11
- * */
12
- isTranslated: boolean;
13
9
  };
14
10
  type TransRenderCallbackOrComponent = {
15
11
  component?: undefined;
@@ -6,10 +6,6 @@ type TransRenderProps = {
6
6
  translation: React.ReactNode;
7
7
  children: React.ReactNode;
8
8
  message?: string | null;
9
- /**
10
- * @deprecated isTranslated prop is undocumented and buggy. It'll be removed in v5 release.
11
- * */
12
- isTranslated: boolean;
13
9
  };
14
10
  type TransRenderCallbackOrComponent = {
15
11
  component?: undefined;
@@ -0,0 +1,137 @@
1
+ import type { ReactNode, VFC, FC } from "react"
2
+ import type { TransRenderCallbackOrComponent, I18nContext } from "@lingui/react"
3
+ import type { MacroMessageDescriptor } from "@lingui/core/macro"
4
+
5
+ type CommonProps = TransRenderCallbackOrComponent & {
6
+ id?: string
7
+ comment?: string
8
+ context?: string
9
+ }
10
+
11
+ type TransProps = {
12
+ children: ReactNode
13
+ } & CommonProps
14
+
15
+ type PluralChoiceProps = {
16
+ value: string | number
17
+ /** Offset of value when calculating plural forms */
18
+ offset?: number
19
+ zero?: ReactNode
20
+ one?: ReactNode
21
+ two?: ReactNode
22
+ few?: ReactNode
23
+ many?: ReactNode
24
+
25
+ /** Catch-all option */
26
+ other: ReactNode
27
+ /** Exact match form, corresponds to =N rule */
28
+ [digit: `_${number}`]: ReactNode
29
+ } & CommonProps
30
+
31
+ type SelectChoiceProps = {
32
+ value: string
33
+ /** Catch-all option */
34
+ other: ReactNode
35
+ [option: `_${string}`]: ReactNode
36
+ } & CommonProps
37
+
38
+ /**
39
+ * Trans is the basic macro for static messages,
40
+ * messages with variables, but also for messages with inline markup
41
+ *
42
+ * @example
43
+ * ```
44
+ * <Trans>Hello {username}. Read the <a href="/docs">docs</a>.</Trans>
45
+ * ```
46
+ * @example
47
+ * ```
48
+ * <Trans id="custom.id">Hello {username}.</Trans>
49
+ * ```
50
+ */
51
+ export const Trans: FC<TransProps>
52
+
53
+ /**
54
+ * Props of Plural macro are transformed into plural format.
55
+ *
56
+ * @example
57
+ * ```
58
+ * import { Plural } from "@lingui/core/macro"
59
+ * <Plural value={numBooks} one="Book" other="Books" />
60
+ *
61
+ * // ↓ ↓ ↓ ↓ ↓ ↓
62
+ * import { Trans } from "@lingui/react"
63
+ * <Trans id="{numBooks, plural, one {Book} other {Books}}" values={{ numBooks }} />
64
+ * ```
65
+ */
66
+ export const Plural: VFC<PluralChoiceProps>
67
+ /**
68
+ * Props of SelectOrdinal macro are transformed into selectOrdinal format.
69
+ *
70
+ * @example
71
+ * ```
72
+ * // count == 1 -> 1st
73
+ * // count == 2 -> 2nd
74
+ * // count == 3 -> 3rd
75
+ * // count == 4 -> 4th
76
+ * <SelectOrdinal
77
+ * value={count}
78
+ * one="#st"
79
+ * two="#nd"
80
+ * few="#rd"
81
+ * other="#th"
82
+ * />
83
+ * ```
84
+ */
85
+ export const SelectOrdinal: VFC<PluralChoiceProps>
86
+
87
+ /**
88
+ * Props of Select macro are transformed into select format
89
+ *
90
+ * @example
91
+ * ```
92
+ * // gender == "female" -> Her book
93
+ * // gender == "male" -> His book
94
+ * // gender == "non-binary" -> Their book
95
+ *
96
+ * <Select
97
+ * value={gender}
98
+ * _male="His book"
99
+ * _female="Her book"
100
+ * other="Their book"
101
+ * />
102
+ * ```
103
+ */
104
+ export const Select: VFC<SelectChoiceProps>
105
+
106
+ declare function _t(descriptor: MacroMessageDescriptor): string
107
+ declare function _t(
108
+ literals: TemplateStringsArray,
109
+ ...placeholders: any[]
110
+ ): string
111
+
112
+ /**
113
+ *
114
+ * Macro version of useLingui replaces _ function with `t` macro function which is bound to i18n passed from React.Context
115
+ *
116
+ * Returned `t` macro function has all the same signatures as global `t`
117
+ *
118
+ * @example
119
+ * ```
120
+ * const { t } = useLingui();
121
+ * const message = t`Text`;
122
+ * ```
123
+ *
124
+ * @example
125
+ * ```
126
+ * const { i18n, t } = useLingui();
127
+ * const locale = i18n.locale;
128
+ * const message = t({
129
+ * id: "msg.hello",
130
+ * comment: "Greetings at the homepage",
131
+ * message: `Hello ${name}`,
132
+ * });
133
+ * ```
134
+ */
135
+ export function useLingui(): Omit<I18nContext, "_"> & {
136
+ t: typeof _t
137
+ }
package/macro/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("@lingui/babel-plugin-lingui-macro/macro")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/react",
3
- "version": "4.11.4",
3
+ "version": "5.0.0-next.1",
4
4
  "sideEffects": false,
5
5
  "description": "React components for translations",
6
6
  "main": "./dist/index.cjs",
@@ -63,29 +63,46 @@
63
63
  "default": "./dist/server.mjs"
64
64
  }
65
65
  },
66
+ "./macro": {
67
+ "types": "./macro/index.d.ts",
68
+ "default": "./macro/index.js"
69
+ },
66
70
  "./package.json": "./package.json"
67
71
  },
68
72
  "files": [
69
73
  "LICENSE",
70
74
  "README.md",
71
- "dist/"
75
+ "dist/",
76
+ "macro/index.d.ts",
77
+ "macro/index.js"
72
78
  ],
73
79
  "peerDependencies": {
80
+ "@lingui/babel-plugin-lingui-macro": "5.0.0-next.1",
81
+ "babel-plugin-macros": "2 || 3",
74
82
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
75
83
  },
84
+ "peerDependenciesMeta": {
85
+ "@lingui/babel-plugin-lingui-macro": {
86
+ "optional": true
87
+ },
88
+ "babel-plugin-macros": {
89
+ "optional": true
90
+ }
91
+ },
76
92
  "dependencies": {
77
93
  "@babel/runtime": "^7.20.13",
78
- "@lingui/core": "4.11.4"
94
+ "@lingui/core": "^5.0.0-next.1"
79
95
  },
80
96
  "devDependencies": {
81
- "@lingui/jest-mocks": "*",
97
+ "@lingui/jest-mocks": "^3.0.3",
82
98
  "@testing-library/react": "^14.0.0",
83
99
  "@types/react": "^18.2.13",
84
100
  "eslint-plugin-react": "^7.32.2",
85
101
  "eslint-plugin-react-hooks": "^4.6.0",
86
102
  "react": "^18.2.0",
87
103
  "react-dom": "^18.2.0",
104
+ "tsd": "^0.26.1",
88
105
  "unbuild": "2.0.0"
89
106
  },
90
- "gitHead": "43d4e671360e8e5f1b820e4e061c1926d95c120b"
107
+ "gitHead": "7936155f7b29ecdc6191042a9a2e363962ab482d"
91
108
  }