Geen omschrijving

i18n.js 50KB

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