i18n.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ 9756:
  4. /***/ (function(module) {
  5. /**
  6. * Memize options object.
  7. *
  8. * @typedef MemizeOptions
  9. *
  10. * @property {number} [maxSize] Maximum size of the cache.
  11. */
  12. /**
  13. * Internal cache entry.
  14. *
  15. * @typedef MemizeCacheNode
  16. *
  17. * @property {?MemizeCacheNode|undefined} [prev] Previous node.
  18. * @property {?MemizeCacheNode|undefined} [next] Next node.
  19. * @property {Array<*>} args Function arguments for cache
  20. * entry.
  21. * @property {*} val Function result.
  22. */
  23. /**
  24. * Properties of the enhanced function for controlling cache.
  25. *
  26. * @typedef MemizeMemoizedFunction
  27. *
  28. * @property {()=>void} clear Clear the cache.
  29. */
  30. /**
  31. * Accepts a function to be memoized, and returns a new memoized function, with
  32. * optional options.
  33. *
  34. * @template {Function} F
  35. *
  36. * @param {F} fn Function to memoize.
  37. * @param {MemizeOptions} [options] Options object.
  38. *
  39. * @return {F & MemizeMemoizedFunction} Memoized function.
  40. */
  41. function memize( fn, options ) {
  42. var size = 0;
  43. /** @type {?MemizeCacheNode|undefined} */
  44. var head;
  45. /** @type {?MemizeCacheNode|undefined} */
  46. var tail;
  47. options = options || {};
  48. function memoized( /* ...args */ ) {
  49. var node = head,
  50. len = arguments.length,
  51. args, i;
  52. searchCache: while ( node ) {
  53. // Perform a shallow equality test to confirm that whether the node
  54. // under test is a candidate for the arguments passed. Two arrays
  55. // are shallowly equal if their length matches and each entry is
  56. // strictly equal between the two sets. Avoid abstracting to a
  57. // function which could incur an arguments leaking deoptimization.
  58. // Check whether node arguments match arguments length
  59. if ( node.args.length !== arguments.length ) {
  60. node = node.next;
  61. continue;
  62. }
  63. // Check whether node arguments match arguments values
  64. for ( i = 0; i < len; i++ ) {
  65. if ( node.args[ i ] !== arguments[ i ] ) {
  66. node = node.next;
  67. continue searchCache;
  68. }
  69. }
  70. // At this point we can assume we've found a match
  71. // Surface matched node to head if not already
  72. if ( node !== head ) {
  73. // As tail, shift to previous. Must only shift if not also
  74. // head, since if both head and tail, there is no previous.
  75. if ( node === tail ) {
  76. tail = node.prev;
  77. }
  78. // Adjust siblings to point to each other. If node was tail,
  79. // this also handles new tail's empty `next` assignment.
  80. /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
  81. if ( node.next ) {
  82. node.next.prev = node.prev;
  83. }
  84. node.next = head;
  85. node.prev = null;
  86. /** @type {MemizeCacheNode} */ ( head ).prev = node;
  87. head = node;
  88. }
  89. // Return immediately
  90. return node.val;
  91. }
  92. // No cached value found. Continue to insertion phase:
  93. // Create a copy of arguments (avoid leaking deoptimization)
  94. args = new Array( len );
  95. for ( i = 0; i < len; i++ ) {
  96. args[ i ] = arguments[ i ];
  97. }
  98. node = {
  99. args: args,
  100. // Generate the result from original function
  101. val: fn.apply( null, args ),
  102. };
  103. // Don't need to check whether node is already head, since it would
  104. // have been returned above already if it was
  105. // Shift existing head down list
  106. if ( head ) {
  107. head.prev = node;
  108. node.next = head;
  109. } else {
  110. // If no head, follows that there's no tail (at initial or reset)
  111. tail = node;
  112. }
  113. // Trim tail if we're reached max size and are pending cache insertion
  114. if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
  115. tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
  116. /** @type {MemizeCacheNode} */ ( tail ).next = null;
  117. } else {
  118. size++;
  119. }
  120. head = node;
  121. return node.val;
  122. }
  123. memoized.clear = function() {
  124. head = null;
  125. tail = null;
  126. size = 0;
  127. };
  128. if ( false ) {}
  129. // Ignore reason: There's not a clear solution to create an intersection of
  130. // the function with additional properties, where the goal is to retain the
  131. // function signature of the incoming argument and add control properties
  132. // on the return value.
  133. // @ts-ignore
  134. return memoized;
  135. }
  136. module.exports = memize;
  137. /***/ }),
  138. /***/ 124:
  139. /***/ (function(module, exports, __webpack_require__) {
  140. var __WEBPACK_AMD_DEFINE_RESULT__;/* global window, exports, define */
  141. !function() {
  142. 'use strict'
  143. var re = {
  144. not_string: /[^s]/,
  145. not_bool: /[^t]/,
  146. not_type: /[^T]/,
  147. not_primitive: /[^v]/,
  148. number: /[diefg]/,
  149. numeric_arg: /[bcdiefguxX]/,
  150. json: /[j]/,
  151. not_json: /[^j]/,
  152. text: /^[^\x25]+/,
  153. modulo: /^\x25{2}/,
  154. placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
  155. key: /^([a-z_][a-z_\d]*)/i,
  156. key_access: /^\.([a-z_][a-z_\d]*)/i,
  157. index_access: /^\[(\d+)\]/,
  158. sign: /^[+-]/
  159. }
  160. function sprintf(key) {
  161. // `arguments` is not an array, but should be fine for this call
  162. return sprintf_format(sprintf_parse(key), arguments)
  163. }
  164. function vsprintf(fmt, argv) {
  165. return sprintf.apply(null, [fmt].concat(argv || []))
  166. }
  167. function sprintf_format(parse_tree, argv) {
  168. var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
  169. for (i = 0; i < tree_length; i++) {
  170. if (typeof parse_tree[i] === 'string') {
  171. output += parse_tree[i]
  172. }
  173. else if (typeof parse_tree[i] === 'object') {
  174. ph = parse_tree[i] // convenience purposes only
  175. if (ph.keys) { // keyword argument
  176. arg = argv[cursor]
  177. for (k = 0; k < ph.keys.length; k++) {
  178. if (arg == undefined) {
  179. throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
  180. }
  181. arg = arg[ph.keys[k]]
  182. }
  183. }
  184. else if (ph.param_no) { // positional argument (explicit)
  185. arg = argv[ph.param_no]
  186. }
  187. else { // positional argument (implicit)
  188. arg = argv[cursor++]
  189. }
  190. if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
  191. arg = arg()
  192. }
  193. if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
  194. throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
  195. }
  196. if (re.number.test(ph.type)) {
  197. is_positive = arg >= 0
  198. }
  199. switch (ph.type) {
  200. case 'b':
  201. arg = parseInt(arg, 10).toString(2)
  202. break
  203. case 'c':
  204. arg = String.fromCharCode(parseInt(arg, 10))
  205. break
  206. case 'd':
  207. case 'i':
  208. arg = parseInt(arg, 10)
  209. break
  210. case 'j':
  211. arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
  212. break
  213. case 'e':
  214. arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
  215. break
  216. case 'f':
  217. arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
  218. break
  219. case 'g':
  220. arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
  221. break
  222. case 'o':
  223. arg = (parseInt(arg, 10) >>> 0).toString(8)
  224. break
  225. case 's':
  226. arg = String(arg)
  227. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  228. break
  229. case 't':
  230. arg = String(!!arg)
  231. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  232. break
  233. case 'T':
  234. arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
  235. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  236. break
  237. case 'u':
  238. arg = parseInt(arg, 10) >>> 0
  239. break
  240. case 'v':
  241. arg = arg.valueOf()
  242. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  243. break
  244. case 'x':
  245. arg = (parseInt(arg, 10) >>> 0).toString(16)
  246. break
  247. case 'X':
  248. arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
  249. break
  250. }
  251. if (re.json.test(ph.type)) {
  252. output += arg
  253. }
  254. else {
  255. if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
  256. sign = is_positive ? '+' : '-'
  257. arg = arg.toString().replace(re.sign, '')
  258. }
  259. else {
  260. sign = ''
  261. }
  262. pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
  263. pad_length = ph.width - (sign + arg).length
  264. pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
  265. output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
  266. }
  267. }
  268. }
  269. return output
  270. }
  271. var sprintf_cache = Object.create(null)
  272. function sprintf_parse(fmt) {
  273. if (sprintf_cache[fmt]) {
  274. return sprintf_cache[fmt]
  275. }
  276. var _fmt = fmt, match, parse_tree = [], arg_names = 0
  277. while (_fmt) {
  278. if ((match = re.text.exec(_fmt)) !== null) {
  279. parse_tree.push(match[0])
  280. }
  281. else if ((match = re.modulo.exec(_fmt)) !== null) {
  282. parse_tree.push('%')
  283. }
  284. else if ((match = re.placeholder.exec(_fmt)) !== null) {
  285. if (match[2]) {
  286. arg_names |= 1
  287. var field_list = [], replacement_field = match[2], field_match = []
  288. if ((field_match = re.key.exec(replacement_field)) !== null) {
  289. field_list.push(field_match[1])
  290. while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
  291. if ((field_match = re.key_access.exec(replacement_field)) !== null) {
  292. field_list.push(field_match[1])
  293. }
  294. else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
  295. field_list.push(field_match[1])
  296. }
  297. else {
  298. throw new SyntaxError('[sprintf] failed to parse named argument key')
  299. }
  300. }
  301. }
  302. else {
  303. throw new SyntaxError('[sprintf] failed to parse named argument key')
  304. }
  305. match[2] = field_list
  306. }
  307. else {
  308. arg_names |= 2
  309. }
  310. if (arg_names === 3) {
  311. throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
  312. }
  313. parse_tree.push(
  314. {
  315. placeholder: match[0],
  316. param_no: match[1],
  317. keys: match[2],
  318. sign: match[3],
  319. pad_char: match[4],
  320. align: match[5],
  321. width: match[6],
  322. precision: match[7],
  323. type: match[8]
  324. }
  325. )
  326. }
  327. else {
  328. throw new SyntaxError('[sprintf] unexpected placeholder')
  329. }
  330. _fmt = _fmt.substring(match[0].length)
  331. }
  332. return sprintf_cache[fmt] = parse_tree
  333. }
  334. /**
  335. * export to either browser or node.js
  336. */
  337. /* eslint-disable quote-props */
  338. if (true) {
  339. exports.sprintf = sprintf
  340. exports.vsprintf = vsprintf
  341. }
  342. if (typeof window !== 'undefined') {
  343. window['sprintf'] = sprintf
  344. window['vsprintf'] = vsprintf
  345. if (true) {
  346. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  347. return {
  348. 'sprintf': sprintf,
  349. 'vsprintf': vsprintf
  350. }
  351. }).call(exports, __webpack_require__, exports, module),
  352. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
  353. }
  354. }
  355. /* eslint-enable quote-props */
  356. }(); // eslint-disable-line
  357. /***/ })
  358. /******/ });
  359. /************************************************************************/
  360. /******/ // The module cache
  361. /******/ var __webpack_module_cache__ = {};
  362. /******/
  363. /******/ // The require function
  364. /******/ function __webpack_require__(moduleId) {
  365. /******/ // Check if module is in cache
  366. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  367. /******/ if (cachedModule !== undefined) {
  368. /******/ return cachedModule.exports;
  369. /******/ }
  370. /******/ // Create a new module (and put it into the cache)
  371. /******/ var module = __webpack_module_cache__[moduleId] = {
  372. /******/ // no module.id needed
  373. /******/ // no module.loaded needed
  374. /******/ exports: {}
  375. /******/ };
  376. /******/
  377. /******/ // Execute the module function
  378. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  379. /******/
  380. /******/ // Return the exports of the module
  381. /******/ return module.exports;
  382. /******/ }
  383. /******/
  384. /************************************************************************/
  385. /******/ /* webpack/runtime/compat get default export */
  386. /******/ !function() {
  387. /******/ // getDefaultExport function for compatibility with non-harmony modules
  388. /******/ __webpack_require__.n = function(module) {
  389. /******/ var getter = module && module.__esModule ?
  390. /******/ function() { return module['default']; } :
  391. /******/ function() { return module; };
  392. /******/ __webpack_require__.d(getter, { a: getter });
  393. /******/ return getter;
  394. /******/ };
  395. /******/ }();
  396. /******/
  397. /******/ /* webpack/runtime/define property getters */
  398. /******/ !function() {
  399. /******/ // define getter functions for harmony exports
  400. /******/ __webpack_require__.d = function(exports, definition) {
  401. /******/ for(var key in definition) {
  402. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  403. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  404. /******/ }
  405. /******/ }
  406. /******/ };
  407. /******/ }();
  408. /******/
  409. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  410. /******/ !function() {
  411. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  412. /******/ }();
  413. /******/
  414. /******/ /* webpack/runtime/make namespace object */
  415. /******/ !function() {
  416. /******/ // define __esModule on exports
  417. /******/ __webpack_require__.r = function(exports) {
  418. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  419. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  420. /******/ }
  421. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  422. /******/ };
  423. /******/ }();
  424. /******/
  425. /************************************************************************/
  426. var __webpack_exports__ = {};
  427. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  428. !function() {
  429. "use strict";
  430. // ESM COMPAT FLAG
  431. __webpack_require__.r(__webpack_exports__);
  432. // EXPORTS
  433. __webpack_require__.d(__webpack_exports__, {
  434. "__": function() { return /* reexport */ __; },
  435. "_n": function() { return /* reexport */ _n; },
  436. "_nx": function() { return /* reexport */ _nx; },
  437. "_x": function() { return /* reexport */ _x; },
  438. "createI18n": function() { return /* reexport */ createI18n; },
  439. "defaultI18n": function() { return /* reexport */ default_i18n; },
  440. "getLocaleData": function() { return /* reexport */ getLocaleData; },
  441. "hasTranslation": function() { return /* reexport */ hasTranslation; },
  442. "isRTL": function() { return /* reexport */ isRTL; },
  443. "resetLocaleData": function() { return /* reexport */ resetLocaleData; },
  444. "setLocaleData": function() { return /* reexport */ setLocaleData; },
  445. "sprintf": function() { return /* reexport */ sprintf_sprintf; },
  446. "subscribe": function() { return /* reexport */ subscribe; }
  447. });
  448. // EXTERNAL MODULE: ./node_modules/memize/index.js
  449. var memize = __webpack_require__(9756);
  450. var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
  451. // EXTERNAL MODULE: ./node_modules/sprintf-js/src/sprintf.js
  452. var sprintf = __webpack_require__(124);
  453. var sprintf_default = /*#__PURE__*/__webpack_require__.n(sprintf);
  454. ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/sprintf.js
  455. /**
  456. * External dependencies
  457. */
  458. /**
  459. * Log to console, once per message; or more precisely, per referentially equal
  460. * argument set. Because Jed throws errors, we log these to the console instead
  461. * to avoid crashing the application.
  462. *
  463. * @param {...*} args Arguments to pass to `console.error`
  464. */
  465. const logErrorOnce = memize_default()(console.error); // eslint-disable-line no-console
  466. /**
  467. * Returns a formatted string. If an error occurs in applying the format, the
  468. * original format string is returned.
  469. *
  470. * @param {string} format The format of the string to generate.
  471. * @param {...*} args Arguments to apply to the format.
  472. *
  473. * @see https://www.npmjs.com/package/sprintf-js
  474. *
  475. * @return {string} The formatted string.
  476. */
  477. function sprintf_sprintf(format) {
  478. try {
  479. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  480. args[_key - 1] = arguments[_key];
  481. }
  482. return sprintf_default().sprintf(format, ...args);
  483. } catch (error) {
  484. if (error instanceof Error) {
  485. logErrorOnce('sprintf error: \n\n' + error.toString());
  486. }
  487. return format;
  488. }
  489. }
  490. ;// CONCATENATED MODULE: ./node_modules/@tannin/postfix/index.js
  491. var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
  492. /**
  493. * Operator precedence mapping.
  494. *
  495. * @type {Object}
  496. */
  497. PRECEDENCE = {
  498. '(': 9,
  499. '!': 8,
  500. '*': 7,
  501. '/': 7,
  502. '%': 7,
  503. '+': 6,
  504. '-': 6,
  505. '<': 5,
  506. '<=': 5,
  507. '>': 5,
  508. '>=': 5,
  509. '==': 4,
  510. '!=': 4,
  511. '&&': 3,
  512. '||': 2,
  513. '?': 1,
  514. '?:': 1,
  515. };
  516. /**
  517. * Characters which signal pair opening, to be terminated by terminators.
  518. *
  519. * @type {string[]}
  520. */
  521. OPENERS = [ '(', '?' ];
  522. /**
  523. * Characters which signal pair termination, the value an array with the
  524. * opener as its first member. The second member is an optional operator
  525. * replacement to push to the stack.
  526. *
  527. * @type {string[]}
  528. */
  529. TERMINATORS = {
  530. ')': [ '(' ],
  531. ':': [ '?', '?:' ],
  532. };
  533. /**
  534. * Pattern matching operators and openers.
  535. *
  536. * @type {RegExp}
  537. */
  538. PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
  539. /**
  540. * Given a C expression, returns the equivalent postfix (Reverse Polish)
  541. * notation terms as an array.
  542. *
  543. * If a postfix string is desired, simply `.join( ' ' )` the result.
  544. *
  545. * @example
  546. *
  547. * ```js
  548. * import postfix from '@tannin/postfix';
  549. *
  550. * postfix( 'n > 1' );
  551. * // ⇒ [ 'n', '1', '>' ]
  552. * ```
  553. *
  554. * @param {string} expression C expression.
  555. *
  556. * @return {string[]} Postfix terms.
  557. */
  558. function postfix( expression ) {
  559. var terms = [],
  560. stack = [],
  561. match, operator, term, element;
  562. while ( ( match = expression.match( PATTERN ) ) ) {
  563. operator = match[ 0 ];
  564. // Term is the string preceding the operator match. It may contain
  565. // whitespace, and may be empty (if operator is at beginning).
  566. term = expression.substr( 0, match.index ).trim();
  567. if ( term ) {
  568. terms.push( term );
  569. }
  570. while ( ( element = stack.pop() ) ) {
  571. if ( TERMINATORS[ operator ] ) {
  572. if ( TERMINATORS[ operator ][ 0 ] === element ) {
  573. // Substitution works here under assumption that because
  574. // the assigned operator will no longer be a terminator, it
  575. // will be pushed to the stack during the condition below.
  576. operator = TERMINATORS[ operator ][ 1 ] || operator;
  577. break;
  578. }
  579. } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
  580. // Push to stack if either an opener or when pop reveals an
  581. // element of lower precedence.
  582. stack.push( element );
  583. break;
  584. }
  585. // For each popped from stack, push to terms.
  586. terms.push( element );
  587. }
  588. if ( ! TERMINATORS[ operator ] ) {
  589. stack.push( operator );
  590. }
  591. // Slice matched fragment from expression to continue match.
  592. expression = expression.substr( match.index + operator.length );
  593. }
  594. // Push remainder of operand, if exists, to terms.
  595. expression = expression.trim();
  596. if ( expression ) {
  597. terms.push( expression );
  598. }
  599. // Pop remaining items from stack into terms.
  600. return terms.concat( stack.reverse() );
  601. }
  602. ;// CONCATENATED MODULE: ./node_modules/@tannin/evaluate/index.js
  603. /**
  604. * Operator callback functions.
  605. *
  606. * @type {Object}
  607. */
  608. var OPERATORS = {
  609. '!': function( a ) {
  610. return ! a;
  611. },
  612. '*': function( a, b ) {
  613. return a * b;
  614. },
  615. '/': function( a, b ) {
  616. return a / b;
  617. },
  618. '%': function( a, b ) {
  619. return a % b;
  620. },
  621. '+': function( a, b ) {
  622. return a + b;
  623. },
  624. '-': function( a, b ) {
  625. return a - b;
  626. },
  627. '<': function( a, b ) {
  628. return a < b;
  629. },
  630. '<=': function( a, b ) {
  631. return a <= b;
  632. },
  633. '>': function( a, b ) {
  634. return a > b;
  635. },
  636. '>=': function( a, b ) {
  637. return a >= b;
  638. },
  639. '==': function( a, b ) {
  640. return a === b;
  641. },
  642. '!=': function( a, b ) {
  643. return a !== b;
  644. },
  645. '&&': function( a, b ) {
  646. return a && b;
  647. },
  648. '||': function( a, b ) {
  649. return a || b;
  650. },
  651. '?:': function( a, b, c ) {
  652. if ( a ) {
  653. throw b;
  654. }
  655. return c;
  656. },
  657. };
  658. /**
  659. * Given an array of postfix terms and operand variables, returns the result of
  660. * the postfix evaluation.
  661. *
  662. * @example
  663. *
  664. * ```js
  665. * import evaluate from '@tannin/evaluate';
  666. *
  667. * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
  668. * const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
  669. *
  670. * evaluate( terms, {} );
  671. * // ⇒ 6.333333333333334
  672. * ```
  673. *
  674. * @param {string[]} postfix Postfix terms.
  675. * @param {Object} variables Operand variables.
  676. *
  677. * @return {*} Result of evaluation.
  678. */
  679. function evaluate( postfix, variables ) {
  680. var stack = [],
  681. i, j, args, getOperatorResult, term, value;
  682. for ( i = 0; i < postfix.length; i++ ) {
  683. term = postfix[ i ];
  684. getOperatorResult = OPERATORS[ term ];
  685. if ( getOperatorResult ) {
  686. // Pop from stack by number of function arguments.
  687. j = getOperatorResult.length;
  688. args = Array( j );
  689. while ( j-- ) {
  690. args[ j ] = stack.pop();
  691. }
  692. try {
  693. value = getOperatorResult.apply( null, args );
  694. } catch ( earlyReturn ) {
  695. return earlyReturn;
  696. }
  697. } else if ( variables.hasOwnProperty( term ) ) {
  698. value = variables[ term ];
  699. } else {
  700. value = +term;
  701. }
  702. stack.push( value );
  703. }
  704. return stack[ 0 ];
  705. }
  706. ;// CONCATENATED MODULE: ./node_modules/@tannin/compile/index.js
  707. /**
  708. * Given a C expression, returns a function which can be called to evaluate its
  709. * result.
  710. *
  711. * @example
  712. *
  713. * ```js
  714. * import compile from '@tannin/compile';
  715. *
  716. * const evaluate = compile( 'n > 1' );
  717. *
  718. * evaluate( { n: 2 } );
  719. * // ⇒ true
  720. * ```
  721. *
  722. * @param {string} expression C expression.
  723. *
  724. * @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator.
  725. */
  726. function compile( expression ) {
  727. var terms = postfix( expression );
  728. return function( variables ) {
  729. return evaluate( terms, variables );
  730. };
  731. }
  732. ;// CONCATENATED MODULE: ./node_modules/@tannin/plural-forms/index.js
  733. /**
  734. * Given a C expression, returns a function which, when called with a value,
  735. * evaluates the result with the value assumed to be the "n" variable of the
  736. * expression. The result will be coerced to its numeric equivalent.
  737. *
  738. * @param {string} expression C expression.
  739. *
  740. * @return {Function} Evaluator function.
  741. */
  742. function pluralForms( expression ) {
  743. var evaluate = compile( expression );
  744. return function( n ) {
  745. return +evaluate( { n: n } );
  746. };
  747. }
  748. ;// CONCATENATED MODULE: ./node_modules/tannin/index.js
  749. /**
  750. * Tannin constructor options.
  751. *
  752. * @typedef {Object} TanninOptions
  753. *
  754. * @property {string} [contextDelimiter] Joiner in string lookup with context.
  755. * @property {Function} [onMissingKey] Callback to invoke when key missing.
  756. */
  757. /**
  758. * Domain metadata.
  759. *
  760. * @typedef {Object} TanninDomainMetadata
  761. *
  762. * @property {string} [domain] Domain name.
  763. * @property {string} [lang] Language code.
  764. * @property {(string|Function)} [plural_forms] Plural forms expression or
  765. * function evaluator.
  766. */
  767. /**
  768. * Domain translation pair respectively representing the singular and plural
  769. * translation.
  770. *
  771. * @typedef {[string,string]} TanninTranslation
  772. */
  773. /**
  774. * Locale data domain. The key is used as reference for lookup, the value an
  775. * array of two string entries respectively representing the singular and plural
  776. * translation.
  777. *
  778. * @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain
  779. */
  780. /**
  781. * Jed-formatted locale data.
  782. *
  783. * @see http://messageformat.github.io/Jed/
  784. *
  785. * @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData
  786. */
  787. /**
  788. * Default Tannin constructor options.
  789. *
  790. * @type {TanninOptions}
  791. */
  792. var DEFAULT_OPTIONS = {
  793. contextDelimiter: '\u0004',
  794. onMissingKey: null,
  795. };
  796. /**
  797. * Given a specific locale data's config `plural_forms` value, returns the
  798. * expression.
  799. *
  800. * @example
  801. *
  802. * ```
  803. * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
  804. * ```
  805. *
  806. * @param {string} pf Locale data plural forms.
  807. *
  808. * @return {string} Plural forms expression.
  809. */
  810. function getPluralExpression( pf ) {
  811. var parts, i, part;
  812. parts = pf.split( ';' );
  813. for ( i = 0; i < parts.length; i++ ) {
  814. part = parts[ i ].trim();
  815. if ( part.indexOf( 'plural=' ) === 0 ) {
  816. return part.substr( 7 );
  817. }
  818. }
  819. }
  820. /**
  821. * Tannin constructor.
  822. *
  823. * @class
  824. *
  825. * @param {TanninLocaleData} data Jed-formatted locale data.
  826. * @param {TanninOptions} [options] Tannin options.
  827. */
  828. function Tannin( data, options ) {
  829. var key;
  830. /**
  831. * Jed-formatted locale data.
  832. *
  833. * @name Tannin#data
  834. * @type {TanninLocaleData}
  835. */
  836. this.data = data;
  837. /**
  838. * Plural forms function cache, keyed by plural forms string.
  839. *
  840. * @name Tannin#pluralForms
  841. * @type {Object<string,Function>}
  842. */
  843. this.pluralForms = {};
  844. /**
  845. * Effective options for instance, including defaults.
  846. *
  847. * @name Tannin#options
  848. * @type {TanninOptions}
  849. */
  850. this.options = {};
  851. for ( key in DEFAULT_OPTIONS ) {
  852. this.options[ key ] = options !== undefined && key in options
  853. ? options[ key ]
  854. : DEFAULT_OPTIONS[ key ];
  855. }
  856. }
  857. /**
  858. * Returns the plural form index for the given domain and value.
  859. *
  860. * @param {string} domain Domain on which to calculate plural form.
  861. * @param {number} n Value for which plural form is to be calculated.
  862. *
  863. * @return {number} Plural form index.
  864. */
  865. Tannin.prototype.getPluralForm = function( domain, n ) {
  866. var getPluralForm = this.pluralForms[ domain ],
  867. config, plural, pf;
  868. if ( ! getPluralForm ) {
  869. config = this.data[ domain ][ '' ];
  870. pf = (
  871. config[ 'Plural-Forms' ] ||
  872. config[ 'plural-forms' ] ||
  873. // Ignore reason: As known, there's no way to document the empty
  874. // string property on a key to guarantee this as metadata.
  875. // @ts-ignore
  876. config.plural_forms
  877. );
  878. if ( typeof pf !== 'function' ) {
  879. plural = getPluralExpression(
  880. config[ 'Plural-Forms' ] ||
  881. config[ 'plural-forms' ] ||
  882. // Ignore reason: As known, there's no way to document the empty
  883. // string property on a key to guarantee this as metadata.
  884. // @ts-ignore
  885. config.plural_forms
  886. );
  887. pf = pluralForms( plural );
  888. }
  889. getPluralForm = this.pluralForms[ domain ] = pf;
  890. }
  891. return getPluralForm( n );
  892. };
  893. /**
  894. * Translate a string.
  895. *
  896. * @param {string} domain Translation domain.
  897. * @param {string|void} context Context distinguishing terms of the same name.
  898. * @param {string} singular Primary key for translation lookup.
  899. * @param {string=} plural Fallback value used for non-zero plural
  900. * form index.
  901. * @param {number=} n Value to use in calculating plural form.
  902. *
  903. * @return {string} Translated string.
  904. */
  905. Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
  906. var index, key, entry;
  907. if ( n === undefined ) {
  908. // Default to singular.
  909. index = 0;
  910. } else {
  911. // Find index by evaluating plural form for value.
  912. index = this.getPluralForm( domain, n );
  913. }
  914. key = singular;
  915. // If provided, context is prepended to key with delimiter.
  916. if ( context ) {
  917. key = context + this.options.contextDelimiter + singular;
  918. }
  919. entry = this.data[ domain ][ key ];
  920. // Verify not only that entry exists, but that the intended index is within
  921. // range and non-empty.
  922. if ( entry && entry[ index ] ) {
  923. return entry[ index ];
  924. }
  925. if ( this.options.onMissingKey ) {
  926. this.options.onMissingKey( singular, domain );
  927. }
  928. // If entry not found, fall back to singular vs. plural with zero index
  929. // representing the singular value.
  930. return index === 0 ? singular : plural;
  931. };
  932. ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/create-i18n.js
  933. /**
  934. * External dependencies
  935. */
  936. /**
  937. * @typedef {Record<string,any>} LocaleData
  938. */
  939. /**
  940. * Default locale data to use for Tannin domain when not otherwise provided.
  941. * Assumes an English plural forms expression.
  942. *
  943. * @type {LocaleData}
  944. */
  945. const DEFAULT_LOCALE_DATA = {
  946. '': {
  947. /** @param {number} n */
  948. plural_forms(n) {
  949. return n === 1 ? 0 : 1;
  950. }
  951. }
  952. };
  953. /*
  954. * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,
  955. * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.
  956. */
  957. const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
  958. /**
  959. * @typedef {(domain?: string) => LocaleData} GetLocaleData
  960. *
  961. * Returns locale data by domain in a
  962. * Jed-formatted JSON object shape.
  963. *
  964. * @see http://messageformat.github.io/Jed/
  965. */
  966. /**
  967. * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
  968. *
  969. * Merges locale data into the Tannin instance by domain. Note that this
  970. * function will overwrite the domain configuration. Accepts data in a
  971. * Jed-formatted JSON object shape.
  972. *
  973. * @see http://messageformat.github.io/Jed/
  974. */
  975. /**
  976. * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
  977. *
  978. * Merges locale data into the Tannin instance by domain. Note that this
  979. * function will also merge the domain configuration. Accepts data in a
  980. * Jed-formatted JSON object shape.
  981. *
  982. * @see http://messageformat.github.io/Jed/
  983. */
  984. /**
  985. * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
  986. *
  987. * Resets all current Tannin instance locale data and sets the specified
  988. * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  989. *
  990. * @see http://messageformat.github.io/Jed/
  991. */
  992. /** @typedef {() => void} SubscribeCallback */
  993. /** @typedef {() => void} UnsubscribeCallback */
  994. /**
  995. * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
  996. *
  997. * Subscribes to changes of locale data
  998. */
  999. /**
  1000. * @typedef {(domain?: string) => string} GetFilterDomain
  1001. * Retrieve the domain to use when calling domain-specific filters.
  1002. */
  1003. /**
  1004. * @typedef {(text: string, domain?: string) => string} __
  1005. *
  1006. * Retrieve the translation of text.
  1007. *
  1008. * @see https://developer.wordpress.org/reference/functions/__/
  1009. */
  1010. /**
  1011. * @typedef {(text: string, context: string, domain?: string) => string} _x
  1012. *
  1013. * Retrieve translated string with gettext context.
  1014. *
  1015. * @see https://developer.wordpress.org/reference/functions/_x/
  1016. */
  1017. /**
  1018. * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
  1019. *
  1020. * Translates and retrieves the singular or plural form based on the supplied
  1021. * number.
  1022. *
  1023. * @see https://developer.wordpress.org/reference/functions/_n/
  1024. */
  1025. /**
  1026. * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
  1027. *
  1028. * Translates and retrieves the singular or plural form based on the supplied
  1029. * number, with gettext context.
  1030. *
  1031. * @see https://developer.wordpress.org/reference/functions/_nx/
  1032. */
  1033. /**
  1034. * @typedef {() => boolean} IsRtl
  1035. *
  1036. * Check if current locale is RTL.
  1037. *
  1038. * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1039. * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1040. * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1041. * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1042. */
  1043. /**
  1044. * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
  1045. *
  1046. * Check if there is a translation for a given string in singular form.
  1047. */
  1048. /** @typedef {import('@wordpress/hooks').Hooks} Hooks */
  1049. /**
  1050. * An i18n instance
  1051. *
  1052. * @typedef I18n
  1053. * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
  1054. * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
  1055. * function will overwrite the domain configuration. Accepts data in a
  1056. * Jed-formatted JSON object shape.
  1057. * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
  1058. * function will also merge the domain configuration. Accepts data in a
  1059. * Jed-formatted JSON object shape.
  1060. * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
  1061. * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1062. * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.
  1063. * @property {__} __ Retrieve the translation of text.
  1064. * @property {_x} _x Retrieve translated string with gettext context.
  1065. * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied
  1066. * number.
  1067. * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied
  1068. * number, with gettext context.
  1069. * @property {IsRtl} isRTL Check if current locale is RTL.
  1070. * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.
  1071. */
  1072. /**
  1073. * Create an i18n instance
  1074. *
  1075. * @param {LocaleData} [initialData] Locale data configuration.
  1076. * @param {string} [initialDomain] Domain for which configuration applies.
  1077. * @param {Hooks} [hooks] Hooks implementation.
  1078. *
  1079. * @return {I18n} I18n instance.
  1080. */
  1081. const createI18n = (initialData, initialDomain, hooks) => {
  1082. /**
  1083. * The underlying instance of Tannin to which exported functions interface.
  1084. *
  1085. * @type {Tannin}
  1086. */
  1087. const tannin = new Tannin({});
  1088. const listeners = new Set();
  1089. const notifyListeners = () => {
  1090. listeners.forEach(listener => listener());
  1091. };
  1092. /**
  1093. * Subscribe to changes of locale data.
  1094. *
  1095. * @param {SubscribeCallback} callback Subscription callback.
  1096. * @return {UnsubscribeCallback} Unsubscribe callback.
  1097. */
  1098. const subscribe = callback => {
  1099. listeners.add(callback);
  1100. return () => listeners.delete(callback);
  1101. };
  1102. /** @type {GetLocaleData} */
  1103. const getLocaleData = function () {
  1104. let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
  1105. return tannin.data[domain];
  1106. };
  1107. /**
  1108. * @param {LocaleData} [data]
  1109. * @param {string} [domain]
  1110. */
  1111. const doSetLocaleData = function (data) {
  1112. var _tannin$data$domain;
  1113. let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
  1114. tannin.data[domain] = { ...tannin.data[domain],
  1115. ...data
  1116. }; // Populate default domain configuration (supported locale date which omits
  1117. // a plural forms expression).
  1118. tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
  1119. ...((_tannin$data$domain = tannin.data[domain]) === null || _tannin$data$domain === void 0 ? void 0 : _tannin$data$domain[''])
  1120. }; // Clean up cached plural forms functions cache as it might be updated.
  1121. delete tannin.pluralForms[domain];
  1122. };
  1123. /** @type {SetLocaleData} */
  1124. const setLocaleData = (data, domain) => {
  1125. doSetLocaleData(data, domain);
  1126. notifyListeners();
  1127. };
  1128. /** @type {AddLocaleData} */
  1129. const addLocaleData = function (data) {
  1130. var _tannin$data$domain2;
  1131. let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
  1132. tannin.data[domain] = { ...tannin.data[domain],
  1133. ...data,
  1134. // Populate default domain configuration (supported locale date which omits
  1135. // a plural forms expression).
  1136. '': { ...DEFAULT_LOCALE_DATA[''],
  1137. ...((_tannin$data$domain2 = tannin.data[domain]) === null || _tannin$data$domain2 === void 0 ? void 0 : _tannin$data$domain2['']),
  1138. ...(data === null || data === void 0 ? void 0 : data[''])
  1139. }
  1140. }; // Clean up cached plural forms functions cache as it might be updated.
  1141. delete tannin.pluralForms[domain];
  1142. notifyListeners();
  1143. };
  1144. /** @type {ResetLocaleData} */
  1145. const resetLocaleData = (data, domain) => {
  1146. // Reset all current Tannin locale data.
  1147. tannin.data = {}; // Reset cached plural forms functions cache.
  1148. tannin.pluralForms = {};
  1149. setLocaleData(data, domain);
  1150. };
  1151. /**
  1152. * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
  1153. * otherwise previously assigned.
  1154. *
  1155. * @param {string|undefined} domain Domain to retrieve the translated text.
  1156. * @param {string|undefined} context Context information for the translators.
  1157. * @param {string} single Text to translate if non-plural. Used as
  1158. * fallback return value on a caught error.
  1159. * @param {string} [plural] The text to be used if the number is
  1160. * plural.
  1161. * @param {number} [number] The number to compare against to use
  1162. * either the singular or plural form.
  1163. *
  1164. * @return {string} The translated string.
  1165. */
  1166. const dcnpgettext = function () {
  1167. let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
  1168. let context = arguments.length > 1 ? arguments[1] : undefined;
  1169. let single = arguments.length > 2 ? arguments[2] : undefined;
  1170. let plural = arguments.length > 3 ? arguments[3] : undefined;
  1171. let number = arguments.length > 4 ? arguments[4] : undefined;
  1172. if (!tannin.data[domain]) {
  1173. // Use `doSetLocaleData` to set silently, without notifying listeners.
  1174. doSetLocaleData(undefined, domain);
  1175. }
  1176. return tannin.dcnpgettext(domain, context, single, plural, number);
  1177. };
  1178. /** @type {GetFilterDomain} */
  1179. const getFilterDomain = function () {
  1180. let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
  1181. return domain;
  1182. };
  1183. /** @type {__} */
  1184. const __ = (text, domain) => {
  1185. let translation = dcnpgettext(domain, undefined, text);
  1186. if (!hooks) {
  1187. return translation;
  1188. }
  1189. /**
  1190. * Filters text with its translation.
  1191. *
  1192. * @param {string} translation Translated text.
  1193. * @param {string} text Text to translate.
  1194. * @param {string} domain Text domain. Unique identifier for retrieving translated strings.
  1195. */
  1196. translation =
  1197. /** @type {string} */
  1198. /** @type {*} */
  1199. hooks.applyFilters('i18n.gettext', translation, text, domain);
  1200. return (
  1201. /** @type {string} */
  1202. /** @type {*} */
  1203. hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain)
  1204. );
  1205. };
  1206. /** @type {_x} */
  1207. const _x = (text, context, domain) => {
  1208. let translation = dcnpgettext(domain, context, text);
  1209. if (!hooks) {
  1210. return translation;
  1211. }
  1212. /**
  1213. * Filters text with its translation based on context information.
  1214. *
  1215. * @param {string} translation Translated text.
  1216. * @param {string} text Text to translate.
  1217. * @param {string} context Context information for the translators.
  1218. * @param {string} domain Text domain. Unique identifier for retrieving translated strings.
  1219. */
  1220. translation =
  1221. /** @type {string} */
  1222. /** @type {*} */
  1223. hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
  1224. return (
  1225. /** @type {string} */
  1226. /** @type {*} */
  1227. hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain)
  1228. );
  1229. };
  1230. /** @type {_n} */
  1231. const _n = (single, plural, number, domain) => {
  1232. let translation = dcnpgettext(domain, undefined, single, plural, number);
  1233. if (!hooks) {
  1234. return translation;
  1235. }
  1236. /**
  1237. * Filters the singular or plural form of a string.
  1238. *
  1239. * @param {string} translation Translated text.
  1240. * @param {string} single The text to be used if the number is singular.
  1241. * @param {string} plural The text to be used if the number is plural.
  1242. * @param {string} number The number to compare against to use either the singular or plural form.
  1243. * @param {string} domain Text domain. Unique identifier for retrieving translated strings.
  1244. */
  1245. translation =
  1246. /** @type {string} */
  1247. /** @type {*} */
  1248. hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
  1249. return (
  1250. /** @type {string} */
  1251. /** @type {*} */
  1252. hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain)
  1253. );
  1254. };
  1255. /** @type {_nx} */
  1256. const _nx = (single, plural, number, context, domain) => {
  1257. let translation = dcnpgettext(domain, context, single, plural, number);
  1258. if (!hooks) {
  1259. return translation;
  1260. }
  1261. /**
  1262. * Filters the singular or plural form of a string with gettext context.
  1263. *
  1264. * @param {string} translation Translated text.
  1265. * @param {string} single The text to be used if the number is singular.
  1266. * @param {string} plural The text to be used if the number is plural.
  1267. * @param {string} number The number to compare against to use either the singular or plural form.
  1268. * @param {string} context Context information for the translators.
  1269. * @param {string} domain Text domain. Unique identifier for retrieving translated strings.
  1270. */
  1271. translation =
  1272. /** @type {string} */
  1273. /** @type {*} */
  1274. hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
  1275. return (
  1276. /** @type {string} */
  1277. /** @type {*} */
  1278. hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain)
  1279. );
  1280. };
  1281. /** @type {IsRtl} */
  1282. const isRTL = () => {
  1283. return 'rtl' === _x('ltr', 'text direction');
  1284. };
  1285. /** @type {HasTranslation} */
  1286. const hasTranslation = (single, context, domain) => {
  1287. var _tannin$data, _tannin$data2;
  1288. const key = context ? context + '\u0004' + single : single;
  1289. 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]);
  1290. if (hooks) {
  1291. /**
  1292. * Filters the presence of a translation in the locale data.
  1293. *
  1294. * @param {boolean} hasTranslation Whether the translation is present or not..
  1295. * @param {string} single The singular form of the translated text (used as key in locale data)
  1296. * @param {string} context Context information for the translators.
  1297. * @param {string} domain Text domain. Unique identifier for retrieving translated strings.
  1298. */
  1299. result =
  1300. /** @type { boolean } */
  1301. /** @type {*} */
  1302. hooks.applyFilters('i18n.has_translation', result, single, context, domain);
  1303. result =
  1304. /** @type { boolean } */
  1305. /** @type {*} */
  1306. hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
  1307. }
  1308. return result;
  1309. };
  1310. if (initialData) {
  1311. setLocaleData(initialData, initialDomain);
  1312. }
  1313. if (hooks) {
  1314. /**
  1315. * @param {string} hookName
  1316. */
  1317. const onHookAddedOrRemoved = hookName => {
  1318. if (I18N_HOOK_REGEXP.test(hookName)) {
  1319. notifyListeners();
  1320. }
  1321. };
  1322. hooks.addAction('hookAdded', 'core/i18n', onHookAddedOrRemoved);
  1323. hooks.addAction('hookRemoved', 'core/i18n', onHookAddedOrRemoved);
  1324. }
  1325. return {
  1326. getLocaleData,
  1327. setLocaleData,
  1328. addLocaleData,
  1329. resetLocaleData,
  1330. subscribe,
  1331. __,
  1332. _x,
  1333. _n,
  1334. _nx,
  1335. isRTL,
  1336. hasTranslation
  1337. };
  1338. };
  1339. ;// CONCATENATED MODULE: external ["wp","hooks"]
  1340. var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
  1341. ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/default-i18n.js
  1342. /**
  1343. * Internal dependencies
  1344. */
  1345. /**
  1346. * WordPress dependencies
  1347. */
  1348. const i18n = createI18n(undefined, undefined, external_wp_hooks_namespaceObject.defaultHooks);
  1349. /**
  1350. * Default, singleton instance of `I18n`.
  1351. */
  1352. /* harmony default export */ var default_i18n = (i18n);
  1353. /*
  1354. * Comments in this file are duplicated from ./i18n due to
  1355. * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
  1356. */
  1357. /**
  1358. * @typedef {import('./create-i18n').LocaleData} LocaleData
  1359. * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback
  1360. * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback
  1361. */
  1362. /**
  1363. * Returns locale data by domain in a Jed-formatted JSON object shape.
  1364. *
  1365. * @see http://messageformat.github.io/Jed/
  1366. *
  1367. * @param {string} [domain] Domain for which to get the data.
  1368. * @return {LocaleData} Locale data.
  1369. */
  1370. const getLocaleData = i18n.getLocaleData.bind(i18n);
  1371. /**
  1372. * Merges locale data into the Tannin instance by domain. Accepts data in a
  1373. * Jed-formatted JSON object shape.
  1374. *
  1375. * @see http://messageformat.github.io/Jed/
  1376. *
  1377. * @param {LocaleData} [data] Locale data configuration.
  1378. * @param {string} [domain] Domain for which configuration applies.
  1379. */
  1380. const setLocaleData = i18n.setLocaleData.bind(i18n);
  1381. /**
  1382. * Resets all current Tannin instance locale data and sets the specified
  1383. * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
  1384. *
  1385. * @see http://messageformat.github.io/Jed/
  1386. *
  1387. * @param {LocaleData} [data] Locale data configuration.
  1388. * @param {string} [domain] Domain for which configuration applies.
  1389. */
  1390. const resetLocaleData = i18n.resetLocaleData.bind(i18n);
  1391. /**
  1392. * Subscribes to changes of locale data
  1393. *
  1394. * @param {SubscribeCallback} callback Subscription callback
  1395. * @return {UnsubscribeCallback} Unsubscribe callback
  1396. */
  1397. const subscribe = i18n.subscribe.bind(i18n);
  1398. /**
  1399. * Retrieve the translation of text.
  1400. *
  1401. * @see https://developer.wordpress.org/reference/functions/__/
  1402. *
  1403. * @param {string} text Text to translate.
  1404. * @param {string} [domain] Domain to retrieve the translated text.
  1405. *
  1406. * @return {string} Translated text.
  1407. */
  1408. const __ = i18n.__.bind(i18n);
  1409. /**
  1410. * Retrieve translated string with gettext context.
  1411. *
  1412. * @see https://developer.wordpress.org/reference/functions/_x/
  1413. *
  1414. * @param {string} text Text to translate.
  1415. * @param {string} context Context information for the translators.
  1416. * @param {string} [domain] Domain to retrieve the translated text.
  1417. *
  1418. * @return {string} Translated context string without pipe.
  1419. */
  1420. const _x = i18n._x.bind(i18n);
  1421. /**
  1422. * Translates and retrieves the singular or plural form based on the supplied
  1423. * number.
  1424. *
  1425. * @see https://developer.wordpress.org/reference/functions/_n/
  1426. *
  1427. * @param {string} single The text to be used if the number is singular.
  1428. * @param {string} plural The text to be used if the number is plural.
  1429. * @param {number} number The number to compare against to use either the
  1430. * singular or plural form.
  1431. * @param {string} [domain] Domain to retrieve the translated text.
  1432. *
  1433. * @return {string} The translated singular or plural form.
  1434. */
  1435. const _n = i18n._n.bind(i18n);
  1436. /**
  1437. * Translates and retrieves the singular or plural form based on the supplied
  1438. * number, with gettext context.
  1439. *
  1440. * @see https://developer.wordpress.org/reference/functions/_nx/
  1441. *
  1442. * @param {string} single The text to be used if the number is singular.
  1443. * @param {string} plural The text to be used if the number is plural.
  1444. * @param {number} number The number to compare against to use either the
  1445. * singular or plural form.
  1446. * @param {string} context Context information for the translators.
  1447. * @param {string} [domain] Domain to retrieve the translated text.
  1448. *
  1449. * @return {string} The translated singular or plural form.
  1450. */
  1451. const _nx = i18n._nx.bind(i18n);
  1452. /**
  1453. * Check if current locale is RTL.
  1454. *
  1455. * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
  1456. * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
  1457. * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
  1458. * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
  1459. *
  1460. * @return {boolean} Whether locale is RTL.
  1461. */
  1462. const isRTL = i18n.isRTL.bind(i18n);
  1463. /**
  1464. * Check if there is a translation for a given string (in singular form).
  1465. *
  1466. * @param {string} single Singular form of the string to look up.
  1467. * @param {string} [context] Context information for the translators.
  1468. * @param {string} [domain] Domain to retrieve the translated text.
  1469. * @return {boolean} Whether the translation exists or not.
  1470. */
  1471. const hasTranslation = i18n.hasTranslation.bind(i18n);
  1472. ;// CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/index.js
  1473. }();
  1474. (window.wp = window.wp || {}).i18n = __webpack_exports__;
  1475. /******/ })()
  1476. ;