PluginProbe
Gutenberg / 12.6.0
Gutenberg v12.6.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 7.4.0 All 402 releases
gutenberg / build / react-i18n / index.js

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

186 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ !function() {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = function(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 /******/ !function() {
21 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
22 /******/ }();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ !function() {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = function(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": function() { return /* binding */ I18nProvider; },
43 "useI18n": function() { return /* binding */ useI18n; },
44 "withI18n": function() { return /* binding */ withI18n; }
45 });
46
47 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
48 function _extends() {
49 _extends = Object.assign || function (target) {
50 for (var i = 1; i < arguments.length; i++) {
51 var source = arguments[i];
52
53 for (var key in source) {
54 if (Object.prototype.hasOwnProperty.call(source, key)) {
55 target[key] = source[key];
56 }
57 }
58 }
59
60 return target;
61 };
62
63 return _extends.apply(this, arguments);
64 }
65 ;// CONCATENATED MODULE: external ["wp","element"]
66 var external_wp_element_namespaceObject = window["wp"]["element"];
67 ;// CONCATENATED MODULE: external ["wp","i18n"]
68 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
69 ;// CONCATENATED MODULE: ./packages/react-i18n/build-module/index.js
70
71
72
73 /**
74 * External dependencies
75 */
76
77 /**
78 * WordPress dependencies
79 */
80
81
82
83 /**
84 * Utility to make a new context value
85 *
86 * @param i18n
87 */
88 function makeContextValue(i18n) {
89 return {
90 __: i18n.__.bind(i18n),
91 _x: i18n._x.bind(i18n),
92 _n: i18n._n.bind(i18n),
93 _nx: i18n._nx.bind(i18n),
94 isRTL: i18n.isRTL.bind(i18n),
95 hasTranslation: i18n.hasTranslation.bind(i18n)
96 };
97 }
98
99 const I18nContext = (0,external_wp_element_namespaceObject.createContext)(makeContextValue(external_wp_i18n_namespaceObject.defaultI18n));
100
101 /**
102 * The `I18nProvider` should be mounted above any localized components:
103 *
104 * @example
105 * ```js
106 * import { createI18n } from '@wordpress/react-i18n';
107 * import { I18nProvider } from '@wordpress/react-i18n';
108 * const i18n = createI18n();
109 *
110 * ReactDom.render(
111 * <I18nProvider i18n={ i18n }>
112 * <App />
113 * </I18nProvider>,
114 * el
115 * );
116 * ```
117 *
118 * You can also instantiate the provider without the `i18n` prop. In that case it will use the
119 * default `I18n` instance exported from `@wordpress/i18n`.
120 *
121 * @param props i18n provider props.
122 * @return Children wrapped in the I18nProvider.
123 */
124 function I18nProvider(props) {
125 const {
126 children,
127 i18n = external_wp_i18n_namespaceObject.defaultI18n
128 } = props;
129 const [update, forceUpdate] = (0,external_wp_element_namespaceObject.useReducer)(() => [], []); // rerender translations whenever the i18n instance fires a change event
130
131 (0,external_wp_element_namespaceObject.useEffect)(() => i18n.subscribe(forceUpdate), [i18n]);
132 const value = (0,external_wp_element_namespaceObject.useMemo)(() => makeContextValue(i18n), [i18n, update]);
133 return (0,external_wp_element_namespaceObject.createElement)(I18nContext.Provider, {
134 value: value
135 }, children);
136 }
137 /**
138 * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,
139 * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).
140 * Refer to their documentation there.
141 *
142 * @example
143 * ```js
144 * import { useI18n } from '@wordpress/react-i18n';
145 *
146 * function MyComponent() {
147 * const { __ } = useI18n();
148 * return __( 'Hello, world!' );
149 * }
150 * ```
151 */
152
153 const useI18n = () => (0,external_wp_element_namespaceObject.useContext)(I18nContext);
154
155 /**
156 * React higher-order component that passes the i18n translate functions (the same set
157 * as exposed by the `useI18n` hook) to the wrapped component as props.
158 *
159 * @example
160 * ```js
161 * import { withI18n } from '@wordpress/react-i18n';
162 *
163 * function MyComponent( { __ } ) {
164 * return __( 'Hello, world!' );
165 * }
166 *
167 * export default withI18n( MyComponent );
168 * ```
169 *
170 * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`
171 * @return The wrapped component
172 */
173 function withI18n(InnerComponent) {
174 const EnhancedComponent = props => {
175 const i18nProps = useI18n();
176 return (0,external_wp_element_namespaceObject.createElement)(InnerComponent, _extends({}, props, i18nProps));
177 };
178
179 const innerComponentName = InnerComponent.displayName || InnerComponent.name || 'Component';
180 EnhancedComponent.displayName = `WithI18n(${innerComponentName})`;
181 return EnhancedComponent;
182 }
183 //# sourceMappingURL=index.js.map
184 (window.wp = window.wp || {}).reactI18n = __webpack_exports__;
185 /******/ })()
186 ;