@i18n-micro/vue 1.4.11 → 2.0.1
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/LICENSE +1 -1
- package/README.md +12 -47
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +129 -157
- package/dist/index.d.ts +129 -157
- package/dist/index.mjs +328 -467
- package/dist/index.mjs.map +1 -1
- package/dist/router.cjs +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +29 -7
- package/dist/router.d.ts +29 -7
- package/dist/router.mjs +13 -18
- package/dist/router.mjs.map +1 -1
- package/package.json +21 -15
package/dist/index.d.ts
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<
|
|
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<
|
|
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
|
-
}>, () =>
|
|
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:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
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:
|
|
452
|
+
rel: "canonical";
|
|
509
453
|
href: string;
|
|
510
|
-
|
|
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
|
-
},
|
|
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:
|
|
473
|
+
rel: "canonical";
|
|
525
474
|
href: string;
|
|
526
|
-
|
|
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
|
-
|
|
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: (
|
|
594
|
-
|
|
595
|
-
|
|
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
|
}
|