@lingui/react 6.0.0-next.1 → 6.0.0-next.3

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/dist/index.mjs CHANGED
@@ -23,19 +23,19 @@ const I18nProvider = ({
23
23
  defaultComponent,
24
24
  children
25
25
  }) => {
26
- const latestKnownLocale = useRef(i18n.locale);
26
+ const latestKnownLocale = useRef(i18n.locale || null);
27
27
  const makeContext = useCallback(
28
28
  () => ({
29
- i18n,
29
+ i18n: new Proxy(i18n, {}),
30
30
  defaultComponent,
31
31
  _: i18n.t.bind(i18n)
32
32
  }),
33
33
  [i18n, defaultComponent]
34
34
  );
35
- const [context, setContext] = useState(makeContext());
35
+ const [context, setContext] = useState(makeContext);
36
36
  useEffect(() => {
37
37
  const updateContext = () => {
38
- latestKnownLocale.current = i18n.locale;
38
+ latestKnownLocale.current = i18n.locale || null;
39
39
  setContext(makeContext());
40
40
  };
41
41
  const unsubscribe = i18n.on("change", updateContext);
@@ -44,7 +44,7 @@ const I18nProvider = ({
44
44
  }
45
45
  return unsubscribe;
46
46
  }, [i18n, makeContext]);
47
- if (!latestKnownLocale.current) {
47
+ if (latestKnownLocale.current === null) {
48
48
  process.env.NODE_ENV === "development" && console.log(
49
49
  "I18nProvider rendered `null`. A call to `i18n.activate` needs to happen in order for translations to be activated and for the I18nProvider to render.This is not an error but an informational message logged only in development."
50
50
  );
@@ -6,5 +6,6 @@ export const useLingui = function () {}
6
6
 
7
7
  throw new Error(
8
8
  `The macro you imported from "@lingui/react/macro" is being executed outside the context of compilation. \n` +
9
- `This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro"`,
9
+ `This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro" \n` +
10
+ "Additionally, dynamic imports — e.g., `await import('@lingui/react/macro')` — are not supported.",
10
11
  )
@@ -135,4 +135,4 @@ export function useLingui(): Omit<I18nContext, "_"> & {
135
135
  (descriptor: MacroMessageDescriptor): string
136
136
  (literals: TemplateStringsArray, ...placeholders: any[]): string
137
137
  }
138
- }
138
+ }
@@ -0,0 +1,23 @@
1
+ import babelPluginMacros from "babel-plugin-macros"
2
+ import { macro } from "@lingui/babel-plugin-lingui-macro/macro"
3
+
4
+ const { createMacro } = babelPluginMacros
5
+
6
+ export default createMacro(macro, {
7
+ configName: "lingui",
8
+ })
9
+
10
+ // the following shims for the case when this import used by nodejs code without transpilation
11
+ function printError() {
12
+ throw new Error(
13
+ `The macro you imported from "@lingui/react/macro" is being executed outside the context of compilation. \n` +
14
+ `This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro" \n` +
15
+ "Additionally, dynamic imports — e.g., `await import('@lingui/react/macro')` — are not supported.",
16
+ )
17
+ }
18
+
19
+ export const Trans = printError
20
+ export const Plural = printError
21
+ export const Select = printError
22
+ export const SelectOrdinal = printError
23
+ export const useLingui = printError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/react",
3
- "version": "6.0.0-next.1",
3
+ "version": "6.0.0-next.3",
4
4
  "sideEffects": false,
5
5
  "description": "React components for translations",
6
6
  "type": "module",
@@ -47,9 +47,9 @@
47
47
  },
48
48
  "./server": "./dist/server.mjs",
49
49
  "./macro": {
50
- "browser": "./macro/browser.cjs",
51
- "types": "./macro/index.d.cts",
52
- "default": "./macro/index.cjs"
50
+ "browser": "./macro/browser.mjs",
51
+ "types": "./macro/index.d.mts",
52
+ "default": "./macro/index.mjs"
53
53
  },
54
54
  "./package.json": "./package.json"
55
55
  },
@@ -57,9 +57,9 @@
57
57
  "LICENSE",
58
58
  "README.md",
59
59
  "dist/",
60
- "macro/browser.cjs",
61
- "macro/index.d.cts",
62
- "macro/index.cjs"
60
+ "macro/browser.mjs",
61
+ "macro/index.d.mts",
62
+ "macro/index.mjs"
63
63
  ],
64
64
  "peerDependencies": {
65
65
  "babel-plugin-macros": "2 || 3",
@@ -71,20 +71,21 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@lingui/babel-plugin-lingui-macro": "6.0.0-next.1",
75
- "@lingui/core": "6.0.0-next.1"
74
+ "@lingui/babel-plugin-lingui-macro": "6.0.0-next.3",
75
+ "@lingui/core": "6.0.0-next.3"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@lingui/test-utils": "3.0.3",
79
79
  "@testing-library/react": "^14.0.0",
80
80
  "@types/react": "^18.2.13",
81
- "eslint-plugin-react": "^7.32.2",
82
- "eslint-plugin-react-hooks": "^4.6.0",
81
+ "eslint": "^9.39.3",
82
+ "eslint-plugin-react": "^7.37.5",
83
+ "eslint-plugin-react-hooks": "^7.0.1",
83
84
  "happy-dom": "^20.0.10",
84
85
  "react": "^18.2.0",
85
86
  "react-dom": "^18.2.0",
86
87
  "unbuild": "3.6.1",
87
88
  "vitest": "4.0.18"
88
89
  },
89
- "gitHead": "783af0c0371c7795e1fc43316f49dd253e161221"
90
+ "gitHead": "ebcb6dc8e8d327ae5775cadee931942ef309480f"
90
91
  }
package/macro/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- const { createMacro } = require("babel-plugin-macros")
2
- const { macro } = require("@lingui/babel-plugin-lingui-macro/macro")
3
-
4
- module.exports = createMacro(macro, {
5
- configName: "lingui",
6
- })