@wordpress/react-i18n 4.33.1 → 4.34.1-next.2f1c7c01b.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.34.0 (2025-10-29)
6
+
5
7
  ## 4.33.0 (2025-10-17)
6
8
 
7
9
  ## 4.32.0 (2025-10-01)
package/build/index.js CHANGED
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/react-i18n/src/index.tsx
19
21
  var index_exports = {};
20
22
  __export(index_exports, {
21
23
  I18nProvider: () => I18nProvider,
@@ -23,9 +25,9 @@ __export(index_exports, {
23
25
  withI18n: () => withI18n
24
26
  });
25
27
  module.exports = __toCommonJS(index_exports);
26
- var import_jsx_runtime = require("react/jsx-runtime");
27
28
  var import_element = require("@wordpress/element");
28
29
  var import_i18n = require("@wordpress/i18n");
30
+ var import_jsx_runtime = require("react/jsx-runtime");
29
31
  function makeContextValue(i18n) {
30
32
  return {
31
33
  __: i18n.__.bind(i18n),
@@ -36,7 +38,7 @@ function makeContextValue(i18n) {
36
38
  hasTranslation: i18n.hasTranslation.bind(i18n)
37
39
  };
38
40
  }
39
- const I18nContext = (0, import_element.createContext)(makeContextValue(import_i18n.defaultI18n));
41
+ var I18nContext = (0, import_element.createContext)(makeContextValue(import_i18n.defaultI18n));
40
42
  I18nContext.displayName = "I18nContext";
41
43
  function I18nProvider(props) {
42
44
  const { children, i18n = import_i18n.defaultI18n } = props;
@@ -45,7 +47,7 @@ function I18nProvider(props) {
45
47
  const value = (0, import_element.useMemo)(() => makeContextValue(i18n), [i18n, update]);
46
48
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(I18nContext.Provider, { value, children });
47
49
  }
48
- const useI18n = () => (0, import_element.useContext)(I18nContext);
50
+ var useI18n = () => (0, import_element.useContext)(I18nContext);
49
51
  function withI18n(InnerComponent) {
50
52
  const EnhancedComponent = (props) => {
51
53
  const i18nProps = useI18n();
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.tsx"],
4
4
  "sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\nI18nContext.displayName = 'I18nContext';\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqFE;AAxEF,qBAMO;AACP,kBAA4B;AAgB5B,SAAS,iBAAkB,MAA+B;AACzD,SAAO;AAAA,IACN,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,KAAK,KAAK,IAAI,KAAM,IAAK;AAAA,IACzB,OAAO,KAAK,MAAM,KAAM,IAAK;AAAA,IAC7B,gBAAgB,KAAK,eAAe,KAAM,IAAK;AAAA,EAChD;AACD;AAEA,MAAM,kBAAc,8BAAe,iBAAkB,uBAAY,CAAE;AACnE,YAAY,cAAc;AA2BnB,SAAS,aAAc,OAAwC;AACrE,QAAM,EAAE,UAAU,OAAO,wBAAY,IAAI;AACzC,QAAM,CAAE,QAAQ,WAAY,QAAI,2BAAY,MAAM,CAAC,GAAG,CAAC,CAAE;AAGzD,gCAAW,MAAM,KAAK,UAAW,WAAY,GAAG,CAAE,IAAK,CAAE;AAEzD,QAAM,YAAQ,wBAAS,MAAM,iBAAkB,IAAK,GAAG,CAAE,MAAM,MAAO,CAAE;AAExE,SACC,4CAAC,YAAY,UAAZ,EAAqB,OACnB,UACH;AAEF;AAiBO,MAAM,UAAU,UAAM,2BAAY,WAAY;AAyB9C,SAAS,SACf,gBACyC;AACzC,QAAM,oBAEF,CAAE,UAAW;AAChB,UAAM,YAAY,QAAQ;AAC1B,WAAO,4CAAC,kBAAiB,GAAK,OAAiB,GAAG,WAAY;AAAA,EAC/D;AACA,QAAM,qBACL,eAAe,eAAe,eAAe,QAAQ;AACtD,oBAAkB,c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/react-i18n/src/index.tsx
2
2
  import {
3
3
  createContext,
4
4
  useContext,
@@ -7,6 +7,7 @@ import {
7
7
  useReducer
8
8
  } from "@wordpress/element";
9
9
  import { defaultI18n } from "@wordpress/i18n";
10
+ import { jsx } from "react/jsx-runtime";
10
11
  function makeContextValue(i18n) {
11
12
  return {
12
13
  __: i18n.__.bind(i18n),
@@ -17,7 +18,7 @@ function makeContextValue(i18n) {
17
18
  hasTranslation: i18n.hasTranslation.bind(i18n)
18
19
  };
19
20
  }
20
- const I18nContext = createContext(makeContextValue(defaultI18n));
21
+ var I18nContext = createContext(makeContextValue(defaultI18n));
21
22
  I18nContext.displayName = "I18nContext";
22
23
  function I18nProvider(props) {
23
24
  const { children, i18n = defaultI18n } = props;
@@ -26,7 +27,7 @@ function I18nProvider(props) {
26
27
  const value = useMemo(() => makeContextValue(i18n), [i18n, update]);
27
28
  return /* @__PURE__ */ jsx(I18nContext.Provider, { value, children });
28
29
  }
29
- const useI18n = () => useContext(I18nContext);
30
+ var useI18n = () => useContext(I18nContext);
30
31
  function withI18n(InnerComponent) {
31
32
  const EnhancedComponent = (props) => {
32
33
  const i18nProps = useI18n();
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.tsx"],
4
4
  "sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\nI18nContext.displayName = 'I18nContext';\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"],
5
- "mappings": "AAqFE;AAxEF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAgB5B,SAAS,iBAAkB,MAA+B;AACzD,SAAO;AAAA,IACN,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,IAAI,KAAK,GAAG,KAAM,IAAK;AAAA,IACvB,KAAK,KAAK,IAAI,KAAM,IAAK;AAAA,IACzB,OAAO,KAAK,MAAM,KAAM,IAAK;AAAA,IAC7B,gBAAgB,KAAK,eAAe,KAAM,IAAK;AAAA,EAChD;AACD;AAEA,MAAM,cAAc,cAAe,iBAAkB,WAAY,CAAE;AACnE,YAAY,cAAc;AA2BnB,SAA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,CAAE;AAGzD,YAAW,MAAM,KAAK,UAAW,WAAY,GAAG,CAAE,IAAK,CAAE;AAEzD,QAAM,QAAQ,QAAS,MAAM,iBAAkB,IAAK,GAAG,CAAE,MAAM,MAAO,CAAE;AAExE,SACC,oBAAC,YAAY,UAAZ,EAAqB,OACnB,UACH;AAEF;AAiBO,IAAM,UAAU,MAAM,WAAY,WAAY;AAyB9C,SAAS,SACf,gBACyC;AACzC,QAAM,oBAEF,CAAE,UAAW;AAChB,UAAM,YAAY,QAAQ;AAC1B,WAAO,oBAAC,kBAAiB,GAAK,OAAiB,GAAG,WAAY;AAAA,EAC/D;AACA,QAAM,qBACL,eAAe,eAAe,eAAe,QAAQ;AACtD,oBAAkB,cAAc,YAAa,kBAAmB;AAChE,SAAO;AACR;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/react-i18n",
3
- "version": "4.33.1",
3
+ "version": "4.34.1-next.2f1c7c01b.0",
4
4
  "description": "React bindings for @wordpress/i18n.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -37,12 +37,12 @@
37
37
  "types": "build-types",
38
38
  "sideEffects": false,
39
39
  "dependencies": {
40
- "@wordpress/element": "^6.33.1",
41
- "@wordpress/i18n": "^6.6.1",
40
+ "@wordpress/element": "^6.34.1-next.2f1c7c01b.0",
41
+ "@wordpress/i18n": "^6.7.1-next.2f1c7c01b.0",
42
42
  "utility-types": "^3.10.0"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "5f84bafdec1bed05247c1080c12f6a237951b862"
47
+ "gitHead": "c6ddcdf455bc02567a2c9e03de6862a2061b85e8"
48
48
  }