i18n.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. this["wp"] = this["wp"] || {}; this["wp"]["i18n"] =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 360);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 10:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
  93. function _defineProperty(obj, key, value) {
  94. if (key in obj) {
  95. Object.defineProperty(obj, key, {
  96. value: value,
  97. enumerable: true,
  98. configurable: true,
  99. writable: true
  100. });
  101. } else {
  102. obj[key] = value;
  103. }
  104. return obj;
  105. }
  106. /***/ }),
  107. /***/ 146:
  108. /***/ (function(module, exports, __webpack_require__) {
  109. var __WEBPACK_AMD_DEFINE_RESULT__;/* global window, exports, define */
  110. !function() {
  111. 'use strict'
  112. var re = {
  113. not_string: /[^s]/,
  114. not_bool: /[^t]/,
  115. not_type: /[^T]/,
  116. not_primitive: /[^v]/,
  117. number: /[diefg]/,
  118. numeric_arg: /[bcdiefguxX]/,
  119. json: /[j]/,
  120. not_json: /[^j]/,
  121. text: /^[^\x25]+/,
  122. modulo: /^\x25{2}/,
  123. placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
  124. key: /^([a-z_][a-z_\d]*)/i,
  125. key_access: /^\.([a-z_][a-z_\d]*)/i,
  126. index_access: /^\[(\d+)\]/,
  127. sign: /^[+-]/
  128. }
  129. function sprintf(key) {
  130. // `arguments` is not an array, but should be fine for this call
  131. return sprintf_format(sprintf_parse(key), arguments)
  132. }
  133. function vsprintf(fmt, argv) {
  134. return sprintf.apply(null, [fmt].concat(argv || []))
  135. }
  136. function sprintf_format(parse_tree, argv) {
  137. var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
  138. for (i = 0; i < tree_length; i++) {
  139. if (typeof parse_tree[i] === 'string') {
  140. output += parse_tree[i]
  141. }
  142. else if (typeof parse_tree[i] === 'object') {
  143. ph = parse_tree[i] // convenience purposes only
  144. if (ph.keys) { // keyword argument
  145. arg = argv[cursor]
  146. for (k = 0; k < ph.keys.length; k++) {
  147. if (arg == undefined) {
  148. throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
  149. }
  150. arg = arg[ph.keys[k]]
  151. }
  152. }
  153. else if (ph.param_no) { // positional argument (explicit)
  154. arg = argv[ph.param_no]
  155. }
  156. else { // positional argument (implicit)
  157. arg = argv[cursor++]
  158. }
  159. if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
  160. arg = arg()
  161. }
  162. if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
  163. throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
  164. }
  165. if (re.number.test(ph.type)) {
  166. is_positive = arg >= 0
  167. }
  168. switch (ph.type) {
  169. case 'b':
  170. arg = parseInt(arg, 10).toString(2)
  171. break
  172. case 'c':
  173. arg = String.fromCharCode(parseInt(arg, 10))
  174. break
  175. case 'd':
  176. case 'i':
  177. arg = parseInt(arg, 10)
  178. break
  179. case 'j':
  180. arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
  181. break
  182. case 'e':
  183. arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
  184. break
  185. case 'f':
  186. arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
  187. break
  188. case 'g':
  189. arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
  190. break
  191. case 'o':
  192. arg = (parseInt(arg, 10) >>> 0).toString(8)
  193. break
  194. case 's':
  195. arg = String(arg)
  196. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  197. break
  198. case 't':
  199. arg = String(!!arg)
  200. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  201. break
  202. case 'T':
  203. arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
  204. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  205. break
  206. case 'u':
  207. arg = parseInt(arg, 10) >>> 0
  208. break
  209. case 'v':
  210. arg = arg.valueOf()
  211. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  212. break
  213. case 'x':
  214. arg = (parseInt(arg, 10) >>> 0).toString(16)
  215. break
  216. case 'X':
  217. arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
  218. break
  219. }
  220. if (re.json.test(ph.type)) {
  221. output += arg
  222. }
  223. else {
  224. if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
  225. sign = is_positive ? '+' : '-'
  226. arg = arg.toString().replace(re.sign, '')
  227. }
  228. else {
  229. sign = ''
  230. }
  231. pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
  232. pad_length = ph.width - (sign + arg).length
  233. pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
  234. output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
  235. }
  236. }
  237. }
  238. return output
  239. }
  240. var sprintf_cache = Object.create(null)
  241. function sprintf_parse(fmt) {
  242. if (sprintf_cache[fmt]) {
  243. return sprintf_cache[fmt]
  244. }
  245. var _fmt = fmt, match, parse_tree = [], arg_names = 0
  246. while (_fmt) {
  247. if ((match = re.text.exec(_fmt)) !== null) {
  248. parse_tree.push(match[0])
  249. }
  250. else if ((match = re.modulo.exec(_fmt)) !== null) {
  251. parse_tree.push('%')
  252. }
  253. else if ((match = re.placeholder.exec(_fmt)) !== null) {
  254. if (match[2]) {
  255. arg_names |= 1
  256. var field_list = [], replacement_field = match[2], field_match = []
  257. if ((field_match = re.key.exec(replacement_field)) !== null) {
  258. field_list.push(field_match[1])
  259. while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
  260. if ((field_match = re.key_access.exec(replacement_field)) !== null) {
  261. field_list.push(field_match[1])
  262. }
  263. else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
  264. field_list.push(field_match[1])
  265. }
  266. else {
  267. throw new SyntaxError('[sprintf] failed to parse named argument key')
  268. }
  269. }
  270. }
  271. else {
  272. throw new SyntaxError('[sprintf] failed to parse named argument key')
  273. }
  274. match[2] = field_list
  275. }
  276. else {
  277. arg_names |= 2
  278. }
  279. if (arg_names === 3) {
  280. throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
  281. }
  282. parse_tree.push(
  283. {
  284. placeholder: match[0],
  285. param_no: match[1],
  286. keys: match[2],
  287. sign: match[3],
  288. pad_char: match[4],
  289. align: match[5],
  290. width: match[6],
  291. precision: match[7],
  292. type: match[8]
  293. }
  294. )
  295. }
  296. else {
  297. throw new SyntaxError('[sprintf] unexpected placeholder')
  298. }
  299. _fmt = _fmt.substring(match[0].length)
  300. }
  301. return sprintf_cache[fmt] = parse_tree
  302. }
  303. /**
  304. * export to either browser or node.js
  305. */
  306. /* eslint-disable quote-props */
  307. if (true) {
  308. exports['sprintf'] = sprintf
  309. exports['vsprintf'] = vsprintf
  310. }
  311. if (typeof window !== 'undefined') {
  312. window['sprintf'] = sprintf
  313. window['vsprintf'] = vsprintf
  314. if (true) {
  315. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  316. return {
  317. 'sprintf': sprintf,
  318. 'vsprintf': vsprintf
  319. }
  320. }).call(exports, __webpack_require__, exports, module),
  321. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
  322. }
  323. }
  324. /* eslint-enable quote-props */
  325. }(); // eslint-disable-line
  326. /***/ }),
  327. /***/ 360:
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread.js
  332. var objectSpread = __webpack_require__(7);
  333. // CONCATENATED MODULE: ./node_modules/@tannin/postfix/index.js
  334. var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
  335. /**
  336. * Operator precedence mapping.
  337. *
  338. * @type {Object}
  339. */
  340. PRECEDENCE = {
  341. '(': 9,
  342. '!': 8,
  343. '*': 7,
  344. '/': 7,
  345. '%': 7,
  346. '+': 6,
  347. '-': 6,
  348. '<': 5,
  349. '<=': 5,
  350. '>': 5,
  351. '>=': 5,
  352. '==': 4,
  353. '!=': 4,
  354. '&&': 3,
  355. '||': 2,
  356. '?': 1,
  357. '?:': 1,
  358. };
  359. /**
  360. * Characters which signal pair opening, to be terminated by terminators.
  361. *
  362. * @type {string[]}
  363. */
  364. OPENERS = [ '(', '?' ];
  365. /**
  366. * Characters which signal pair termination, the value an array with the
  367. * opener as its first member. The second member is an optional operator
  368. * replacement to push to the stack.
  369. *
  370. * @type {string[]}
  371. */
  372. TERMINATORS = {
  373. ')': [ '(' ],
  374. ':': [ '?', '?:' ],
  375. };
  376. /**
  377. * Pattern matching operators and openers.
  378. *
  379. * @type {RegExp}
  380. */
  381. PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
  382. /**
  383. * Given a C expression, returns the equivalent postfix (Reverse Polish)
  384. * notation terms as an array.
  385. *
  386. * If a postfix string is desired, simply `.join( ' ' )` the result.
  387. *
  388. * @example
  389. *
  390. * ```js
  391. * import postfix from '@tannin/postfix';
  392. *
  393. * postfix( 'n > 1' );
  394. * // ⇒ [ 'n', '1', '>' ]
  395. * ```
  396. *
  397. * @param {string} expression C expression.
  398. *
  399. * @return {string[]} Postfix terms.
  400. */
  401. function postfix( expression ) {
  402. var terms = [],
  403. stack = [],
  404. match, operator, term, element;
  405. while ( ( match = expression.match( PATTERN ) ) ) {
  406. operator = match[ 0 ];
  407. // Term is the string preceding the operator match. It may contain
  408. // whitespace, and may be empty (if operator is at beginning).
  409. term = expression.substr( 0, match.index ).trim();
  410. if ( term ) {
  411. terms.push( term );
  412. }
  413. while ( ( element = stack.pop() ) ) {
  414. if ( TERMINATORS[ operator ] ) {
  415. if ( TERMINATORS[ operator ][ 0 ] === element ) {
  416. // Substitution works here under assumption that because
  417. // the assigned operator will no longer be a terminator, it
  418. // will be pushed to the stack during the condition below.
  419. operator = TERMINATORS[ operator ][ 1 ] || operator;
  420. break;
  421. }
  422. } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) {
  423. // Push to stack if either an opener or when pop reveals an
  424. // element of lower precedence.
  425. stack.push( element );
  426. break;
  427. }
  428. // For each popped from stack, push to terms.
  429. terms.push( element );
  430. }
  431. if ( ! TERMINATORS[ operator ] ) {
  432. stack.push( operator );
  433. }
  434. // Slice matched fragment from expression to continue match.
  435. expression = expression.substr( match.index + operator.length );
  436. }
  437. // Push remainder of operand, if exists, to terms.
  438. expression = expression.trim();
  439. if ( expression ) {
  440. terms.push( expression );
  441. }
  442. // Pop remaining items from stack into terms.
  443. return terms.concat( stack.reverse() );
  444. }
  445. // CONCATENATED MODULE: ./node_modules/@tannin/evaluate/index.js
  446. /**
  447. * Operator callback functions.
  448. *
  449. * @type {Object}
  450. */
  451. var OPERATORS = {
  452. '!': function( a ) {
  453. return ! a;
  454. },
  455. '*': function( a, b ) {
  456. return a * b;
  457. },
  458. '/': function( a, b ) {
  459. return a / b;
  460. },
  461. '%': function( a, b ) {
  462. return a % b;
  463. },
  464. '+': function( a, b ) {
  465. return a + b;
  466. },
  467. '-': function( a, b ) {
  468. return a - b;
  469. },
  470. '<': function( a, b ) {
  471. return a < b;
  472. },
  473. '<=': function( a, b ) {
  474. return a <= b;
  475. },
  476. '>': function( a, b ) {
  477. return a > b;
  478. },
  479. '>=': function( a, b ) {
  480. return a >= b;
  481. },
  482. '==': function( a, b ) {
  483. return a === b;
  484. },
  485. '!=': function( a, b ) {
  486. return a !== b;
  487. },
  488. '&&': function( a, b ) {
  489. return a && b;
  490. },
  491. '||': function( a, b ) {
  492. return a || b;
  493. },
  494. '?:': function( a, b, c ) {
  495. if ( a ) {
  496. throw b;
  497. }
  498. return c;
  499. },
  500. };
  501. /**
  502. * Given an array of postfix terms and operand variables, returns the result of
  503. * the postfix evaluation.
  504. *
  505. * @example
  506. *
  507. * ```js
  508. * import evaluate from '@tannin/evaluate';
  509. *
  510. * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +'
  511. * const terms = [ '3', '4', '5', '*', '6', '/', '+' ];
  512. *
  513. * evaluate( terms, {} );
  514. * // ⇒ 6.333333333333334
  515. * ```
  516. *
  517. * @param {string[]} postfix Postfix terms.
  518. * @param {Object} variables Operand variables.
  519. *
  520. * @return {*} Result of evaluation.
  521. */
  522. function evaluate_evaluate( postfix, variables ) {
  523. var stack = [],
  524. i, j, args, getOperatorResult, term, value;
  525. for ( i = 0; i < postfix.length; i++ ) {
  526. term = postfix[ i ];
  527. getOperatorResult = OPERATORS[ term ];
  528. if ( getOperatorResult ) {
  529. // Pop from stack by number of function arguments.
  530. j = getOperatorResult.length;
  531. args = Array( j );
  532. while ( j-- ) {
  533. args[ j ] = stack.pop();
  534. }
  535. try {
  536. value = getOperatorResult.apply( null, args );
  537. } catch ( earlyReturn ) {
  538. return earlyReturn;
  539. }
  540. } else if ( variables.hasOwnProperty( term ) ) {
  541. value = variables[ term ];
  542. } else {
  543. value = +term;
  544. }
  545. stack.push( value );
  546. }
  547. return stack[ 0 ];
  548. }
  549. // CONCATENATED MODULE: ./node_modules/@tannin/compile/index.js
  550. /**
  551. * Given a C expression, returns a function which can be called to evaluate its
  552. * result.
  553. *
  554. * @example
  555. *
  556. * ```js
  557. * import compile from '@tannin/compile';
  558. *
  559. * const evaluate = compile( 'n > 1' );
  560. *
  561. * evaluate( { n: 2 } );
  562. * // ⇒ true
  563. * ```
  564. *
  565. * @param {string} expression C expression.
  566. *
  567. * @return {Function} Compiled evaluator.
  568. */
  569. function compile( expression ) {
  570. var terms = postfix( expression );
  571. return function( variables ) {
  572. return evaluate_evaluate( terms, variables );
  573. };
  574. }
  575. // CONCATENATED MODULE: ./node_modules/@tannin/plural-forms/index.js
  576. /**
  577. * Given a C expression, returns a function which, when called with a value,
  578. * evaluates the result with the value assumed to be the "n" variable of the
  579. * expression. The result will be coerced to its numeric equivalent.
  580. *
  581. * @param {string} expression C expression.
  582. *
  583. * @return {Function} Evaluator function.
  584. */
  585. function pluralForms( expression ) {
  586. var evaluate = compile( expression );
  587. return function( n ) {
  588. return +evaluate( { n: n } );
  589. };
  590. }
  591. // CONCATENATED MODULE: ./node_modules/tannin/index.js
  592. /**
  593. * Tannin constructor options.
  594. *
  595. * @property {?string} contextDelimiter Joiner in string lookup with context.
  596. * @property {?Function} onMissingKey Callback to invoke when key missing.
  597. *
  598. * @type {Object}
  599. *
  600. * @typedef {TanninOptions}
  601. */
  602. /**
  603. * Default Tannin constructor options.
  604. *
  605. * @type {TanninOptions}
  606. */
  607. var DEFAULT_OPTIONS = {
  608. contextDelimiter: '\u0004',
  609. onMissingKey: null,
  610. };
  611. /**
  612. * Given a specific locale data's config `plural_forms` value, returns the
  613. * expression.
  614. *
  615. * @example
  616. *
  617. * ```
  618. * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)'
  619. * ```
  620. *
  621. * @param {string} pf Locale data plural forms.
  622. *
  623. * @return {string} Plural forms expression.
  624. */
  625. function getPluralExpression( pf ) {
  626. var parts, i, part;
  627. parts = pf.split( ';' );
  628. for ( i = 0; i < parts.length; i++ ) {
  629. part = parts[ i ].trim();
  630. if ( part.indexOf( 'plural=' ) === 0 ) {
  631. return part.substr( 7 );
  632. }
  633. }
  634. }
  635. /**
  636. * Tannin constructor.
  637. *
  638. * @param {Object} data Jed-formatted locale data.
  639. * @param {TanninOptions} options Tannin options.
  640. */
  641. function Tannin( data, options ) {
  642. var key;
  643. this.data = data;
  644. this.pluralForms = {};
  645. options = options || {};
  646. this.options = {};
  647. for ( key in DEFAULT_OPTIONS ) {
  648. this.options[ key ] = options[ key ] || DEFAULT_OPTIONS[ key ];
  649. }
  650. }
  651. /**
  652. * Returns the plural form index for the given domain and value.
  653. *
  654. * @param {string} domain Domain on which to calculate plural form.
  655. * @param {number} n Value for which plural form is to be calculated.
  656. *
  657. * @return {number} Plural form index.
  658. */
  659. Tannin.prototype.getPluralForm = function( domain, n ) {
  660. var getPluralForm = this.pluralForms[ domain ],
  661. config, plural, pf;
  662. if ( ! getPluralForm ) {
  663. config = this.data[ domain ][ '' ];
  664. pf = (
  665. config[ 'Plural-Forms' ] ||
  666. config[ 'plural-forms' ] ||
  667. config.plural_forms
  668. );
  669. if ( typeof pf !== 'function' ) {
  670. plural = getPluralExpression(
  671. config[ 'Plural-Forms' ] ||
  672. config[ 'plural-forms' ] ||
  673. config.plural_forms
  674. );
  675. pf = pluralForms( plural );
  676. }
  677. getPluralForm = this.pluralForms[ domain ] = pf;
  678. }
  679. return getPluralForm( n );
  680. };
  681. /**
  682. * Translate a string.
  683. *
  684. * @param {string} domain Translation domain.
  685. * @param {string} context Context distinguishing terms of the same name.
  686. * @param {string} singular Primary key for translation lookup.
  687. * @param {string} plural Fallback value used for non-zero plural form index.
  688. * @param {number} n Value to use in calculating plural form.
  689. *
  690. * @return {string} Translated string.
  691. */
  692. Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) {
  693. var index, key, entry;
  694. if ( n === undefined ) {
  695. // Default to singular.
  696. index = 0;
  697. } else {
  698. // Find index by evaluating plural form for value.
  699. index = this.getPluralForm( domain, n );
  700. }
  701. key = singular;
  702. // If provided, context is prepended to key with delimiter.
  703. if ( context ) {
  704. key = context + this.options.contextDelimiter + singular;
  705. }
  706. entry = this.data[ domain ][ key ];
  707. // Verify not only that entry exists, but that the intended index is within
  708. // range and non-empty.
  709. if ( entry && entry[ index ] ) {
  710. return entry[ index ];
  711. }
  712. if ( this.options.onMissingKey ) {
  713. this.options.onMissingKey( singular, domain );
  714. }
  715. // If entry not found, fall back to singular vs. plural with zero index
  716. // representing the singular value.
  717. return index === 0 ? singular : plural;
  718. };
  719. // EXTERNAL MODULE: ./node_modules/memize/index.js
  720. var memize = __webpack_require__(44);
  721. var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
  722. // EXTERNAL MODULE: ./node_modules/sprintf-js/src/sprintf.js
  723. var sprintf = __webpack_require__(146);
  724. var sprintf_default = /*#__PURE__*/__webpack_require__.n(sprintf);
  725. // CONCATENATED MODULE: ./node_modules/@wordpress/i18n/build-module/index.js
  726. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setLocaleData", function() { return setLocaleData; });
  727. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__", function() { return __; });
  728. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_x", function() { return _x; });
  729. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_n", function() { return _n; });
  730. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_nx", function() { return _nx; });
  731. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sprintf", function() { return build_module_sprintf; });
  732. /**
  733. * External dependencies
  734. */
  735. /**
  736. * Default locale data to use for Tannin domain when not otherwise provided.
  737. * Assumes an English plural forms expression.
  738. *
  739. * @type {Object}
  740. */
  741. var DEFAULT_LOCALE_DATA = {
  742. '': {
  743. plural_forms: function plural_forms(n) {
  744. return n === 1 ? 0 : 1;
  745. }
  746. }
  747. };
  748. /**
  749. * Log to console, once per message; or more precisely, per referentially equal
  750. * argument set. Because Jed throws errors, we log these to the console instead
  751. * to avoid crashing the application.
  752. *
  753. * @param {...*} args Arguments to pass to `console.error`
  754. */
  755. var logErrorOnce = memize_default()(console.error); // eslint-disable-line no-console
  756. /**
  757. * The underlying instance of Tannin to which exported functions interface.
  758. *
  759. * @type {Tannin}
  760. */
  761. var i18n = new Tannin({});
  762. /**
  763. * Merges locale data into the Tannin instance by domain. Accepts data in a
  764. * Jed-formatted JSON object shape.
  765. *
  766. * @see http://messageformat.github.io/Jed/
  767. *
  768. * @param {?Object} data Locale data configuration.
  769. * @param {?string} domain Domain for which configuration applies.
  770. */
  771. function setLocaleData(data) {
  772. var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
  773. i18n.data[domain] = Object(objectSpread["a" /* default */])({}, DEFAULT_LOCALE_DATA, i18n.data[domain], data); // Populate default domain configuration (supported locale date which omits
  774. // a plural forms expression).
  775. i18n.data[domain][''] = Object(objectSpread["a" /* default */])({}, DEFAULT_LOCALE_DATA[''], i18n.data[domain]['']);
  776. }
  777. /**
  778. * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
  779. * otherwise previously assigned.
  780. *
  781. * @param {?string} domain Domain to retrieve the translated text.
  782. * @param {?string} context Context information for the translators.
  783. * @param {string} single Text to translate if non-plural. Used as fallback
  784. * return value on a caught error.
  785. * @param {?string} plural The text to be used if the number is plural.
  786. * @param {?number} number The number to compare against to use either the
  787. * singular or plural form.
  788. *
  789. * @return {string} The translated string.
  790. */
  791. function dcnpgettext() {
  792. var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
  793. var context = arguments.length > 1 ? arguments[1] : undefined;
  794. var single = arguments.length > 2 ? arguments[2] : undefined;
  795. var plural = arguments.length > 3 ? arguments[3] : undefined;
  796. var number = arguments.length > 4 ? arguments[4] : undefined;
  797. if (!i18n.data[domain]) {
  798. setLocaleData(undefined, domain);
  799. }
  800. return i18n.dcnpgettext(domain, context, single, plural, number);
  801. }
  802. /**
  803. * Retrieve the translation of text.
  804. *
  805. * @see https://developer.wordpress.org/reference/functions/__/
  806. *
  807. * @param {string} text Text to translate.
  808. * @param {?string} domain Domain to retrieve the translated text.
  809. *
  810. * @return {string} Translated text.
  811. */
  812. function __(text, domain) {
  813. return dcnpgettext(domain, undefined, text);
  814. }
  815. /**
  816. * Retrieve translated string with gettext context.
  817. *
  818. * @see https://developer.wordpress.org/reference/functions/_x/
  819. *
  820. * @param {string} text Text to translate.
  821. * @param {string} context Context information for the translators.
  822. * @param {?string} domain Domain to retrieve the translated text.
  823. *
  824. * @return {string} Translated context string without pipe.
  825. */
  826. function _x(text, context, domain) {
  827. return dcnpgettext(domain, context, text);
  828. }
  829. /**
  830. * Translates and retrieves the singular or plural form based on the supplied
  831. * number.
  832. *
  833. * @see https://developer.wordpress.org/reference/functions/_n/
  834. *
  835. * @param {string} single The text to be used if the number is singular.
  836. * @param {string} plural The text to be used if the number is plural.
  837. * @param {number} number The number to compare against to use either the
  838. * singular or plural form.
  839. * @param {?string} domain Domain to retrieve the translated text.
  840. *
  841. * @return {string} The translated singular or plural form.
  842. */
  843. function _n(single, plural, number, domain) {
  844. return dcnpgettext(domain, undefined, single, plural, number);
  845. }
  846. /**
  847. * Translates and retrieves the singular or plural form based on the supplied
  848. * number, with gettext context.
  849. *
  850. * @see https://developer.wordpress.org/reference/functions/_nx/
  851. *
  852. * @param {string} single The text to be used if the number is singular.
  853. * @param {string} plural The text to be used if the number is plural.
  854. * @param {number} number The number to compare against to use either the
  855. * singular or plural form.
  856. * @param {string} context Context information for the translators.
  857. * @param {?string} domain Domain to retrieve the translated text.
  858. *
  859. * @return {string} The translated singular or plural form.
  860. */
  861. function _nx(single, plural, number, context, domain) {
  862. return dcnpgettext(domain, context, single, plural, number);
  863. }
  864. /**
  865. * Returns a formatted string. If an error occurs in applying the format, the
  866. * original format string is returned.
  867. *
  868. * @param {string} format The format of the string to generate.
  869. * @param {...string} args Arguments to apply to the format.
  870. *
  871. * @see http://www.diveintojavascript.com/projects/javascript-sprintf
  872. *
  873. * @return {string} The formatted string.
  874. */
  875. function build_module_sprintf(format) {
  876. try {
  877. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  878. args[_key - 1] = arguments[_key];
  879. }
  880. return sprintf_default.a.sprintf.apply(sprintf_default.a, [format].concat(args));
  881. } catch (error) {
  882. logErrorOnce('sprintf error: \n\n' + error.toString());
  883. return format;
  884. }
  885. }
  886. /***/ }),
  887. /***/ 44:
  888. /***/ (function(module, exports, __webpack_require__) {
  889. module.exports = function memize( fn, options ) {
  890. var size = 0,
  891. maxSize, head, tail;
  892. if ( options && options.maxSize ) {
  893. maxSize = options.maxSize;
  894. }
  895. function memoized( /* ...args */ ) {
  896. var node = head,
  897. len = arguments.length,
  898. args, i;
  899. searchCache: while ( node ) {
  900. // Perform a shallow equality test to confirm that whether the node
  901. // under test is a candidate for the arguments passed. Two arrays
  902. // are shallowly equal if their length matches and each entry is
  903. // strictly equal between the two sets. Avoid abstracting to a
  904. // function which could incur an arguments leaking deoptimization.
  905. // Check whether node arguments match arguments length
  906. if ( node.args.length !== arguments.length ) {
  907. node = node.next;
  908. continue;
  909. }
  910. // Check whether node arguments match arguments values
  911. for ( i = 0; i < len; i++ ) {
  912. if ( node.args[ i ] !== arguments[ i ] ) {
  913. node = node.next;
  914. continue searchCache;
  915. }
  916. }
  917. // At this point we can assume we've found a match
  918. // Surface matched node to head if not already
  919. if ( node !== head ) {
  920. // As tail, shift to previous. Must only shift if not also
  921. // head, since if both head and tail, there is no previous.
  922. if ( node === tail ) {
  923. tail = node.prev;
  924. }
  925. // Adjust siblings to point to each other. If node was tail,
  926. // this also handles new tail's empty `next` assignment.
  927. node.prev.next = node.next;
  928. if ( node.next ) {
  929. node.next.prev = node.prev;
  930. }
  931. node.next = head;
  932. node.prev = null;
  933. head.prev = node;
  934. head = node;
  935. }
  936. // Return immediately
  937. return node.val;
  938. }
  939. // No cached value found. Continue to insertion phase:
  940. // Create a copy of arguments (avoid leaking deoptimization)
  941. args = new Array( len );
  942. for ( i = 0; i < len; i++ ) {
  943. args[ i ] = arguments[ i ];
  944. }
  945. node = {
  946. args: args,
  947. // Generate the result from original function
  948. val: fn.apply( null, args )
  949. };
  950. // Don't need to check whether node is already head, since it would
  951. // have been returned above already if it was
  952. // Shift existing head down list
  953. if ( head ) {
  954. head.prev = node;
  955. node.next = head;
  956. } else {
  957. // If no head, follows that there's no tail (at initial or reset)
  958. tail = node;
  959. }
  960. // Trim tail if we're reached max size and are pending cache insertion
  961. if ( size === maxSize ) {
  962. tail = tail.prev;
  963. tail.next = null;
  964. } else {
  965. size++;
  966. }
  967. head = node;
  968. return node.val;
  969. }
  970. memoized.clear = function() {
  971. head = null;
  972. tail = null;
  973. size = 0;
  974. };
  975. if ( false ) {}
  976. return memoized;
  977. };
  978. /***/ }),
  979. /***/ 7:
  980. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  981. "use strict";
  982. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectSpread; });
  983. /* harmony import */ var _defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10);
  984. function _objectSpread(target) {
  985. for (var i = 1; i < arguments.length; i++) {
  986. var source = arguments[i] != null ? arguments[i] : {};
  987. var ownKeys = Object.keys(source);
  988. if (typeof Object.getOwnPropertySymbols === 'function') {
  989. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  990. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  991. }));
  992. }
  993. ownKeys.forEach(function (key) {
  994. Object(_defineProperty__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(target, key, source[key]);
  995. });
  996. }
  997. return target;
  998. }
  999. /***/ })
  1000. /******/ });