wp/wp-includes/js/dist/i18n.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /******/ (function() { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	var __webpack_modules__ = ({
     2 /******/ 	var __webpack_modules__ = ({
     3 
     3 
     4 /***/ 9756:
     4 /***/ 2058:
     5 /***/ (function(module) {
     5 /***/ ((module, exports, __webpack_require__) => {
     6 
       
     7 /**
       
     8  * Memize options object.
       
     9  *
       
    10  * @typedef MemizeOptions
       
    11  *
       
    12  * @property {number} [maxSize] Maximum size of the cache.
       
    13  */
       
    14 
       
    15 /**
       
    16  * Internal cache entry.
       
    17  *
       
    18  * @typedef MemizeCacheNode
       
    19  *
       
    20  * @property {?MemizeCacheNode|undefined} [prev] Previous node.
       
    21  * @property {?MemizeCacheNode|undefined} [next] Next node.
       
    22  * @property {Array<*>}                   args   Function arguments for cache
       
    23  *                                               entry.
       
    24  * @property {*}                          val    Function result.
       
    25  */
       
    26 
       
    27 /**
       
    28  * Properties of the enhanced function for controlling cache.
       
    29  *
       
    30  * @typedef MemizeMemoizedFunction
       
    31  *
       
    32  * @property {()=>void} clear Clear the cache.
       
    33  */
       
    34 
       
    35 /**
       
    36  * Accepts a function to be memoized, and returns a new memoized function, with
       
    37  * optional options.
       
    38  *
       
    39  * @template {Function} F
       
    40  *
       
    41  * @param {F}             fn        Function to memoize.
       
    42  * @param {MemizeOptions} [options] Options object.
       
    43  *
       
    44  * @return {F & MemizeMemoizedFunction} Memoized function.
       
    45  */
       
    46 function memize( fn, options ) {
       
    47 	var size = 0;
       
    48 
       
    49 	/** @type {?MemizeCacheNode|undefined} */
       
    50 	var head;
       
    51 
       
    52 	/** @type {?MemizeCacheNode|undefined} */
       
    53 	var tail;
       
    54 
       
    55 	options = options || {};
       
    56 
       
    57 	function memoized( /* ...args */ ) {
       
    58 		var node = head,
       
    59 			len = arguments.length,
       
    60 			args, i;
       
    61 
       
    62 		searchCache: while ( node ) {
       
    63 			// Perform a shallow equality test to confirm that whether the node
       
    64 			// under test is a candidate for the arguments passed. Two arrays
       
    65 			// are shallowly equal if their length matches and each entry is
       
    66 			// strictly equal between the two sets. Avoid abstracting to a
       
    67 			// function which could incur an arguments leaking deoptimization.
       
    68 
       
    69 			// Check whether node arguments match arguments length
       
    70 			if ( node.args.length !== arguments.length ) {
       
    71 				node = node.next;
       
    72 				continue;
       
    73 			}
       
    74 
       
    75 			// Check whether node arguments match arguments values
       
    76 			for ( i = 0; i < len; i++ ) {
       
    77 				if ( node.args[ i ] !== arguments[ i ] ) {
       
    78 					node = node.next;
       
    79 					continue searchCache;
       
    80 				}
       
    81 			}
       
    82 
       
    83 			// At this point we can assume we've found a match
       
    84 
       
    85 			// Surface matched node to head if not already
       
    86 			if ( node !== head ) {
       
    87 				// As tail, shift to previous. Must only shift if not also
       
    88 				// head, since if both head and tail, there is no previous.
       
    89 				if ( node === tail ) {
       
    90 					tail = node.prev;
       
    91 				}
       
    92 
       
    93 				// Adjust siblings to point to each other. If node was tail,
       
    94 				// this also handles new tail's empty `next` assignment.
       
    95 				/** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
       
    96 				if ( node.next ) {
       
    97 					node.next.prev = node.prev;
       
    98 				}
       
    99 
       
   100 				node.next = head;
       
   101 				node.prev = null;
       
   102 				/** @type {MemizeCacheNode} */ ( head ).prev = node;
       
   103 				head = node;
       
   104 			}
       
   105 
       
   106 			// Return immediately
       
   107 			return node.val;
       
   108 		}
       
   109 
       
   110 		// No cached value found. Continue to insertion phase:
       
   111 
       
   112 		// Create a copy of arguments (avoid leaking deoptimization)
       
   113 		args = new Array( len );
       
   114 		for ( i = 0; i < len; i++ ) {
       
   115 			args[ i ] = arguments[ i ];
       
   116 		}
       
   117 
       
   118 		node = {
       
   119 			args: args,
       
   120 
       
   121 			// Generate the result from original function
       
   122 			val: fn.apply( null, args ),
       
   123 		};
       
   124 
       
   125 		// Don't need to check whether node is already head, since it would
       
   126 		// have been returned above already if it was
       
   127 
       
   128 		// Shift existing head down list
       
   129 		if ( head ) {
       
   130 			head.prev = node;
       
   131 			node.next = head;
       
   132 		} else {
       
   133 			// If no head, follows that there's no tail (at initial or reset)
       
   134 			tail = node;
       
   135 		}
       
   136 
       
   137 		// Trim tail if we're reached max size and are pending cache insertion
       
   138 		if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
       
   139 			tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
       
   140 			/** @type {MemizeCacheNode} */ ( tail ).next = null;
       
   141 		} else {
       
   142 			size++;
       
   143 		}
       
   144 
       
   145 		head = node;
       
   146 
       
   147 		return node.val;
       
   148 	}
       
   149 
       
   150 	memoized.clear = function() {
       
   151 		head = null;
       
   152 		tail = null;
       
   153 		size = 0;
       
   154 	};
       
   155 
       
   156 	if ( false ) {}
       
   157 
       
   158 	// Ignore reason: There's not a clear solution to create an intersection of
       
   159 	// the function with additional properties, where the goal is to retain the
       
   160 	// function signature of the incoming argument and add control properties
       
   161 	// on the return value.
       
   162 
       
   163 	// @ts-ignore
       
   164 	return memoized;
       
   165 }
       
   166 
       
   167 module.exports = memize;
       
   168 
       
   169 
       
   170 /***/ }),
       
   171 
       
   172 /***/ 124:
       
   173 /***/ (function(module, exports, __webpack_require__) {
       
   174 
     6 
   175 var __WEBPACK_AMD_DEFINE_RESULT__;/* global window, exports, define */
     7 var __WEBPACK_AMD_DEFINE_RESULT__;/* global window, exports, define */
   176 
     8 
   177 !function() {
     9 !function() {
   178     'use strict'
    10     'use strict'
   434 /******/ 		return module.exports;
   266 /******/ 		return module.exports;
   435 /******/ 	}
   267 /******/ 	}
   436 /******/ 	
   268 /******/ 	
   437 /************************************************************************/
   269 /************************************************************************/
   438 /******/ 	/* webpack/runtime/compat get default export */
   270 /******/ 	/* webpack/runtime/compat get default export */
   439 /******/ 	!function() {
   271 /******/ 	(() => {
   440 /******/ 		// getDefaultExport function for compatibility with non-harmony modules
   272 /******/ 		// getDefaultExport function for compatibility with non-harmony modules
   441 /******/ 		__webpack_require__.n = function(module) {
   273 /******/ 		__webpack_require__.n = (module) => {
   442 /******/ 			var getter = module && module.__esModule ?
   274 /******/ 			var getter = module && module.__esModule ?
   443 /******/ 				function() { return module['default']; } :
   275 /******/ 				() => (module['default']) :
   444 /******/ 				function() { return module; };
   276 /******/ 				() => (module);
   445 /******/ 			__webpack_require__.d(getter, { a: getter });
   277 /******/ 			__webpack_require__.d(getter, { a: getter });
   446 /******/ 			return getter;
   278 /******/ 			return getter;
   447 /******/ 		};
   279 /******/ 		};
   448 /******/ 	}();
   280 /******/ 	})();
   449 /******/ 	
   281 /******/ 	
   450 /******/ 	/* webpack/runtime/define property getters */
   282 /******/ 	/* webpack/runtime/define property getters */
   451 /******/ 	!function() {
   283 /******/ 	(() => {
   452 /******/ 		// define getter functions for harmony exports
   284 /******/ 		// define getter functions for harmony exports
   453 /******/ 		__webpack_require__.d = function(exports, definition) {
   285 /******/ 		__webpack_require__.d = (exports, definition) => {
   454 /******/ 			for(var key in definition) {
   286 /******/ 			for(var key in definition) {
   455 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
   287 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
   456 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
   288 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
   457 /******/ 				}
   289 /******/ 				}
   458 /******/ 			}
   290 /******/ 			}
   459 /******/ 		};
   291 /******/ 		};
   460 /******/ 	}();
   292 /******/ 	})();
   461 /******/ 	
   293 /******/ 	
   462 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
   294 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
   463 /******/ 	!function() {
   295 /******/ 	(() => {
   464 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
   296 /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
   465 /******/ 	}();
   297 /******/ 	})();
   466 /******/ 	
   298 /******/ 	
   467 /******/ 	/* webpack/runtime/make namespace object */
   299 /******/ 	/* webpack/runtime/make namespace object */
   468 /******/ 	!function() {
   300 /******/ 	(() => {
   469 /******/ 		// define __esModule on exports
   301 /******/ 		// define __esModule on exports
   470 /******/ 		__webpack_require__.r = function(exports) {
   302 /******/ 		__webpack_require__.r = (exports) => {
   471 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
   303 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
   472 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
   304 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
   473 /******/ 			}
   305 /******/ 			}
   474 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
   306 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
   475 /******/ 		};
   307 /******/ 		};
   476 /******/ 	}();
   308 /******/ 	})();
   477 /******/ 	
   309 /******/ 	
   478 /************************************************************************/
   310 /************************************************************************/
   479 var __webpack_exports__ = {};
   311 var __webpack_exports__ = {};
   480 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
   312 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
   481 !function() {
   313 (() => {
   482 "use strict";
   314 "use strict";
   483 // ESM COMPAT FLAG
   315 // ESM COMPAT FLAG
   484 __webpack_require__.r(__webpack_exports__);
   316 __webpack_require__.r(__webpack_exports__);
   485 
   317 
   486 // EXPORTS
   318 // EXPORTS
   487 __webpack_require__.d(__webpack_exports__, {
   319 __webpack_require__.d(__webpack_exports__, {
   488   "__": function() { return /* reexport */ __; },
   320   __: () => (/* reexport */ __),
   489   "_n": function() { return /* reexport */ _n; },
   321   _n: () => (/* reexport */ _n),
   490   "_nx": function() { return /* reexport */ _nx; },
   322   _nx: () => (/* reexport */ _nx),
   491   "_x": function() { return /* reexport */ _x; },
   323   _x: () => (/* reexport */ _x),
   492   "createI18n": function() { return /* reexport */ createI18n; },
   324   createI18n: () => (/* reexport */ createI18n),
   493   "defaultI18n": function() { return /* reexport */ default_i18n; },
   325   defaultI18n: () => (/* reexport */ default_i18n),
   494   "getLocaleData": function() { return /* reexport */ getLocaleData; },
   326   getLocaleData: () => (/* reexport */ getLocaleData),
   495   "hasTranslation": function() { return /* reexport */ hasTranslation; },
   327   hasTranslation: () => (/* reexport */ hasTranslation),
   496   "isRTL": function() { return /* reexport */ isRTL; },
   328   isRTL: () => (/* reexport */ isRTL),
   497   "resetLocaleData": function() { return /* reexport */ resetLocaleData; },
   329   resetLocaleData: () => (/* reexport */ resetLocaleData),
   498   "setLocaleData": function() { return /* reexport */ setLocaleData; },
   330   setLocaleData: () => (/* reexport */ setLocaleData),
   499   "sprintf": function() { return /* reexport */ sprintf_sprintf; },
   331   sprintf: () => (/* reexport */ sprintf_sprintf),
   500   "subscribe": function() { return /* reexport */ subscribe; }
   332   subscribe: () => (/* reexport */ subscribe)
   501 });
   333 });
   502 
   334 
   503 // EXTERNAL MODULE: ./node_modules/memize/index.js
   335 ;// CONCATENATED MODULE: ./node_modules/memize/dist/index.js
   504 var memize = __webpack_require__(9756);
   336 /**
   505 var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
   337  * Memize options object.
       
   338  *
       
   339  * @typedef MemizeOptions
       
   340  *
       
   341  * @property {number} [maxSize] Maximum size of the cache.
       
   342  */
       
   343 
       
   344 /**
       
   345  * Internal cache entry.
       
   346  *
       
   347  * @typedef MemizeCacheNode
       
   348  *
       
   349  * @property {?MemizeCacheNode|undefined} [prev] Previous node.
       
   350  * @property {?MemizeCacheNode|undefined} [next] Next node.
       
   351  * @property {Array<*>}                   args   Function arguments for cache
       
   352  *                                               entry.
       
   353  * @property {*}                          val    Function result.
       
   354  */
       
   355 
       
   356 /**
       
   357  * Properties of the enhanced function for controlling cache.
       
   358  *
       
   359  * @typedef MemizeMemoizedFunction
       
   360  *
       
   361  * @property {()=>void} clear Clear the cache.
       
   362  */
       
   363 
       
   364 /**
       
   365  * Accepts a function to be memoized, and returns a new memoized function, with
       
   366  * optional options.
       
   367  *
       
   368  * @template {(...args: any[]) => any} F
       
   369  *
       
   370  * @param {F}             fn        Function to memoize.
       
   371  * @param {MemizeOptions} [options] Options object.
       
   372  *
       
   373  * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
       
   374  */
       
   375 function memize(fn, options) {
       
   376 	var size = 0;
       
   377 
       
   378 	/** @type {?MemizeCacheNode|undefined} */
       
   379 	var head;
       
   380 
       
   381 	/** @type {?MemizeCacheNode|undefined} */
       
   382 	var tail;
       
   383 
       
   384 	options = options || {};
       
   385 
       
   386 	function memoized(/* ...args */) {
       
   387 		var node = head,
       
   388 			len = arguments.length,
       
   389 			args,
       
   390 			i;
       
   391 
       
   392 		searchCache: while (node) {
       
   393 			// Perform a shallow equality test to confirm that whether the node
       
   394 			// under test is a candidate for the arguments passed. Two arrays
       
   395 			// are shallowly equal if their length matches and each entry is
       
   396 			// strictly equal between the two sets. Avoid abstracting to a
       
   397 			// function which could incur an arguments leaking deoptimization.
       
   398 
       
   399 			// Check whether node arguments match arguments length
       
   400 			if (node.args.length !== arguments.length) {
       
   401 				node = node.next;
       
   402 				continue;
       
   403 			}
       
   404 
       
   405 			// Check whether node arguments match arguments values
       
   406 			for (i = 0; i < len; i++) {
       
   407 				if (node.args[i] !== arguments[i]) {
       
   408 					node = node.next;
       
   409 					continue searchCache;
       
   410 				}
       
   411 			}
       
   412 
       
   413 			// At this point we can assume we've found a match
       
   414 
       
   415 			// Surface matched node to head if not already
       
   416 			if (node !== head) {
       
   417 				// As tail, shift to previous. Must only shift if not also
       
   418 				// head, since if both head and tail, there is no previous.
       
   419 				if (node === tail) {
       
   420 					tail = node.prev;
       
   421 				}
       
   422 
       
   423 				// Adjust siblings to point to each other. If node was tail,
       
   424 				// this also handles new tail's empty `next` assignment.
       
   425 				/** @type {MemizeCacheNode} */ (node.prev).next = node.next;
       
   426 				if (node.next) {
       
   427 					node.next.prev = node.prev;
       
   428 				}
       
   429 
       
   430 				node.next = head;
       
   431 				node.prev = null;
       
   432 				/** @type {MemizeCacheNode} */ (head).prev = node;
       
   433 				head = node;
       
   434 			}
       
   435 
       
   436 			// Return immediately
       
   437 			return node.val;
       
   438 		}
       
   439 
       
   440 		// No cached value found. Continue to insertion phase:
       
   441 
       
   442 		// Create a copy of arguments (avoid leaking deoptimization)
       
   443 		args = new Array(len);
       
   444 		for (i = 0; i < len; i++) {
       
   445 			args[i] = arguments[i];
       
   446 		}
       
   447 
       
   448 		node = {
       
   449 			args: args,
       
   450 
       
   451 			// Generate the result from original function
       
   452 			val: fn.apply(null, args),
       
   453 		};
       
   454 
       
   455 		// Don't need to check whether node is already head, since it would
       
   456 		// have been returned above already if it was
       
   457 
       
   458 		// Shift existing head down list
       
   459 		if (head) {
       
   460 			head.prev = node;
       
   461 			node.next = head;
       
   462 		} else {
       
   463 			// If no head, follows that there's no tail (at initial or reset)
       
   464 			tail = node;
       
   465 		}
       
   466 
       
   467 		// Trim tail if we're reached max size and are pending cache insertion
       
   468 		if (size === /** @type {MemizeOptions} */ (options).maxSize) {
       
   469 			tail = /** @type {MemizeCacheNode} */ (tail).prev;
       
   470 			/** @type {MemizeCacheNode} */ (tail).next = null;
       
   471 		} else {
       
   472 			size++;
       
   473 		}
       
   474 
       
   475 		head = node;
       
   476 
       
   477 		return node.val;
       
   478 	}
       
   479 
       
   480 	memoized.clear = function () {
       
   481 		head = null;
       
   482 		tail = null;
       
   483 		size = 0;
       
   484 	};
       
   485 
       
   486 	// Ignore reason: There's not a clear solution to create an intersection of
       
   487 	// the function with additional properties, where the goal is to retain the
       
   488 	// function signature of the incoming argument and add control properties
       
   489 	// on the return value.
       
   490 
       
   491 	// @ts-ignore
       
   492 	return memoized;
       
   493 }
       
   494 
       
   495 
       
   496 
   506 // EXTERNAL MODULE: ./node_modules/sprintf-js/src/sprintf.js
   497 // EXTERNAL MODULE: ./node_modules/sprintf-js/src/sprintf.js
   507 var sprintf = __webpack_require__(124);
   498 var sprintf = __webpack_require__(2058);
   508 var sprintf_default = /*#__PURE__*/__webpack_require__.n(sprintf);
   499 var sprintf_default = /*#__PURE__*/__webpack_require__.n(sprintf);
   509 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/sprintf.js
   500 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/sprintf.js
   510 /**
   501 /**
   511  * External dependencies
   502  * External dependencies
   512  */
   503  */
       
   504 
   513 
   505 
   514 
   506 
   515 /**
   507 /**
   516  * Log to console, once per message; or more precisely, per referentially equal
   508  * Log to console, once per message; or more precisely, per referentially equal
   517  * argument set. Because Jed throws errors, we log these to the console instead
   509  * argument set. Because Jed throws errors, we log these to the console instead
   518  * to avoid crashing the application.
   510  * to avoid crashing the application.
   519  *
   511  *
   520  * @param {...*} args Arguments to pass to `console.error`
   512  * @param {...*} args Arguments to pass to `console.error`
   521  */
   513  */
   522 
   514 const logErrorOnce = memize(console.error); // eslint-disable-line no-console
   523 const logErrorOnce = memize_default()(console.error); // eslint-disable-line no-console
       
   524 
   515 
   525 /**
   516 /**
   526  * Returns a formatted string. If an error occurs in applying the format, the
   517  * Returns a formatted string. If an error occurs in applying the format, the
   527  * original format string is returned.
   518  * original format string is returned.
   528  *
   519  *
   531  *
   522  *
   532  * @see https://www.npmjs.com/package/sprintf-js
   523  * @see https://www.npmjs.com/package/sprintf-js
   533  *
   524  *
   534  * @return {string} The formatted string.
   525  * @return {string} The formatted string.
   535  */
   526  */
   536 
   527 function sprintf_sprintf(format, ...args) {
   537 function sprintf_sprintf(format) {
       
   538   try {
   528   try {
   539     for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
       
   540       args[_key - 1] = arguments[_key];
       
   541     }
       
   542 
       
   543     return sprintf_default().sprintf(format, ...args);
   529     return sprintf_default().sprintf(format, ...args);
   544   } catch (error) {
   530   } catch (error) {
   545     if (error instanceof Error) {
   531     if (error instanceof Error) {
   546       logErrorOnce('sprintf error: \n\n' + error.toString());
   532       logErrorOnce('sprintf error: \n\n' + error.toString());
   547     }
   533     }
   548 
       
   549     return format;
   534     return format;
   550   }
   535   }
   551 }
   536 }
   552 
   537 
   553 ;// CONCATENATED MODULE: ./node_modules/@tannin/postfix/index.js
   538 ;// CONCATENATED MODULE: ./node_modules/@tannin/postfix/index.js
  1057 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/create-i18n.js
  1042 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/create-i18n.js
  1058 /**
  1043 /**
  1059  * External dependencies
  1044  * External dependencies
  1060  */
  1045  */
  1061 
  1046 
       
  1047 
  1062 /**
  1048 /**
  1063  * @typedef {Record<string,any>} LocaleData
  1049  * @typedef {Record<string,any>} LocaleData
  1064  */
  1050  */
  1065 
  1051 
  1066 /**
  1052 /**
  1067  * Default locale data to use for Tannin domain when not otherwise provided.
  1053  * Default locale data to use for Tannin domain when not otherwise provided.
  1068  * Assumes an English plural forms expression.
  1054  * Assumes an English plural forms expression.
  1069  *
  1055  *
  1070  * @type {LocaleData}
  1056  * @type {LocaleData}
  1071  */
  1057  */
  1072 
       
  1073 const DEFAULT_LOCALE_DATA = {
  1058 const DEFAULT_LOCALE_DATA = {
  1074   '': {
  1059   '': {
  1075     /** @param {number} n */
  1060     /** @param {number} n */
  1076     plural_forms(n) {
  1061     plural_forms(n) {
  1077       return n === 1 ? 0 : 1;
  1062       return n === 1 ? 0 : 1;
  1078     }
  1063     }
  1079 
       
  1080   }
  1064   }
  1081 };
  1065 };
       
  1066 
  1082 /*
  1067 /*
  1083  * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,
  1068  * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,
  1084  * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.
  1069  * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.
  1085  */
  1070  */
  1086 
       
  1087 const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
  1071 const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
       
  1072 
  1088 /**
  1073 /**
  1089  * @typedef {(domain?: string) => LocaleData} GetLocaleData
  1074  * @typedef {(domain?: string) => LocaleData} GetLocaleData
  1090  *
  1075  *
  1091  * Returns locale data by domain in a
  1076  * Returns locale data by domain in a
  1092  * Jed-formatted JSON object shape.
  1077  * Jed-formatted JSON object shape.
  1093  *
  1078  *
  1094  * @see http://messageformat.github.io/Jed/
  1079  * @see http://messageformat.github.io/Jed/
  1095  */
  1080  */
  1096 
       
  1097 /**
  1081 /**
  1098  * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
  1082  * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
  1099  *
  1083  *
  1100  * Merges locale data into the Tannin instance by domain. Note that this
  1084  * Merges locale data into the Tannin instance by domain. Note that this
  1101  * function will overwrite the domain configuration. Accepts data in a
  1085  * function will overwrite the domain configuration. Accepts data in a
  1102  * Jed-formatted JSON object shape.
  1086  * Jed-formatted JSON object shape.
  1103  *
  1087  *
  1104  * @see http://messageformat.github.io/Jed/
  1088  * @see http://messageformat.github.io/Jed/
  1105  */
  1089  */
  1106 
       
  1107 /**
  1090 /**
  1108  * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
  1091  * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
  1109  *
  1092  *
  1110  * Merges locale data into the Tannin instance by domain. Note that this
  1093  * Merges locale data into the Tannin instance by domain. Note that this
  1111  * function will also merge the domain configuration. Accepts data in a
  1094  * function will also merge the domain configuration. Accepts data in a
  1112  * Jed-formatted JSON object shape.
  1095  * Jed-formatted JSON object shape.
  1113  *
  1096  *
  1114  * @see http://messageformat.github.io/Jed/
  1097  * @see http://messageformat.github.io/Jed/
  1115  */
  1098  */
  1116 
       
  1117 /**
  1099 /**
  1118  * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
  1100  * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
  1119  *
  1101  *
  1120  * Resets all current Tannin instance locale data and sets the specified
  1102  * Resets all current Tannin instance locale data and sets the specified
  1121  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1103  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1122  *
  1104  *
  1123  * @see http://messageformat.github.io/Jed/
  1105  * @see http://messageformat.github.io/Jed/
  1124  */
  1106  */
  1125 
       
  1126 /** @typedef {() => void} SubscribeCallback */
  1107 /** @typedef {() => void} SubscribeCallback */
  1127 
       
  1128 /** @typedef {() => void} UnsubscribeCallback */
  1108 /** @typedef {() => void} UnsubscribeCallback */
  1129 
       
  1130 /**
  1109 /**
  1131  * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
  1110  * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
  1132  *
  1111  *
  1133  * Subscribes to changes of locale data
  1112  * Subscribes to changes of locale data
  1134  */
  1113  */
  1135 
       
  1136 /**
  1114 /**
  1137  * @typedef {(domain?: string) => string} GetFilterDomain
  1115  * @typedef {(domain?: string) => string} GetFilterDomain
  1138  * Retrieve the domain to use when calling domain-specific filters.
  1116  * Retrieve the domain to use when calling domain-specific filters.
  1139  */
  1117  */
  1140 
       
  1141 /**
  1118 /**
  1142  * @typedef {(text: string, domain?: string) => string} __
  1119  * @typedef {(text: string, domain?: string) => string} __
  1143  *
  1120  *
  1144  * Retrieve the translation of text.
  1121  * Retrieve the translation of text.
  1145  *
  1122  *
  1146  * @see https://developer.wordpress.org/reference/functions/__/
  1123  * @see https://developer.wordpress.org/reference/functions/__/
  1147  */
  1124  */
  1148 
       
  1149 /**
  1125 /**
  1150  * @typedef {(text: string, context: string, domain?: string) => string} _x
  1126  * @typedef {(text: string, context: string, domain?: string) => string} _x
  1151  *
  1127  *
  1152  * Retrieve translated string with gettext context.
  1128  * Retrieve translated string with gettext context.
  1153  *
  1129  *
  1154  * @see https://developer.wordpress.org/reference/functions/_x/
  1130  * @see https://developer.wordpress.org/reference/functions/_x/
  1155  */
  1131  */
  1156 
       
  1157 /**
  1132 /**
  1158  * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
  1133  * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
  1159  *
  1134  *
  1160  * Translates and retrieves the singular or plural form based on the supplied
  1135  * Translates and retrieves the singular or plural form based on the supplied
  1161  * number.
  1136  * number.
  1162  *
  1137  *
  1163  * @see https://developer.wordpress.org/reference/functions/_n/
  1138  * @see https://developer.wordpress.org/reference/functions/_n/
  1164  */
  1139  */
  1165 
       
  1166 /**
  1140 /**
  1167  * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
  1141  * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
  1168  *
  1142  *
  1169  * Translates and retrieves the singular or plural form based on the supplied
  1143  * Translates and retrieves the singular or plural form based on the supplied
  1170  * number, with gettext context.
  1144  * number, with gettext context.
  1171  *
  1145  *
  1172  * @see https://developer.wordpress.org/reference/functions/_nx/
  1146  * @see https://developer.wordpress.org/reference/functions/_nx/
  1173  */
  1147  */
  1174 
       
  1175 /**
  1148 /**
  1176  * @typedef {() => boolean} IsRtl
  1149  * @typedef {() => boolean} IsRtl
  1177  *
  1150  *
  1178  * Check if current locale is RTL.
  1151  * Check if current locale is RTL.
  1179  *
  1152  *
  1180  * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1153  * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1181  * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1154  * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1182  * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1155  * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1183  * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1156  * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1184  */
  1157  */
  1185 
       
  1186 /**
  1158 /**
  1187  * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
  1159  * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
  1188  *
  1160  *
  1189  * Check if there is a translation for a given string in singular form.
  1161  * Check if there is a translation for a given string in singular form.
  1190  */
  1162  */
  1191 
       
  1192 /** @typedef {import('@wordpress/hooks').Hooks} Hooks */
  1163 /** @typedef {import('@wordpress/hooks').Hooks} Hooks */
  1193 
  1164 
  1194 /**
  1165 /**
  1195  * An i18n instance
  1166  * An i18n instance
  1196  *
  1167  *
  1222  * @param {string}     [initialDomain] Domain for which configuration applies.
  1193  * @param {string}     [initialDomain] Domain for which configuration applies.
  1223  * @param {Hooks}      [hooks]         Hooks implementation.
  1194  * @param {Hooks}      [hooks]         Hooks implementation.
  1224  *
  1195  *
  1225  * @return {I18n} I18n instance.
  1196  * @return {I18n} I18n instance.
  1226  */
  1197  */
  1227 
       
  1228 const createI18n = (initialData, initialDomain, hooks) => {
  1198 const createI18n = (initialData, initialDomain, hooks) => {
  1229   /**
  1199   /**
  1230    * The underlying instance of Tannin to which exported functions interface.
  1200    * The underlying instance of Tannin to which exported functions interface.
  1231    *
  1201    *
  1232    * @type {Tannin}
  1202    * @type {Tannin}
  1233    */
  1203    */
  1234   const tannin = new Tannin({});
  1204   const tannin = new Tannin({});
  1235   const listeners = new Set();
  1205   const listeners = new Set();
  1236 
       
  1237   const notifyListeners = () => {
  1206   const notifyListeners = () => {
  1238     listeners.forEach(listener => listener());
  1207     listeners.forEach(listener => listener());
  1239   };
  1208   };
       
  1209 
  1240   /**
  1210   /**
  1241    * Subscribe to changes of locale data.
  1211    * Subscribe to changes of locale data.
  1242    *
  1212    *
  1243    * @param {SubscribeCallback} callback Subscription callback.
  1213    * @param {SubscribeCallback} callback Subscription callback.
  1244    * @return {UnsubscribeCallback} Unsubscribe callback.
  1214    * @return {UnsubscribeCallback} Unsubscribe callback.
  1245    */
  1215    */
  1246 
       
  1247 
       
  1248   const subscribe = callback => {
  1216   const subscribe = callback => {
  1249     listeners.add(callback);
  1217     listeners.add(callback);
  1250     return () => listeners.delete(callback);
  1218     return () => listeners.delete(callback);
  1251   };
  1219   };
       
  1220 
  1252   /** @type {GetLocaleData} */
  1221   /** @type {GetLocaleData} */
  1253 
  1222   const getLocaleData = (domain = 'default') => tannin.data[domain];
  1254 
  1223 
  1255   const getLocaleData = function () {
       
  1256     let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
       
  1257     return tannin.data[domain];
       
  1258   };
       
  1259   /**
  1224   /**
  1260    * @param {LocaleData} [data]
  1225    * @param {LocaleData} [data]
  1261    * @param {string}     [domain]
  1226    * @param {string}     [domain]
  1262    */
  1227    */
  1263 
  1228   const doSetLocaleData = (data, domain = 'default') => {
  1264 
  1229     tannin.data[domain] = {
  1265   const doSetLocaleData = function (data) {
  1230       ...tannin.data[domain],
  1266     var _tannin$data$domain;
       
  1267 
       
  1268     let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
       
  1269     tannin.data[domain] = { ...tannin.data[domain],
       
  1270       ...data
  1231       ...data
  1271     }; // Populate default domain configuration (supported locale date which omits
  1232     };
       
  1233 
       
  1234     // Populate default domain configuration (supported locale date which omits
  1272     // a plural forms expression).
  1235     // a plural forms expression).
  1273 
  1236     tannin.data[domain][''] = {
  1274     tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
  1237       ...DEFAULT_LOCALE_DATA[''],
  1275       ...((_tannin$data$domain = tannin.data[domain]) === null || _tannin$data$domain === void 0 ? void 0 : _tannin$data$domain[''])
  1238       ...tannin.data[domain]?.['']
  1276     }; // Clean up cached plural forms functions cache as it might be updated.
  1239     };
  1277 
  1240 
       
  1241     // Clean up cached plural forms functions cache as it might be updated.
  1278     delete tannin.pluralForms[domain];
  1242     delete tannin.pluralForms[domain];
  1279   };
  1243   };
       
  1244 
  1280   /** @type {SetLocaleData} */
  1245   /** @type {SetLocaleData} */
  1281 
       
  1282 
       
  1283   const setLocaleData = (data, domain) => {
  1246   const setLocaleData = (data, domain) => {
  1284     doSetLocaleData(data, domain);
  1247     doSetLocaleData(data, domain);
  1285     notifyListeners();
  1248     notifyListeners();
  1286   };
  1249   };
       
  1250 
  1287   /** @type {AddLocaleData} */
  1251   /** @type {AddLocaleData} */
  1288 
  1252   const addLocaleData = (data, domain = 'default') => {
  1289 
  1253     tannin.data[domain] = {
  1290   const addLocaleData = function (data) {
  1254       ...tannin.data[domain],
  1291     var _tannin$data$domain2;
       
  1292 
       
  1293     let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
       
  1294     tannin.data[domain] = { ...tannin.data[domain],
       
  1295       ...data,
  1255       ...data,
  1296       // Populate default domain configuration (supported locale date which omits
  1256       // Populate default domain configuration (supported locale date which omits
  1297       // a plural forms expression).
  1257       // a plural forms expression).
  1298       '': { ...DEFAULT_LOCALE_DATA[''],
  1258       '': {
  1299         ...((_tannin$data$domain2 = tannin.data[domain]) === null || _tannin$data$domain2 === void 0 ? void 0 : _tannin$data$domain2['']),
  1259         ...DEFAULT_LOCALE_DATA[''],
  1300         ...(data === null || data === void 0 ? void 0 : data[''])
  1260         ...tannin.data[domain]?.[''],
       
  1261         ...data?.['']
  1301       }
  1262       }
  1302     }; // Clean up cached plural forms functions cache as it might be updated.
  1263     };
  1303 
  1264 
       
  1265     // Clean up cached plural forms functions cache as it might be updated.
  1304     delete tannin.pluralForms[domain];
  1266     delete tannin.pluralForms[domain];
  1305     notifyListeners();
  1267     notifyListeners();
  1306   };
  1268   };
       
  1269 
  1307   /** @type {ResetLocaleData} */
  1270   /** @type {ResetLocaleData} */
  1308 
       
  1309 
       
  1310   const resetLocaleData = (data, domain) => {
  1271   const resetLocaleData = (data, domain) => {
  1311     // Reset all current Tannin locale data.
  1272     // Reset all current Tannin locale data.
  1312     tannin.data = {}; // Reset cached plural forms functions cache.
  1273     tannin.data = {};
  1313 
  1274 
       
  1275     // Reset cached plural forms functions cache.
  1314     tannin.pluralForms = {};
  1276     tannin.pluralForms = {};
  1315     setLocaleData(data, domain);
  1277     setLocaleData(data, domain);
  1316   };
  1278   };
       
  1279 
  1317   /**
  1280   /**
  1318    * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
  1281    * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
  1319    * otherwise previously assigned.
  1282    * otherwise previously assigned.
  1320    *
  1283    *
  1321    * @param {string|undefined} domain   Domain to retrieve the translated text.
  1284    * @param {string|undefined} domain   Domain to retrieve the translated text.
  1327    * @param {number}           [number] The number to compare against to use
  1290    * @param {number}           [number] The number to compare against to use
  1328    *                                    either the singular or plural form.
  1291    *                                    either the singular or plural form.
  1329    *
  1292    *
  1330    * @return {string} The translated string.
  1293    * @return {string} The translated string.
  1331    */
  1294    */
  1332 
  1295   const dcnpgettext = (domain = 'default', context, single, plural, number) => {
  1333 
       
  1334   const dcnpgettext = function () {
       
  1335     let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
       
  1336     let context = arguments.length > 1 ? arguments[1] : undefined;
       
  1337     let single = arguments.length > 2 ? arguments[2] : undefined;
       
  1338     let plural = arguments.length > 3 ? arguments[3] : undefined;
       
  1339     let number = arguments.length > 4 ? arguments[4] : undefined;
       
  1340 
       
  1341     if (!tannin.data[domain]) {
  1296     if (!tannin.data[domain]) {
  1342       // Use `doSetLocaleData` to set silently, without notifying listeners.
  1297       // Use `doSetLocaleData` to set silently, without notifying listeners.
  1343       doSetLocaleData(undefined, domain);
  1298       doSetLocaleData(undefined, domain);
  1344     }
  1299     }
  1345 
       
  1346     return tannin.dcnpgettext(domain, context, single, plural, number);
  1300     return tannin.dcnpgettext(domain, context, single, plural, number);
  1347   };
  1301   };
       
  1302 
  1348   /** @type {GetFilterDomain} */
  1303   /** @type {GetFilterDomain} */
  1349 
  1304   const getFilterDomain = (domain = 'default') => domain;
  1350 
  1305 
  1351   const getFilterDomain = function () {
       
  1352     let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
       
  1353     return domain;
       
  1354   };
       
  1355   /** @type {__} */
  1306   /** @type {__} */
  1356 
       
  1357 
       
  1358   const __ = (text, domain) => {
  1307   const __ = (text, domain) => {
  1359     let translation = dcnpgettext(domain, undefined, text);
  1308     let translation = dcnpgettext(domain, undefined, text);
  1360 
       
  1361     if (!hooks) {
  1309     if (!hooks) {
  1362       return translation;
  1310       return translation;
  1363     }
  1311     }
       
  1312 
  1364     /**
  1313     /**
  1365      * Filters text with its translation.
  1314      * Filters text with its translation.
  1366      *
  1315      *
  1367      * @param {string} translation Translated text.
  1316      * @param {string} translation Translated text.
  1368      * @param {string} text        Text to translate.
  1317      * @param {string} text        Text to translate.
  1369      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1318      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1370      */
  1319      */
  1371 
  1320     translation = /** @type {string} */
  1372 
  1321     /** @type {*} */hooks.applyFilters('i18n.gettext', translation, text, domain);
  1373     translation =
  1322     return /** @type {string} */(
  1374     /** @type {string} */
  1323       /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain)
  1375 
       
  1376     /** @type {*} */
       
  1377     hooks.applyFilters('i18n.gettext', translation, text, domain);
       
  1378     return (
       
  1379       /** @type {string} */
       
  1380 
       
  1381       /** @type {*} */
       
  1382       hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain)
       
  1383     );
  1324     );
  1384   };
  1325   };
       
  1326 
  1385   /** @type {_x} */
  1327   /** @type {_x} */
  1386 
       
  1387 
       
  1388   const _x = (text, context, domain) => {
  1328   const _x = (text, context, domain) => {
  1389     let translation = dcnpgettext(domain, context, text);
  1329     let translation = dcnpgettext(domain, context, text);
  1390 
       
  1391     if (!hooks) {
  1330     if (!hooks) {
  1392       return translation;
  1331       return translation;
  1393     }
  1332     }
       
  1333 
  1394     /**
  1334     /**
  1395      * Filters text with its translation based on context information.
  1335      * Filters text with its translation based on context information.
  1396      *
  1336      *
  1397      * @param {string} translation Translated text.
  1337      * @param {string} translation Translated text.
  1398      * @param {string} text        Text to translate.
  1338      * @param {string} text        Text to translate.
  1399      * @param {string} context     Context information for the translators.
  1339      * @param {string} context     Context information for the translators.
  1400      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1340      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1401      */
  1341      */
  1402 
  1342     translation = /** @type {string} */
  1403 
  1343     /** @type {*} */hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
  1404     translation =
  1344     return /** @type {string} */(
  1405     /** @type {string} */
  1345       /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain)
  1406 
       
  1407     /** @type {*} */
       
  1408     hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
       
  1409     return (
       
  1410       /** @type {string} */
       
  1411 
       
  1412       /** @type {*} */
       
  1413       hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain)
       
  1414     );
  1346     );
  1415   };
  1347   };
       
  1348 
  1416   /** @type {_n} */
  1349   /** @type {_n} */
  1417 
       
  1418 
       
  1419   const _n = (single, plural, number, domain) => {
  1350   const _n = (single, plural, number, domain) => {
  1420     let translation = dcnpgettext(domain, undefined, single, plural, number);
  1351     let translation = dcnpgettext(domain, undefined, single, plural, number);
  1421 
       
  1422     if (!hooks) {
  1352     if (!hooks) {
  1423       return translation;
  1353       return translation;
  1424     }
  1354     }
       
  1355 
  1425     /**
  1356     /**
  1426      * Filters the singular or plural form of a string.
  1357      * Filters the singular or plural form of a string.
  1427      *
  1358      *
  1428      * @param {string} translation Translated text.
  1359      * @param {string} translation Translated text.
  1429      * @param {string} single      The text to be used if the number is singular.
  1360      * @param {string} single      The text to be used if the number is singular.
  1430      * @param {string} plural      The text to be used if the number is plural.
  1361      * @param {string} plural      The text to be used if the number is plural.
  1431      * @param {string} number      The number to compare against to use either the singular or plural form.
  1362      * @param {string} number      The number to compare against to use either the singular or plural form.
  1432      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1363      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1433      */
  1364      */
  1434 
  1365     translation = /** @type {string} */
  1435 
  1366     /** @type {*} */hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
  1436     translation =
  1367     return /** @type {string} */(
  1437     /** @type {string} */
  1368       /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain)
  1438 
       
  1439     /** @type {*} */
       
  1440     hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
       
  1441     return (
       
  1442       /** @type {string} */
       
  1443 
       
  1444       /** @type {*} */
       
  1445       hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain)
       
  1446     );
  1369     );
  1447   };
  1370   };
       
  1371 
  1448   /** @type {_nx} */
  1372   /** @type {_nx} */
  1449 
       
  1450 
       
  1451   const _nx = (single, plural, number, context, domain) => {
  1373   const _nx = (single, plural, number, context, domain) => {
  1452     let translation = dcnpgettext(domain, context, single, plural, number);
  1374     let translation = dcnpgettext(domain, context, single, plural, number);
  1453 
       
  1454     if (!hooks) {
  1375     if (!hooks) {
  1455       return translation;
  1376       return translation;
  1456     }
  1377     }
       
  1378 
  1457     /**
  1379     /**
  1458      * Filters the singular or plural form of a string with gettext context.
  1380      * Filters the singular or plural form of a string with gettext context.
  1459      *
  1381      *
  1460      * @param {string} translation Translated text.
  1382      * @param {string} translation Translated text.
  1461      * @param {string} single      The text to be used if the number is singular.
  1383      * @param {string} single      The text to be used if the number is singular.
  1462      * @param {string} plural      The text to be used if the number is plural.
  1384      * @param {string} plural      The text to be used if the number is plural.
  1463      * @param {string} number      The number to compare against to use either the singular or plural form.
  1385      * @param {string} number      The number to compare against to use either the singular or plural form.
  1464      * @param {string} context     Context information for the translators.
  1386      * @param {string} context     Context information for the translators.
  1465      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1387      * @param {string} domain      Text domain. Unique identifier for retrieving translated strings.
  1466      */
  1388      */
  1467 
  1389     translation = /** @type {string} */
  1468 
  1390     /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
  1469     translation =
  1391     return /** @type {string} */(
  1470     /** @type {string} */
  1392       /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain)
  1471 
       
  1472     /** @type {*} */
       
  1473     hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
       
  1474     return (
       
  1475       /** @type {string} */
       
  1476 
       
  1477       /** @type {*} */
       
  1478       hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain)
       
  1479     );
  1393     );
  1480   };
  1394   };
       
  1395 
  1481   /** @type {IsRtl} */
  1396   /** @type {IsRtl} */
  1482 
       
  1483 
       
  1484   const isRTL = () => {
  1397   const isRTL = () => {
  1485     return 'rtl' === _x('ltr', 'text direction');
  1398     return 'rtl' === _x('ltr', 'text direction');
  1486   };
  1399   };
       
  1400 
  1487   /** @type {HasTranslation} */
  1401   /** @type {HasTranslation} */
  1488 
       
  1489 
       
  1490   const hasTranslation = (single, context, domain) => {
  1402   const hasTranslation = (single, context, domain) => {
  1491     var _tannin$data, _tannin$data2;
       
  1492 
       
  1493     const key = context ? context + '\u0004' + single : single;
  1403     const key = context ? context + '\u0004' + single : single;
  1494     let result = !!((_tannin$data = tannin.data) !== null && _tannin$data !== void 0 && (_tannin$data2 = _tannin$data[domain !== null && domain !== void 0 ? domain : 'default']) !== null && _tannin$data2 !== void 0 && _tannin$data2[key]);
  1404     let result = !!tannin.data?.[domain !== null && domain !== void 0 ? domain : 'default']?.[key];
  1495 
       
  1496     if (hooks) {
  1405     if (hooks) {
  1497       /**
  1406       /**
  1498        * Filters the presence of a translation in the locale data.
  1407        * Filters the presence of a translation in the locale data.
  1499        *
  1408        *
  1500        * @param {boolean} hasTranslation Whether the translation is present or not..
  1409        * @param {boolean} hasTranslation Whether the translation is present or not..
  1501        * @param {string}  single         The singular form of the translated text (used as key in locale data)
  1410        * @param {string}  single         The singular form of the translated text (used as key in locale data)
  1502        * @param {string}  context        Context information for the translators.
  1411        * @param {string}  context        Context information for the translators.
  1503        * @param {string}  domain         Text domain. Unique identifier for retrieving translated strings.
  1412        * @param {string}  domain         Text domain. Unique identifier for retrieving translated strings.
  1504        */
  1413        */
  1505       result =
  1414       result = /** @type { boolean } */
  1506       /** @type { boolean } */
  1415       /** @type {*} */hooks.applyFilters('i18n.has_translation', result, single, context, domain);
  1507 
  1416       result = /** @type { boolean } */
  1508       /** @type {*} */
  1417       /** @type {*} */hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
  1509       hooks.applyFilters('i18n.has_translation', result, single, context, domain);
       
  1510       result =
       
  1511       /** @type { boolean } */
       
  1512 
       
  1513       /** @type {*} */
       
  1514       hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
       
  1515     }
  1418     }
  1516 
       
  1517     return result;
  1419     return result;
  1518   };
  1420   };
  1519 
       
  1520   if (initialData) {
  1421   if (initialData) {
  1521     setLocaleData(initialData, initialDomain);
  1422     setLocaleData(initialData, initialDomain);
  1522   }
  1423   }
  1523 
       
  1524   if (hooks) {
  1424   if (hooks) {
  1525     /**
  1425     /**
  1526      * @param {string} hookName
  1426      * @param {string} hookName
  1527      */
  1427      */
  1528     const onHookAddedOrRemoved = hookName => {
  1428     const onHookAddedOrRemoved = hookName => {
  1529       if (I18N_HOOK_REGEXP.test(hookName)) {
  1429       if (I18N_HOOK_REGEXP.test(hookName)) {
  1530         notifyListeners();
  1430         notifyListeners();
  1531       }
  1431       }
  1532     };
  1432     };
  1533 
       
  1534     hooks.addAction('hookAdded', 'core/i18n', onHookAddedOrRemoved);
  1433     hooks.addAction('hookAdded', 'core/i18n', onHookAddedOrRemoved);
  1535     hooks.addAction('hookRemoved', 'core/i18n', onHookAddedOrRemoved);
  1434     hooks.addAction('hookRemoved', 'core/i18n', onHookAddedOrRemoved);
  1536   }
  1435   }
  1537 
       
  1538   return {
  1436   return {
  1539     getLocaleData,
  1437     getLocaleData,
  1540     setLocaleData,
  1438     setLocaleData,
  1541     addLocaleData,
  1439     addLocaleData,
  1542     resetLocaleData,
  1440     resetLocaleData,
  1549     hasTranslation
  1447     hasTranslation
  1550   };
  1448   };
  1551 };
  1449 };
  1552 
  1450 
  1553 ;// CONCATENATED MODULE: external ["wp","hooks"]
  1451 ;// CONCATENATED MODULE: external ["wp","hooks"]
  1554 var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
  1452 const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
  1555 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/default-i18n.js
  1453 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/default-i18n.js
  1556 /**
  1454 /**
  1557  * Internal dependencies
  1455  * Internal dependencies
  1558  */
  1456  */
  1559 
  1457 
       
  1458 
  1560 /**
  1459 /**
  1561  * WordPress dependencies
  1460  * WordPress dependencies
  1562  */
  1461  */
  1563 
  1462 
  1564 
       
  1565 const i18n = createI18n(undefined, undefined, external_wp_hooks_namespaceObject.defaultHooks);
  1463 const i18n = createI18n(undefined, undefined, external_wp_hooks_namespaceObject.defaultHooks);
       
  1464 
  1566 /**
  1465 /**
  1567  * Default, singleton instance of `I18n`.
  1466  * Default, singleton instance of `I18n`.
  1568  */
  1467  */
  1569 
  1468 /* harmony default export */ const default_i18n = (i18n);
  1570 /* harmony default export */ var default_i18n = (i18n);
  1469 
  1571 /*
  1470 /*
  1572  * Comments in this file are duplicated from ./i18n due to
  1471  * Comments in this file are duplicated from ./i18n due to
  1573  * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
  1472  * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
  1574  */
  1473  */
  1575 
  1474 
  1585  * @see http://messageformat.github.io/Jed/
  1484  * @see http://messageformat.github.io/Jed/
  1586  *
  1485  *
  1587  * @param {string} [domain] Domain for which to get the data.
  1486  * @param {string} [domain] Domain for which to get the data.
  1588  * @return {LocaleData} Locale data.
  1487  * @return {LocaleData} Locale data.
  1589  */
  1488  */
  1590 
       
  1591 const getLocaleData = i18n.getLocaleData.bind(i18n);
  1489 const getLocaleData = i18n.getLocaleData.bind(i18n);
       
  1490 
  1592 /**
  1491 /**
  1593  * Merges locale data into the Tannin instance by domain. Accepts data in a
  1492  * Merges locale data into the Tannin instance by domain. Accepts data in a
  1594  * Jed-formatted JSON object shape.
  1493  * Jed-formatted JSON object shape.
  1595  *
  1494  *
  1596  * @see http://messageformat.github.io/Jed/
  1495  * @see http://messageformat.github.io/Jed/
  1597  *
  1496  *
  1598  * @param {LocaleData} [data]   Locale data configuration.
  1497  * @param {LocaleData} [data]   Locale data configuration.
  1599  * @param {string}     [domain] Domain for which configuration applies.
  1498  * @param {string}     [domain] Domain for which configuration applies.
  1600  */
  1499  */
  1601 
       
  1602 const setLocaleData = i18n.setLocaleData.bind(i18n);
  1500 const setLocaleData = i18n.setLocaleData.bind(i18n);
       
  1501 
  1603 /**
  1502 /**
  1604  * Resets all current Tannin instance locale data and sets the specified
  1503  * Resets all current Tannin instance locale data and sets the specified
  1605  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1504  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1606  *
  1505  *
  1607  * @see http://messageformat.github.io/Jed/
  1506  * @see http://messageformat.github.io/Jed/
  1608  *
  1507  *
  1609  * @param {LocaleData} [data]   Locale data configuration.
  1508  * @param {LocaleData} [data]   Locale data configuration.
  1610  * @param {string}     [domain] Domain for which configuration applies.
  1509  * @param {string}     [domain] Domain for which configuration applies.
  1611  */
  1510  */
  1612 
       
  1613 const resetLocaleData = i18n.resetLocaleData.bind(i18n);
  1511 const resetLocaleData = i18n.resetLocaleData.bind(i18n);
       
  1512 
  1614 /**
  1513 /**
  1615  * Subscribes to changes of locale data
  1514  * Subscribes to changes of locale data
  1616  *
  1515  *
  1617  * @param {SubscribeCallback} callback Subscription callback
  1516  * @param {SubscribeCallback} callback Subscription callback
  1618  * @return {UnsubscribeCallback} Unsubscribe callback
  1517  * @return {UnsubscribeCallback} Unsubscribe callback
  1619  */
  1518  */
  1620 
       
  1621 const subscribe = i18n.subscribe.bind(i18n);
  1519 const subscribe = i18n.subscribe.bind(i18n);
       
  1520 
  1622 /**
  1521 /**
  1623  * Retrieve the translation of text.
  1522  * Retrieve the translation of text.
  1624  *
  1523  *
  1625  * @see https://developer.wordpress.org/reference/functions/__/
  1524  * @see https://developer.wordpress.org/reference/functions/__/
  1626  *
  1525  *
  1627  * @param {string} text     Text to translate.
  1526  * @param {string} text     Text to translate.
  1628  * @param {string} [domain] Domain to retrieve the translated text.
  1527  * @param {string} [domain] Domain to retrieve the translated text.
  1629  *
  1528  *
  1630  * @return {string} Translated text.
  1529  * @return {string} Translated text.
  1631  */
  1530  */
  1632 
       
  1633 const __ = i18n.__.bind(i18n);
  1531 const __ = i18n.__.bind(i18n);
       
  1532 
  1634 /**
  1533 /**
  1635  * Retrieve translated string with gettext context.
  1534  * Retrieve translated string with gettext context.
  1636  *
  1535  *
  1637  * @see https://developer.wordpress.org/reference/functions/_x/
  1536  * @see https://developer.wordpress.org/reference/functions/_x/
  1638  *
  1537  *
  1640  * @param {string} context  Context information for the translators.
  1539  * @param {string} context  Context information for the translators.
  1641  * @param {string} [domain] Domain to retrieve the translated text.
  1540  * @param {string} [domain] Domain to retrieve the translated text.
  1642  *
  1541  *
  1643  * @return {string} Translated context string without pipe.
  1542  * @return {string} Translated context string without pipe.
  1644  */
  1543  */
  1645 
       
  1646 const _x = i18n._x.bind(i18n);
  1544 const _x = i18n._x.bind(i18n);
       
  1545 
  1647 /**
  1546 /**
  1648  * Translates and retrieves the singular or plural form based on the supplied
  1547  * Translates and retrieves the singular or plural form based on the supplied
  1649  * number.
  1548  * number.
  1650  *
  1549  *
  1651  * @see https://developer.wordpress.org/reference/functions/_n/
  1550  * @see https://developer.wordpress.org/reference/functions/_n/
  1656  *                          singular or plural form.
  1555  *                          singular or plural form.
  1657  * @param {string} [domain] Domain to retrieve the translated text.
  1556  * @param {string} [domain] Domain to retrieve the translated text.
  1658  *
  1557  *
  1659  * @return {string} The translated singular or plural form.
  1558  * @return {string} The translated singular or plural form.
  1660  */
  1559  */
  1661 
       
  1662 const _n = i18n._n.bind(i18n);
  1560 const _n = i18n._n.bind(i18n);
       
  1561 
  1663 /**
  1562 /**
  1664  * Translates and retrieves the singular or plural form based on the supplied
  1563  * Translates and retrieves the singular or plural form based on the supplied
  1665  * number, with gettext context.
  1564  * number, with gettext context.
  1666  *
  1565  *
  1667  * @see https://developer.wordpress.org/reference/functions/_nx/
  1566  * @see https://developer.wordpress.org/reference/functions/_nx/
  1673  * @param {string} context  Context information for the translators.
  1572  * @param {string} context  Context information for the translators.
  1674  * @param {string} [domain] Domain to retrieve the translated text.
  1573  * @param {string} [domain] Domain to retrieve the translated text.
  1675  *
  1574  *
  1676  * @return {string} The translated singular or plural form.
  1575  * @return {string} The translated singular or plural form.
  1677  */
  1576  */
  1678 
       
  1679 const _nx = i18n._nx.bind(i18n);
  1577 const _nx = i18n._nx.bind(i18n);
       
  1578 
  1680 /**
  1579 /**
  1681  * Check if current locale is RTL.
  1580  * Check if current locale is RTL.
  1682  *
  1581  *
  1683  * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1582  * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1684  * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1583  * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1685  * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1584  * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1686  * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1585  * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1687  *
  1586  *
  1688  * @return {boolean} Whether locale is RTL.
  1587  * @return {boolean} Whether locale is RTL.
  1689  */
  1588  */
  1690 
       
  1691 const isRTL = i18n.isRTL.bind(i18n);
  1589 const isRTL = i18n.isRTL.bind(i18n);
       
  1590 
  1692 /**
  1591 /**
  1693  * Check if there is a translation for a given string (in singular form).
  1592  * Check if there is a translation for a given string (in singular form).
  1694  *
  1593  *
  1695  * @param {string} single    Singular form of the string to look up.
  1594  * @param {string} single    Singular form of the string to look up.
  1696  * @param {string} [context] Context information for the translators.
  1595  * @param {string} [context] Context information for the translators.
  1697  * @param {string} [domain]  Domain to retrieve the translated text.
  1596  * @param {string} [domain]  Domain to retrieve the translated text.
  1698  * @return {boolean} Whether the translation exists or not.
  1597  * @return {boolean} Whether the translation exists or not.
  1699  */
  1598  */
  1700 
       
  1701 const hasTranslation = i18n.hasTranslation.bind(i18n);
  1599 const hasTranslation = i18n.hasTranslation.bind(i18n);
  1702 
  1600 
  1703 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/index.js
  1601 ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/index.js
  1704 
  1602 
  1705 
  1603 
  1706 
  1604 
  1707 
  1605 
  1708 }();
  1606 })();
       
  1607 
  1709 (window.wp = window.wp || {}).i18n = __webpack_exports__;
  1608 (window.wp = window.wp || {}).i18n = __webpack_exports__;
  1710 /******/ })()
  1609 /******/ })()
  1711 ;
  1610 ;