@i18n-micro/vue 1.4.11 → 2.0.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.
package/dist/index.d.cts CHANGED
@@ -4,15 +4,19 @@ import { Component } from 'vue';
4
4
  import { ComponentOptionsMixin } from 'vue';
5
5
  import { ComponentProvideOptions } from 'vue';
6
6
  import { CSSProperties } from 'vue';
7
+ import { DateTimeFormatsConfig } from '@i18n-micro/core';
7
8
  import { defaultPlural } from '@i18n-micro/core';
8
9
  import { DefineComponent } from 'vue';
9
10
  import { ExtractPropTypes } from 'vue';
10
11
  import { FormatService } from '@i18n-micro/core';
12
+ import { FunctionalComponent } from 'vue';
11
13
  import { Getter } from '@i18n-micro/types';
12
14
  import { InjectionKey } from 'vue';
13
15
  import { interpolate } from '@i18n-micro/core';
14
16
  import { Locale } from '@i18n-micro/types';
15
17
  import { LocaleCode } from '@i18n-micro/types';
18
+ import { LocaleHead } from '@i18n-micro/utils/locale-head';
19
+ import { NumberFormatsConfig } from '@i18n-micro/core';
16
20
  import { Params } from '@i18n-micro/types';
17
21
  import { Plugin as Plugin_2 } from 'vue';
18
22
  import { PluralFunc } from '@i18n-micro/types';
@@ -64,9 +68,7 @@ export declare const I18nInjectionKey: InjectionKey<VueI18n>;
64
68
 
65
69
  export declare const I18nLink: DefineComponent<ExtractPropTypes<{
66
70
  to: {
67
- type: PropType<string | {
68
- path?: string;
69
- }>;
71
+ type: PropType<I18nRouteTarget>;
70
72
  required: true;
71
73
  };
72
74
  activeStyle: {
@@ -74,9 +76,7 @@ export declare const I18nLink: DefineComponent<ExtractPropTypes<{
74
76
  default: () => {};
75
77
  };
76
78
  localeRoute: {
77
- type: PropType<(to: string | {
78
- path?: string;
79
- }, locale?: string) => string | {
79
+ type: PropType<(to: I18nRouteTarget, locale?: string) => string | {
80
80
  path?: string;
81
81
  }>;
82
82
  default: undefined;
@@ -85,9 +85,7 @@ export declare const I18nLink: DefineComponent<ExtractPropTypes<{
85
85
  [key: string]: any;
86
86
  }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
87
87
  to: {
88
- type: PropType<string | {
89
- path?: string;
90
- }>;
88
+ type: PropType<I18nRouteTarget>;
91
89
  required: true;
92
90
  };
93
91
  activeStyle: {
@@ -95,18 +93,14 @@ export declare const I18nLink: DefineComponent<ExtractPropTypes<{
95
93
  default: () => {};
96
94
  };
97
95
  localeRoute: {
98
- type: PropType<(to: string | {
99
- path?: string;
100
- }, locale?: string) => string | {
96
+ type: PropType<(to: I18nRouteTarget, locale?: string) => string | {
101
97
  path?: string;
102
98
  }>;
103
99
  default: undefined;
104
100
  };
105
101
  }>> & Readonly<{}>, {
106
102
  activeStyle: CSSProperties;
107
- localeRoute: (to: string | {
108
- path?: string;
109
- }, locale?: string) => string | {
103
+ localeRoute: (to: I18nRouteTarget, locale?: string) => string | {
110
104
  path?: string;
111
105
  };
112
106
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
@@ -118,6 +112,15 @@ export declare type I18nPlugin = Plugin_2 & {
118
112
  setRoutingStrategy: (strategy: I18nRoutingStrategy) => void;
119
113
  };
120
114
 
115
+ /** A link target: a path with its query and hash, or a location (a named one needs a router that resolves names). */
116
+ export declare type I18nRouteTarget = string | {
117
+ path?: string;
118
+ name?: string | symbol;
119
+ params?: object;
120
+ query?: object;
121
+ hash?: string;
122
+ };
123
+
121
124
  /**
122
125
  * Routing strategy interface for i18n
123
126
  * Implement this interface to integrate with any router library
@@ -147,11 +150,14 @@ export declare interface I18nRoutingStrategy {
147
150
  /**
148
151
  * Generate path for specific locale
149
152
  */
150
- resolvePath?: (to: string | {
151
- path?: string;
152
- }, locale: string) => string | {
153
+ resolvePath?: (to: I18nRouteTarget, locale: string) => string | {
153
154
  path?: string;
154
155
  };
156
+ /**
157
+ * `href` of a path from `resolvePath`, for a router that navigates by something else
158
+ * (VitePress: paths are relative to the site base, the address bar is not)
159
+ */
160
+ toHref?: (path: string) => string;
155
161
  /**
156
162
  * (Optional) Get current route object for SEO/Meta tags
157
163
  */
@@ -229,9 +235,7 @@ export declare const I18nSwitcher: DefineComponent<ExtractPropTypes<{
229
235
  }>;
230
236
  default: undefined;
231
237
  };
232
- }>, () => VNode< RendererNode, RendererElement, {
233
- [key: string]: any;
234
- }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
238
+ }>, () => unknown, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
235
239
  customLabels: {
236
240
  type: PropType<Record<string, string>>;
237
241
  default: () => {};
@@ -305,7 +309,6 @@ export declare const I18nSwitcher: DefineComponent<ExtractPropTypes<{
305
309
  }, locale?: string) => string | {
306
310
  path?: string;
307
311
  };
308
- customLabels: Record<string, string>;
309
312
  customWrapperStyle: CSSProperties;
310
313
  customButtonStyle: CSSProperties;
311
314
  customDropdownStyle: CSSProperties;
@@ -314,104 +317,72 @@ export declare const I18nSwitcher: DefineComponent<ExtractPropTypes<{
314
317
  customActiveLinkStyle: CSSProperties;
315
318
  customDisabledLinkStyle: CSSProperties;
316
319
  customIconStyle: CSSProperties;
320
+ customLabels: Record<string, string>;
317
321
  locales: Locale[];
318
322
  currentLocale: string | (() => string);
319
323
  getLocaleName: () => string | null;
320
324
  switchLocale: (locale: string) => void;
321
325
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
322
326
 
323
- export declare const I18nT: DefineComponent<ExtractPropTypes<{
324
- keypath: {
325
- type: PropType<TranslationKey>;
326
- required: true;
327
- };
328
- plural: {
329
- type: PropType<number | string>;
330
- };
331
- tag: {
332
- type: PropType<string>;
333
- default: string;
334
- };
335
- params: {
336
- type: PropType<Record<string, string | number | boolean>>;
337
- default: () => {};
338
- };
339
- defaultValue: {
340
- type: PropType<string>;
341
- default: string;
342
- };
343
- html: {
344
- type: PropType<boolean>;
345
- default: boolean;
346
- };
347
- hideIfEmpty: {
348
- type: PropType<boolean>;
349
- default: boolean;
350
- };
351
- customPluralRule: {
352
- type: PropType<PluralFunc>;
353
- default: null;
354
- };
355
- number: {
356
- type: PropType<number | string>;
357
- };
358
- date: {
359
- type: PropType<Date | string | number>;
360
- };
361
- relativeDate: {
362
- type: PropType<Date | string | number>;
363
- };
364
- }>, () => string | VNode< RendererNode, RendererElement, {
365
- [key: string]: any;
366
- }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
367
- keypath: {
368
- type: PropType<TranslationKey>;
369
- required: true;
370
- };
371
- plural: {
372
- type: PropType<number | string>;
373
- };
374
- tag: {
375
- type: PropType<string>;
376
- default: string;
377
- };
378
- params: {
379
- type: PropType<Record<string, string | number | boolean>>;
380
- default: () => {};
381
- };
382
- defaultValue: {
383
- type: PropType<string>;
384
- default: string;
385
- };
386
- html: {
387
- type: PropType<boolean>;
388
- default: boolean;
389
- };
390
- hideIfEmpty: {
391
- type: PropType<boolean>;
392
- default: boolean;
393
- };
394
- customPluralRule: {
395
- type: PropType<PluralFunc>;
396
- default: null;
397
- };
398
- number: {
399
- type: PropType<number | string>;
400
- };
401
- date: {
402
- type: PropType<Date | string | number>;
403
- };
404
- relativeDate: {
405
- type: PropType<Date | string | number>;
327
+ export declare const I18nT: FunctionalComponent<I18nTProps, {}, any, {}> & {
328
+ displayName: string;
329
+ inheritAttrs: boolean;
330
+ props: {
331
+ keypath: {
332
+ type: PropType<TranslationKey>;
333
+ required: boolean;
334
+ };
335
+ plural: {
336
+ type: PropType<number | string | null>;
337
+ };
338
+ tag: {
339
+ type: StringConstructor;
340
+ default: string;
341
+ };
342
+ params: {
343
+ type: PropType<Record<string, string | number | boolean>>;
344
+ };
345
+ defaultValue: {
346
+ type: StringConstructor;
347
+ default: string;
348
+ };
349
+ html: {
350
+ type: BooleanConstructor;
351
+ default: boolean;
352
+ };
353
+ hideIfEmpty: {
354
+ type: BooleanConstructor;
355
+ default: boolean;
356
+ };
357
+ customPluralRule: {
358
+ type: PropType<PluralFunc>;
359
+ default: null;
360
+ };
361
+ number: {
362
+ type: PropType<number | string | null>;
363
+ };
364
+ date: {
365
+ type: PropType<Date | string | number | null>;
366
+ };
367
+ relativeDate: {
368
+ type: PropType<Date | string | number | null>;
369
+ };
406
370
  };
407
- }>> & Readonly<{}>, {
408
- html: boolean;
409
- tag: string;
410
- params: Record<string, string | number | boolean>;
411
- defaultValue: string;
412
- hideIfEmpty: boolean;
413
- customPluralRule: PluralFunc;
414
- }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
371
+ };
372
+
373
+ export declare interface I18nTProps {
374
+ keypath: TranslationKey;
375
+ plural?: number | string | null;
376
+ tag?: string;
377
+ params?: Record<string, string | number | boolean>;
378
+ defaultValue?: string;
379
+ html?: boolean;
380
+ hideIfEmpty?: boolean;
381
+ customPluralRule?: PluralFunc | null;
382
+ number?: number | string | null;
383
+ date?: Date | string | number | null;
384
+ relativeDate?: Date | string | number | null;
385
+ }
415
386
 
416
387
  export { interpolate }
417
388
 
@@ -419,28 +390,6 @@ export { Locale }
419
390
 
420
391
  export { LocaleCode }
421
392
 
422
- declare interface MetaLink {
423
- [key: string]: string | undefined;
424
- rel: string;
425
- href: string;
426
- hreflang?: string;
427
- }
428
-
429
- declare interface MetaObject {
430
- htmlAttrs: {
431
- lang?: string;
432
- dir?: 'ltr' | 'rtl' | 'auto';
433
- };
434
- link: MetaLink[];
435
- meta: MetaTag[];
436
- }
437
-
438
- declare interface MetaTag {
439
- [key: string]: string;
440
- property: string;
441
- content: string;
442
- }
443
-
444
393
  export { Params }
445
394
 
446
395
  export { PluralFunc }
@@ -457,14 +406,8 @@ export declare function useI18n(options?: UseI18nOptions): {
457
406
  getLocales: () => Locale[];
458
407
  defaultLocale: () => string;
459
408
  getLocaleName: () => string | null;
460
- localeRoute: (to: string | {
461
- path?: string;
462
- }, localeCode?: string) => string | {
463
- path?: string;
464
- };
465
- localePath: (to: string | {
466
- path?: string;
467
- }, locale?: string) => string;
409
+ localeRoute: (to: I18nRouteTarget, localeCode?: string) => I18nRouteTarget;
410
+ localePath: (to: I18nRouteTarget, locale?: string) => string;
468
411
  switchLocale: (newLocale: string) => void;
469
412
  t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeContext?: unknown) => CleanTranslation;
470
413
  ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeContext?: unknown) => string;
@@ -500,31 +443,41 @@ export declare interface UseI18nOptions {
500
443
  export declare function useLocaleHead(options?: UseLocaleHeadOptions): {
501
444
  metaObject: Ref<{
502
445
  htmlAttrs: {
446
+ [x: string]: string | undefined;
503
447
  lang?: string | undefined;
504
448
  dir?: "ltr" | "rtl" | "auto" | undefined;
505
449
  };
506
- link: {
450
+ link: ({
507
451
  [x: string]: string | undefined;
508
- rel: string;
452
+ rel: "canonical";
509
453
  href: string;
510
- hreflang?: string | undefined;
511
- }[];
454
+ } | {
455
+ [x: string]: string | undefined;
456
+ rel: "alternate";
457
+ href: string;
458
+ hreflang: string;
459
+ })[];
512
460
  meta: {
513
461
  [x: string]: string;
514
462
  property: string;
515
463
  content: string;
516
464
  }[];
517
- }, MetaObject | {
465
+ }, LocaleHead | {
518
466
  htmlAttrs: {
467
+ [x: string]: string | undefined;
519
468
  lang?: string | undefined;
520
469
  dir?: "ltr" | "rtl" | "auto" | undefined;
521
470
  };
522
- link: {
471
+ link: ({
523
472
  [x: string]: string | undefined;
524
- rel: string;
473
+ rel: "canonical";
525
474
  href: string;
526
- hreflang?: string | undefined;
527
- }[];
475
+ } | {
476
+ [x: string]: string | undefined;
477
+ rel: "alternate";
478
+ href: string;
479
+ hreflang: string;
480
+ })[];
528
481
  meta: {
529
482
  [x: string]: string;
530
483
  property: string;
@@ -566,7 +519,8 @@ export declare class VueI18n extends BaseI18n {
566
519
  addTranslations(locale: string, translations: Translations, merge?: boolean): void;
567
520
  addRouteTranslations(locale: string, routeName: string, translations: Translations, merge?: boolean): void;
568
521
  mergeTranslations(locale: string, routeName: string, translations: Translations): void;
569
- clearCache(): void;
522
+ /** Every read depends on the revision, so `computed(() => t(key))` re-runs after a write. */
523
+ protected touch(): void;
570
524
  protected onTranslationsChanged(): void;
571
525
  subscribeToChanges(cb: () => void): () => void;
572
526
  private notifyListeners;
@@ -581,6 +535,14 @@ export declare interface VueI18nOptions {
581
535
  plural?: PluralFunc;
582
536
  missingWarn?: boolean;
583
537
  missingHandler?: (locale: string, key: string, routeName: string) => void;
538
+ /** Named number formats per locale (`tn(n, 'currency')`). */
539
+ numberFormats?: NumberFormatsConfig;
540
+ /** Named datetime formats per locale (`td(d, 'short')`). */
541
+ datetimeFormats?: DateTimeFormatsConfig;
542
+ /** IANA zone for dates (`Europe/Berlin`): set it so server and browser render one date. */
543
+ timeZone?: string;
544
+ /** BCP 47 tag per locale code, for plurals of a code that is no language tag. `createI18n` fills it from `locales`. */
545
+ localeIso?: Record<string, string>;
584
546
  }
585
547
 
586
548
  export { }
@@ -590,9 +552,19 @@ export { }
590
552
  // Extend '@vue/runtime-core' module so types work correctly in all environments
591
553
  declare module '@vue/runtime-core' {
592
554
  interface ComponentCustomProperties {
593
- $t: (key: TranslationKey, params?: Params, defaultValue?: string | null, routeName?: string) => CleanTranslation
594
- $ts: (key: TranslationKey, params?: Params, defaultValue?: string, routeName?: string) => string
595
- $tc: (key: TranslationKey, count: number | Params, defaultValue?: string) => string
555
+ $t: (
556
+ key: import('@i18n-micro/types').TranslationKey,
557
+ params?: import('@i18n-micro/types').Params,
558
+ defaultValue?: string | null,
559
+ routeName?: string,
560
+ ) => import('@i18n-micro/types').CleanTranslation
561
+ $ts: (
562
+ key: import('@i18n-micro/types').TranslationKey,
563
+ params?: import('@i18n-micro/types').Params,
564
+ defaultValue?: string,
565
+ routeName?: string,
566
+ ) => string
567
+ $tc: (key: import('@i18n-micro/types').TranslationKey, count: number | import('@i18n-micro/types').Params, defaultValue?: string) => string
596
568
  $tn: {
597
569
  (value: number, options?: Intl.NumberFormatOptions): string
598
570
  (value: number, key: string, overrides?: Intl.NumberFormatOptions): string
@@ -604,7 +576,7 @@ declare module '@vue/runtime-core' {
604
576
  (value: Date | number | string, key: string, locale: string, overrides?: Intl.DateTimeFormatOptions): string
605
577
  }
606
578
  $tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string
607
- $has: (key: TranslationKey, routeName?: string) => boolean
579
+ $has: (key: import('@i18n-micro/types').TranslationKey, routeName?: string) => boolean
608
580
  $i18n: any
609
581
  }
610
582
  }