i18next 21.1.0 → 21.2.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 21.2.2
2
+
3
+ - log error if Intl.PluralRules API is not available
4
+
5
+ ## 21.2.1
6
+
7
+ - do skip natural language detection, if user provided keySeparator option is passed [1670](https://github.com/i18next/i18next/issues/1670)
8
+
9
+ ## 21.2.0
10
+
11
+ - provide bundled esm distributable [1667](https://github.com/i18next/i18next/issues/1667)
12
+
13
+ ## 21.1.1
14
+
15
+ - optimize natural language detection [1661](https://github.com/i18next/i18next/issues/1661)
16
+
1
17
  ## 21.1.0
2
18
 
3
19
  - A new RTL support added for `ckb` language code
@@ -303,13 +303,23 @@ function looksLikeObjectPath(key, nsSeparator, keySeparator) {
303
303
  nsSeparator = nsSeparator || '';
304
304
  keySeparator = keySeparator || '';
305
305
  var possibleChars = chars.filter(function (c) {
306
- return nsSeparator.indexOf(c) < 0 || keySeparator.indexOf(c) < 0;
306
+ return nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0;
307
307
  });
308
308
  if (possibleChars.length === 0) return true;
309
309
  var r = new RegExp("(".concat(possibleChars.map(function (c) {
310
310
  return c === '?' ? '\\?' : c;
311
311
  }).join('|'), ")"));
312
- return !r.test(key);
312
+ var matched = !r.test(key);
313
+
314
+ if (!matched) {
315
+ var ki = key.indexOf(keySeparator);
316
+
317
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
318
+ matched = true;
319
+ }
320
+ }
321
+
322
+ return matched;
313
323
  }
314
324
 
315
325
  function deepFind(obj, path) {
@@ -598,7 +608,7 @@ var Translator = function (_EventEmitter) {
598
608
  var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
599
609
  var namespaces = options.ns || this.options.defaultNS;
600
610
  var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
601
- var seemsNaturalLanguage = !looksLikeObjectPath(key, nsSeparator, keySeparator);
611
+ var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
602
612
 
603
613
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
604
614
  var m = key.match(this.interpolator.nestingRegexp);
@@ -1268,6 +1278,11 @@ var PluralResolver = function () {
1268
1278
  this.languageUtils = languageUtils;
1269
1279
  this.options = options;
1270
1280
  this.logger = baseLogger.create('pluralResolver');
1281
+
1282
+ if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && !Intl && !Intl.PluralRules) {
1283
+ this.logger.error('Your environment seems not to be Inlt API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
1284
+ }
1285
+
1271
1286
  this.rules = createRules();
1272
1287
  }
1273
1288
 
@@ -1981,6 +1996,11 @@ var I18n = function (_EventEmitter) {
1981
1996
  }
1982
1997
 
1983
1998
  this.options = _objectSpread__default['default']({}, get(), this.options, transformOptions(options));
1999
+
2000
+ if (options.keySeparator !== undefined) {
2001
+ this.options.userDefinedKeySeparator = options.keySeparator;
2002
+ }
2003
+
1984
2004
  this.format = this.options.interpolation.format;
1985
2005
  if (!callback) callback = noop;
1986
2006