@intlify/core-base 9.4.1 → 9.6.0

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v9.4.1
2
+ * core-base v9.6.0
3
3
  * (c) 2023 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -464,6 +464,22 @@ function getWarnMessage(code, ...args) {
464
464
  return format$1(warnMessages[code], ...args);
465
465
  }
466
466
 
467
+ /** @internal */
468
+ function getLocale(context, options) {
469
+ return options.locale != null
470
+ ? resolveLocale(options.locale)
471
+ : resolveLocale(context.locale);
472
+ }
473
+ let _resolveLocale;
474
+ /** @internal */
475
+ function resolveLocale(locale) {
476
+ // prettier-ignore
477
+ return isString(locale)
478
+ ? locale
479
+ : _resolveLocale != null && locale.resolvedOnce
480
+ ? _resolveLocale
481
+ : (_resolveLocale = locale());
482
+ }
467
483
  /**
468
484
  * Fallback with simple implemenation
469
485
  *
@@ -585,7 +601,7 @@ function appendItemToChain(chain, target, blocks) {
585
601
  * Intlify core-base version
586
602
  * @internal
587
603
  */
588
- const VERSION = '9.4.1';
604
+ const VERSION = '9.6.0';
589
605
  const NOT_REOSLVED = -1;
590
606
  const DEFAULT_LOCALE = 'en-US';
591
607
  const MISSING_RESOLVE_VALUE = '';
@@ -661,23 +677,26 @@ function createCoreContext(options = {}) {
661
677
  // setup options
662
678
  const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
663
679
  const version = isString(options.version) ? options.version : VERSION;
664
- const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
680
+ const locale = isString(options.locale) || isFunction(options.locale)
681
+ ? options.locale
682
+ : DEFAULT_LOCALE;
683
+ const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
665
684
  const fallbackLocale = isArray(options.fallbackLocale) ||
666
685
  isPlainObject(options.fallbackLocale) ||
667
686
  isString(options.fallbackLocale) ||
668
687
  options.fallbackLocale === false
669
688
  ? options.fallbackLocale
670
- : locale;
689
+ : _locale;
671
690
  const messages = isPlainObject(options.messages)
672
691
  ? options.messages
673
- : { [locale]: {} };
692
+ : { [_locale]: {} };
674
693
  const datetimeFormats = isPlainObject(options.datetimeFormats)
675
694
  ? options.datetimeFormats
676
- : { [locale]: {} }
695
+ : { [_locale]: {} }
677
696
  ;
678
697
  const numberFormats = isPlainObject(options.numberFormats)
679
698
  ? options.numberFormats
680
- : { [locale]: {} }
699
+ : { [_locale]: {} }
681
700
  ;
682
701
  const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
683
702
  const pluralRules = options.pluralRules || {};
@@ -857,7 +876,7 @@ function formatMessagePart(ctx, node) {
857
876
  return ctx.interpolate(ctx.named(named.k || named.key));
858
877
  case 5 /* NodeTypes.List */:
859
878
  const list = node;
860
- return ctx.interpolate(ctx.list(list.i || list.index));
879
+ return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
861
880
  case 6 /* NodeTypes.Linked */:
862
881
  const linked = node;
863
882
  const modifier = linked.m || linked.modifier;
@@ -1021,7 +1040,7 @@ function translate(context, ...args) {
1021
1040
  ? (!messageCompiler ? () => key : key)
1022
1041
  : '';
1023
1042
  const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
1024
- const locale = isString(options.locale) ? options.locale : context.locale;
1043
+ const locale = getLocale(context, options);
1025
1044
  // escape params
1026
1045
  escapeParameter && escapeParams(options);
1027
1046
  // resolve message format
@@ -1429,7 +1448,7 @@ function datetime(context, ...args) {
1429
1448
  ? options.fallbackWarn
1430
1449
  : context.fallbackWarn;
1431
1450
  const part = !!options.part;
1432
- const locale = isString(options.locale) ? options.locale : context.locale;
1451
+ const locale = getLocale(context, options);
1433
1452
  const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1434
1453
  fallbackLocale, locale);
1435
1454
  if (!isString(key) || key === '') {
@@ -1604,7 +1623,7 @@ function number(context, ...args) {
1604
1623
  ? options.fallbackWarn
1605
1624
  : context.fallbackWarn;
1606
1625
  const part = !!options.part;
1607
- const locale = isString(options.locale) ? options.locale : context.locale;
1626
+ const locale = getLocale(context, options);
1608
1627
  const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1609
1628
  fallbackLocale, locale);
1610
1629
  if (!isString(key) || key === '') {
@@ -1735,4 +1754,4 @@ function clearNumberFormat(ctx, locale, format) {
1735
1754
  initFeatureFlags();
1736
1755
  }
1737
1756
 
1738
- export { CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, compileToFunction, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getWarnMessage, handleMissing, initI18nDevTools, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
1757
+ export { CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, compileToFunction, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getLocale, getWarnMessage, handleMissing, initI18nDevTools, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core-base v9.4.1
2
+ * core-base v9.6.0
3
3
  * (c) 2023 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -449,6 +449,22 @@ function getWarnMessage(code, ...args) {
449
449
  return shared.format(warnMessages[code], ...args);
450
450
  }
451
451
 
452
+ /** @internal */
453
+ function getLocale(context, options) {
454
+ return options.locale != null
455
+ ? resolveLocale(options.locale)
456
+ : resolveLocale(context.locale);
457
+ }
458
+ let _resolveLocale;
459
+ /** @internal */
460
+ function resolveLocale(locale) {
461
+ // prettier-ignore
462
+ return shared.isString(locale)
463
+ ? locale
464
+ : _resolveLocale != null && locale.resolvedOnce
465
+ ? _resolveLocale
466
+ : (_resolveLocale = locale());
467
+ }
452
468
  /**
453
469
  * Fallback with simple implemenation
454
470
  *
@@ -570,7 +586,7 @@ function appendItemToChain(chain, target, blocks) {
570
586
  * Intlify core-base version
571
587
  * @internal
572
588
  */
573
- const VERSION = '9.4.1';
589
+ const VERSION = '9.6.0';
574
590
  const NOT_REOSLVED = -1;
575
591
  const DEFAULT_LOCALE = 'en-US';
576
592
  const MISSING_RESOLVE_VALUE = '';
@@ -646,23 +662,26 @@ function createCoreContext(options = {}) {
646
662
  // setup options
647
663
  const onWarn = shared.isFunction(options.onWarn) ? options.onWarn : shared.warn;
648
664
  const version = shared.isString(options.version) ? options.version : VERSION;
649
- const locale = shared.isString(options.locale) ? options.locale : DEFAULT_LOCALE;
665
+ const locale = shared.isString(options.locale) || shared.isFunction(options.locale)
666
+ ? options.locale
667
+ : DEFAULT_LOCALE;
668
+ const _locale = shared.isFunction(locale) ? DEFAULT_LOCALE : locale;
650
669
  const fallbackLocale = shared.isArray(options.fallbackLocale) ||
651
670
  shared.isPlainObject(options.fallbackLocale) ||
652
671
  shared.isString(options.fallbackLocale) ||
653
672
  options.fallbackLocale === false
654
673
  ? options.fallbackLocale
655
- : locale;
674
+ : _locale;
656
675
  const messages = shared.isPlainObject(options.messages)
657
676
  ? options.messages
658
- : { [locale]: {} };
677
+ : { [_locale]: {} };
659
678
  const datetimeFormats = shared.isPlainObject(options.datetimeFormats)
660
679
  ? options.datetimeFormats
661
- : { [locale]: {} }
680
+ : { [_locale]: {} }
662
681
  ;
663
682
  const numberFormats = shared.isPlainObject(options.numberFormats)
664
683
  ? options.numberFormats
665
- : { [locale]: {} }
684
+ : { [_locale]: {} }
666
685
  ;
667
686
  const modifiers = shared.assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
668
687
  const pluralRules = options.pluralRules || {};
@@ -810,7 +829,7 @@ function formatMessagePart(ctx, node) {
810
829
  return ctx.interpolate(ctx.named(named.k || named.key));
811
830
  case 5 /* NodeTypes.List */:
812
831
  const list = node;
813
- return ctx.interpolate(ctx.list(list.i || list.index));
832
+ return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index));
814
833
  case 6 /* NodeTypes.Linked */:
815
834
  const linked = node;
816
835
  const modifier = linked.m || linked.modifier;
@@ -961,7 +980,7 @@ function translate(context, ...args) {
961
980
  ? (!messageCompiler ? () => key : key)
962
981
  : '';
963
982
  const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
964
- const locale = shared.isString(options.locale) ? options.locale : context.locale;
983
+ const locale = getLocale(context, options);
965
984
  // escape params
966
985
  escapeParameter && escapeParams(options);
967
986
  // resolve message format
@@ -1196,7 +1215,7 @@ function datetime(context, ...args) {
1196
1215
  ? options.fallbackWarn
1197
1216
  : context.fallbackWarn;
1198
1217
  const part = !!options.part;
1199
- const locale = shared.isString(options.locale) ? options.locale : context.locale;
1218
+ const locale = getLocale(context, options);
1200
1219
  const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1201
1220
  fallbackLocale, locale);
1202
1221
  if (!shared.isString(key) || key === '') {
@@ -1343,7 +1362,7 @@ function number(context, ...args) {
1343
1362
  ? options.fallbackWarn
1344
1363
  : context.fallbackWarn;
1345
1364
  const part = !!options.part;
1346
- const locale = shared.isString(options.locale) ? options.locale : context.locale;
1365
+ const locale = getLocale(context, options);
1347
1366
  const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1348
1367
  fallbackLocale, locale);
1349
1368
  if (!shared.isString(key) || key === '') {
@@ -1471,6 +1490,7 @@ exports.fallbackWithSimple = fallbackWithSimple;
1471
1490
  exports.getAdditionalMeta = getAdditionalMeta;
1472
1491
  exports.getDevToolsHook = getDevToolsHook;
1473
1492
  exports.getFallbackContext = getFallbackContext;
1493
+ exports.getLocale = getLocale;
1474
1494
  exports.getWarnMessage = getWarnMessage;
1475
1495
  exports.handleMissing = handleMissing;
1476
1496
  exports.initI18nDevTools = initI18nDevTools;
@@ -1486,6 +1506,7 @@ exports.parseTranslateArgs = parseTranslateArgs;
1486
1506
  exports.registerLocaleFallbacker = registerLocaleFallbacker;
1487
1507
  exports.registerMessageCompiler = registerMessageCompiler;
1488
1508
  exports.registerMessageResolver = registerMessageResolver;
1509
+ exports.resolveLocale = resolveLocale;
1489
1510
  exports.resolveValue = resolveValue;
1490
1511
  exports.resolveWithKeyValue = resolveWithKeyValue;
1491
1512
  exports.setAdditionalMeta = setAdditionalMeta;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/core-base",
3
- "version": "9.4.1",
3
+ "version": "9.6.0",
4
4
  "description": "@intlify/core-base",
5
5
  "keywords": [
6
6
  "core",
@@ -33,12 +33,12 @@
33
33
  "jsdelivr": "dist/core-base.global.js",
34
34
  "types": "dist/core-base.d.ts",
35
35
  "dependencies": {
36
- "@intlify/shared": "9.4.1",
37
- "@intlify/message-compiler": "9.4.1"
36
+ "@intlify/shared": "9.6.0",
37
+ "@intlify/message-compiler": "9.6.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@intlify/vue-devtools": "9.4.1",
41
- "@intlify/devtools-if": "9.4.1"
40
+ "@intlify/vue-devtools": "9.6.0",
41
+ "@intlify/devtools-if": "9.6.0"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">= 16"