textbrowser 0.46.1 → 0.46.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGES to `textbrowser`
2
2
 
3
+ ## 0.46.3
4
+
5
+ - fix: update `intl-dom` (affecting fallbacks for non-English locales)
6
+
7
+ ## 0.46.2
8
+
9
+ - fix: ensure `fetch` is set on server for locale retrieval for `/textbrowser`
10
+
3
11
  ## 0.46.1
4
12
 
5
13
  - fix: regression with live data
package/README.md CHANGED
@@ -748,6 +748,10 @@ it supports the following arguments:
748
748
  ## To-dos (Highest priority)
749
749
 
750
750
  1. Progressive web app? / Electron?
751
+ 1. Fix regression upon converting from `imf` to `intl-dom` that locales
752
+ do not properly default (to English) when missing and give errors
753
+ 1. Figure out why `/textbrowser?lang=...` isn't working now on
754
+ <https://bahai-browser.org> despite working locally
751
755
  1. Adapt approach of <https://suttacentral.net/offline> in providing form for
752
756
  choice of items to offline (also add to individual work pages).
753
757
  1. Mention idea that it works offline
@@ -223,7 +223,7 @@ let nodeFetch;
223
223
  * @returns {getJSONCallback}
224
224
  */
225
225
 
226
- function _invoke(body, then) {
226
+ function _invoke$2(body, then) {
227
227
  var result = body();
228
228
 
229
229
  if (result && result.then) {
@@ -266,9 +266,9 @@ function buildGetJSON({
266
266
  } = {}) {
267
267
  const _fetch = typeof fetch !== 'undefined' ? fetch : _async$2(function (jsonURL) {
268
268
  let _exit = false;
269
- return _invoke(function () {
269
+ return _invoke$2(function () {
270
270
  if (/^https?:/u.test(jsonURL)) {
271
- return _invoke(function () {
271
+ return _invoke$2(function () {
272
272
  if (!nodeFetch) {
273
273
  return _await$3(import('node-fetch'), function (_import) {
274
274
  nodeFetch = _import;
@@ -282,7 +282,7 @@ function buildGetJSON({
282
282
  });
283
283
  }
284
284
  }, function (_result) {
285
- return _exit ? _result : _invoke(function () {
285
+ return _exit ? _result : _invoke$2(function () {
286
286
  if (!basePath) {
287
287
  return _call(setDirname, function () {
288
288
  basePath = baseURL ? getDirectoryForURL(baseURL) : typeof fetch === 'undefined' && process.cwd();
@@ -2083,9 +2083,7 @@ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults()
2083
2083
  } else if (defaults === false || defaults === undefined || defaults === null) {
2084
2084
  str = false;
2085
2085
  } else if (defaults && _typeof(defaults) === 'object') {
2086
- str = messageForKey({
2087
- body: defaults
2088
- }, key);
2086
+ str = messageForKey(defaults, key);
2089
2087
  if (str) {
2090
2088
  str = str.value;
2091
2089
  }
@@ -2369,7 +2367,7 @@ var _findLocale = _async(function (_ref4) {
2369
2367
  } else if (typeof localeMatcher !== 'function') {
2370
2368
  throw new TypeError('`localeMatcher` must be "lookup" or a function!');
2371
2369
  }
2372
- return promiseChainForValues([].concat(_toConsumableArray(locales), _toConsumableArray(defaultLocales)), getLocale, 'No matching locale found!');
2370
+ return promiseChainForValues([].concat(_toConsumableArray(locales), _toConsumableArray(defaultLocales)), getLocale, 'No matching locale found for ' + [].concat(_toConsumableArray(locales), _toConsumableArray(defaultLocales)).join(', '));
2373
2371
  });
2374
2372
 
2375
2373
  /**
@@ -2440,6 +2438,14 @@ function _await(value, then, direct) {
2440
2438
  * @param {boolean} [cfg.throwOnExtraSuppliedFormatters=true]
2441
2439
  * @returns {Promise<I18NCallback>} Rejects if no suitable locale is found.
2442
2440
  */
2441
+
2442
+ function _invoke(body, then) {
2443
+ var result = body();
2444
+ if (result && result.then) {
2445
+ return result.then(then);
2446
+ }
2447
+ return then(result);
2448
+ }
2443
2449
  var i18nServer = function i18nServer(_ref) {
2444
2450
  var strings = _ref.strings,
2445
2451
  resolvedLocale = _ref.resolvedLocale,
@@ -2555,20 +2561,39 @@ var i18n = function i18n() {
2555
2561
  }), function (_ref4) {
2556
2562
  var strings = _ref4.strings,
2557
2563
  resolvedLocale = _ref4.locale;
2558
- return i18nServer({
2559
- strings: strings,
2560
- resolvedLocale: resolvedLocale,
2561
- messageStyle: messageStyle,
2562
- allSubstitutions: allSubstitutions,
2563
- insertNodes: insertNodes,
2564
- keyCheckerConverter: keyCheckerConverter,
2565
- defaults: defaults,
2566
- substitutions: substitutions,
2567
- maximumLocalNestingDepth: maximumLocalNestingDepth,
2568
- dom: dom,
2569
- forceNodeReturn: forceNodeReturn,
2570
- throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2571
- throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2564
+ return _invoke(function () {
2565
+ if (!defaults && defaultLocales) {
2566
+ var defaultLocale;
2567
+ return _await(localeStringFinder({
2568
+ locales: defaultLocales,
2569
+ defaultLocales: [],
2570
+ localeResolver: localeResolver,
2571
+ localesBasePath: localesBasePath,
2572
+ localeMatcher: localeMatcher
2573
+ }), function (_localeStringFinder) {
2574
+ defaults = _localeStringFinder.strings;
2575
+ defaultLocale = _localeStringFinder.locale;
2576
+ if (defaultLocale === resolvedLocale) {
2577
+ defaults = null; // No need to fall back
2578
+ }
2579
+ });
2580
+ }
2581
+ }, function () {
2582
+ return i18nServer({
2583
+ strings: strings,
2584
+ resolvedLocale: resolvedLocale,
2585
+ messageStyle: messageStyle,
2586
+ allSubstitutions: allSubstitutions,
2587
+ insertNodes: insertNodes,
2588
+ keyCheckerConverter: keyCheckerConverter,
2589
+ defaults: defaults,
2590
+ substitutions: substitutions,
2591
+ maximumLocalNestingDepth: maximumLocalNestingDepth,
2592
+ dom: dom,
2593
+ forceNodeReturn: forceNodeReturn,
2594
+ throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2595
+ throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2596
+ });
2572
2597
  });
2573
2598
  });
2574
2599
  } catch (e) {
package/dist/index-es.js CHANGED
@@ -259,7 +259,7 @@ let nodeFetch;
259
259
  * @returns {getJSONCallback}
260
260
  */
261
261
 
262
- function _invoke(body, then) {
262
+ function _invoke$2(body, then) {
263
263
  var result = body();
264
264
  if (result && result.then) {
265
265
  return result.then(then);
@@ -295,9 +295,9 @@ function buildGetJSON({
295
295
  } = {}) {
296
296
  const _fetch = typeof fetch !== 'undefined' ? fetch : _async$2(function (jsonURL) {
297
297
  let _exit = false;
298
- return _invoke(function () {
298
+ return _invoke$2(function () {
299
299
  if (/^https?:/u.test(jsonURL)) {
300
- return _invoke(function () {
300
+ return _invoke$2(function () {
301
301
  if (!nodeFetch) {
302
302
  return _await$3(import('node-fetch'), function (_import) {
303
303
  nodeFetch = _import;
@@ -310,7 +310,7 @@ function buildGetJSON({
310
310
  });
311
311
  }
312
312
  }, function (_result) {
313
- return _exit ? _result : _invoke(function () {
313
+ return _exit ? _result : _invoke$2(function () {
314
314
  if (!basePath) {
315
315
  return _call(setDirname, function () {
316
316
  basePath = baseURL ? getDirectoryForURL(baseURL) : typeof fetch === 'undefined' && process.cwd();
@@ -2106,9 +2106,7 @@ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults()
2106
2106
  } else if (defaults === false || defaults === undefined || defaults === null) {
2107
2107
  str = false;
2108
2108
  } else if (defaults && _typeof$1(defaults) === 'object') {
2109
- str = messageForKey({
2110
- body: defaults
2111
- }, key);
2109
+ str = messageForKey(defaults, key);
2112
2110
  if (str) {
2113
2111
  str = str.value;
2114
2112
  }
@@ -2391,7 +2389,7 @@ var _findLocale = _async(function (_ref4) {
2391
2389
  } else if (typeof localeMatcher !== 'function') {
2392
2390
  throw new TypeError('`localeMatcher` must be "lookup" or a function!');
2393
2391
  }
2394
- return promiseChainForValues([].concat(_toConsumableArray$1(locales), _toConsumableArray$1(defaultLocales)), getLocale, 'No matching locale found!');
2392
+ return promiseChainForValues([].concat(_toConsumableArray$1(locales), _toConsumableArray$1(defaultLocales)), getLocale, 'No matching locale found for ' + [].concat(_toConsumableArray$1(locales), _toConsumableArray$1(defaultLocales)).join(', '));
2395
2393
  });
2396
2394
 
2397
2395
  /**
@@ -2462,6 +2460,14 @@ function _await(value, then, direct) {
2462
2460
  * @param {boolean} [cfg.throwOnExtraSuppliedFormatters=true]
2463
2461
  * @returns {Promise<I18NCallback>} Rejects if no suitable locale is found.
2464
2462
  */
2463
+
2464
+ function _invoke(body, then) {
2465
+ var result = body();
2466
+ if (result && result.then) {
2467
+ return result.then(then);
2468
+ }
2469
+ return then(result);
2470
+ }
2465
2471
  var i18nServer = function i18nServer(_ref) {
2466
2472
  var strings = _ref.strings,
2467
2473
  resolvedLocale = _ref.resolvedLocale,
@@ -2577,20 +2583,39 @@ var i18n = function i18n() {
2577
2583
  }), function (_ref4) {
2578
2584
  var strings = _ref4.strings,
2579
2585
  resolvedLocale = _ref4.locale;
2580
- return i18nServer({
2581
- strings: strings,
2582
- resolvedLocale: resolvedLocale,
2583
- messageStyle: messageStyle,
2584
- allSubstitutions: allSubstitutions,
2585
- insertNodes: insertNodes,
2586
- keyCheckerConverter: keyCheckerConverter,
2587
- defaults: defaults,
2588
- substitutions: substitutions,
2589
- maximumLocalNestingDepth: maximumLocalNestingDepth,
2590
- dom: dom,
2591
- forceNodeReturn: forceNodeReturn,
2592
- throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2593
- throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2586
+ return _invoke(function () {
2587
+ if (!defaults && defaultLocales) {
2588
+ var defaultLocale;
2589
+ return _await(localeStringFinder({
2590
+ locales: defaultLocales,
2591
+ defaultLocales: [],
2592
+ localeResolver: localeResolver,
2593
+ localesBasePath: localesBasePath,
2594
+ localeMatcher: localeMatcher
2595
+ }), function (_localeStringFinder) {
2596
+ defaults = _localeStringFinder.strings;
2597
+ defaultLocale = _localeStringFinder.locale;
2598
+ if (defaultLocale === resolvedLocale) {
2599
+ defaults = null; // No need to fall back
2600
+ }
2601
+ });
2602
+ }
2603
+ }, function () {
2604
+ return i18nServer({
2605
+ strings: strings,
2606
+ resolvedLocale: resolvedLocale,
2607
+ messageStyle: messageStyle,
2608
+ allSubstitutions: allSubstitutions,
2609
+ insertNodes: insertNodes,
2610
+ keyCheckerConverter: keyCheckerConverter,
2611
+ defaults: defaults,
2612
+ substitutions: substitutions,
2613
+ maximumLocalNestingDepth: maximumLocalNestingDepth,
2614
+ dom: dom,
2615
+ forceNodeReturn: forceNodeReturn,
2616
+ throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2617
+ throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2618
+ });
2594
2619
  });
2595
2620
  });
2596
2621
  } catch (e) {