PluginProbe
Gutenberg / 19.6.0
Gutenberg v19.6.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / react-i18n / index.js

index.js in Gutenberg 19.6.0, at build/react-i18n/index.js

168 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ (() => {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = (exports, definition) => {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ (() => {
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22 /******/ })();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ (() => {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = (exports) => {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ })();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 I18nProvider: () => (/* binding */ I18nProvider),
43 useI18n: () => (/* binding */ useI18n),
44 withI18n: () => (/* binding */ withI18n)
45 });
46
47 ;// external ["wp","element"]
48 const external_wp_element_namespaceObject = window["wp"]["element"];
49 ;// external ["wp","i18n"]
50 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
51 ;// external "ReactJSXRuntime"
52 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
53 ;// ./packages/react-i18n/build-module/index.js
54 /**
55 * External dependencies
56 */
57
58 /**
59 * WordPress dependencies
60 */
61
62
63
64 /**
65 * Utility to make a new context value
66 *
67 * @param i18n
68 */
69 function makeContextValue(i18n) {
70 return {
71 __: i18n.__.bind(i18n),
72 _x: i18n._x.bind(i18n),
73 _n: i18n._n.bind(i18n),
74 _nx: i18n._nx.bind(i18n),
75 isRTL: i18n.isRTL.bind(i18n),
76 hasTranslation: i18n.hasTranslation.bind(i18n)
77 };
78 }
79 const I18nContext = (0,external_wp_element_namespaceObject.createContext)(makeContextValue(external_wp_i18n_namespaceObject.defaultI18n));
80 /**
81 * The `I18nProvider` should be mounted above any localized components:
82 *
83 * @example
84 * ```js
85 * import { createI18n } from '@wordpress/i18n';
86 * import { I18nProvider } from '@wordpress/react-i18n';
87 * const i18n = createI18n();
88 *
89 * ReactDom.render(
90 * <I18nProvider i18n={ i18n }>
91 * <App />
92 * </I18nProvider>,
93 * el
94 * );
95 * ```
96 *
97 * You can also instantiate the provider without the `i18n` prop. In that case it will use the
98 * default `I18n` instance exported from `@wordpress/i18n`.
99 *
100 * @param props i18n provider props.
101 * @return Children wrapped in the I18nProvider.
102 */
103 function I18nProvider(props) {
104 const {
105 children,
106 i18n = external_wp_i18n_namespaceObject.defaultI18n
107 } = props;
108 const [update, forceUpdate] = (0,external_wp_element_namespaceObject.useReducer)(() => [], []);
109
110 // Rerender translations whenever the i18n instance fires a change event.
111 (0,external_wp_element_namespaceObject.useEffect)(() => i18n.subscribe(forceUpdate), [i18n]);
112 const value = (0,external_wp_element_namespaceObject.useMemo)(() => makeContextValue(i18n), [i18n, update]);
113 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(I18nContext.Provider, {
114 value: value,
115 children: children
116 });
117 }
118
119 /**
120 * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,
121 * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).
122 * Refer to their documentation there.
123 *
124 * @example
125 * ```js
126 * import { useI18n } from '@wordpress/react-i18n';
127 *
128 * function MyComponent() {
129 * const { __ } = useI18n();
130 * return __( 'Hello, world!' );
131 * }
132 * ```
133 */
134 const useI18n = () => (0,external_wp_element_namespaceObject.useContext)(I18nContext);
135 /**
136 * React higher-order component that passes the i18n translate functions (the same set
137 * as exposed by the `useI18n` hook) to the wrapped component as props.
138 *
139 * @example
140 * ```js
141 * import { withI18n } from '@wordpress/react-i18n';
142 *
143 * function MyComponent( { __ } ) {
144 * return __( 'Hello, world!' );
145 * }
146 *
147 * export default withI18n( MyComponent );
148 * ```
149 *
150 * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`
151 * @return The wrapped component
152 */
153 function withI18n(InnerComponent) {
154 const EnhancedComponent = props => {
155 const i18nProps = useI18n();
156 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InnerComponent, {
157 ...props,
158 ...i18nProps
159 });
160 };
161 const innerComponentName = InnerComponent.displayName || InnerComponent.name || 'Component';
162 EnhancedComponent.displayName = `WithI18n(${innerComponentName})`;
163 return EnhancedComponent;
164 }
165
166 (window.wp = window.wp || {}).reactI18n = __webpack_exports__;
167 /******/ })()
168 ;