@jsverse/transloco-locale 7.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.
Files changed (38) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3 -0
  3. package/esm2022/index.mjs +8 -0
  4. package/esm2022/jsverse-transloco-locale.mjs +5 -0
  5. package/esm2022/lib/helpers.mjs +70 -0
  6. package/esm2022/lib/locale-currency.mjs +651 -0
  7. package/esm2022/lib/pipes/base-locale.pipe.mjs +24 -0
  8. package/esm2022/lib/pipes/index.mjs +6 -0
  9. package/esm2022/lib/pipes/transloco-currency.pipe.mjs +44 -0
  10. package/esm2022/lib/pipes/transloco-date.pipe.mjs +43 -0
  11. package/esm2022/lib/pipes/transloco-decimal.pipe.mjs +39 -0
  12. package/esm2022/lib/pipes/transloco-percent.pipe.mjs +39 -0
  13. package/esm2022/lib/shared.mjs +9 -0
  14. package/esm2022/lib/transloco-locale.config.mjs +18 -0
  15. package/esm2022/lib/transloco-locale.module.mjs +28 -0
  16. package/esm2022/lib/transloco-locale.providers.mjs +75 -0
  17. package/esm2022/lib/transloco-locale.service.mjs +120 -0
  18. package/esm2022/lib/transloco-locale.transformers.mjs +15 -0
  19. package/esm2022/lib/transloco-locale.types.mjs +2 -0
  20. package/fesm2022/jsverse-transloco-locale.mjs +1140 -0
  21. package/fesm2022/jsverse-transloco-locale.mjs.map +1 -0
  22. package/index.d.ts +7 -0
  23. package/lib/helpers.d.ts +15 -0
  24. package/lib/locale-currency.d.ts +651 -0
  25. package/lib/pipes/base-locale.pipe.d.ts +13 -0
  26. package/lib/pipes/index.d.ts +5 -0
  27. package/lib/pipes/transloco-currency.pipe.d.ts +22 -0
  28. package/lib/pipes/transloco-date.pipe.d.ts +24 -0
  29. package/lib/pipes/transloco-decimal.pipe.d.ts +19 -0
  30. package/lib/pipes/transloco-percent.pipe.d.ts +19 -0
  31. package/lib/shared.d.ts +2 -0
  32. package/lib/transloco-locale.config.d.ts +8 -0
  33. package/lib/transloco-locale.module.d.ts +10 -0
  34. package/lib/transloco-locale.providers.d.ts +11 -0
  35. package/lib/transloco-locale.service.d.ts +54 -0
  36. package/lib/transloco-locale.transformers.d.ts +16 -0
  37. package/lib/transloco-locale.types.d.ts +151 -0
  38. package/package.json +49 -0
@@ -0,0 +1,24 @@
1
+ import { PipeTransform } from '@angular/core';
2
+ import { DateFormatOptions, Locale, ValidDate } from '../transloco-locale.types';
3
+ import { BaseLocalePipe } from './base-locale.pipe';
4
+ import * as i0 from "@angular/core";
5
+ export declare class TranslocoDatePipe extends BaseLocalePipe implements PipeTransform {
6
+ private localeConfig;
7
+ /**
8
+ * Transform a date into the locale's date format.
9
+ *
10
+ * The date expression: a `Date` object, a number
11
+ * (milliseconds since UTC epoch), or an ISO string (https://www.w3.org/TR/NOTE-datetime).
12
+ *
13
+ * @example
14
+ *
15
+ * date | translocoDate: {} : en-US // 9/10/2019
16
+ * date | translocoDate: { dateStyle: 'medium', timeStyle: 'medium' } : en-US // Sep 10, 2019, 10:46:12 PM
17
+ * date | translocoDate: { timeZone: 'UTC', timeStyle: 'full' } : en-US // 7:40:32 PM Coordinated Universal Time
18
+ * 1 | translocoDate: { dateStyle: 'medium' } // Jan 1, 1970
19
+ * '2019-02-08' | translocoDate: { dateStyle: 'medium' } // Feb 8, 2019
20
+ */
21
+ transform(date: ValidDate, options?: DateFormatOptions, locale?: Locale): string;
22
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslocoDatePipe, never>;
23
+ static ɵpipe: i0.ɵɵPipeDeclaration<TranslocoDatePipe, "translocoDate", true>;
24
+ }
@@ -0,0 +1,19 @@
1
+ import { PipeTransform } from '@angular/core';
2
+ import { Locale, NumberFormatOptions } from '../transloco-locale.types';
3
+ import { BaseLocalePipe } from './base-locale.pipe';
4
+ import * as i0 from "@angular/core";
5
+ export declare class TranslocoDecimalPipe extends BaseLocalePipe implements PipeTransform {
6
+ private localeConfig;
7
+ /**
8
+ * Transform a given number into the locale's currency format.
9
+ *
10
+ * @example
11
+ *
12
+ * 1234567890 | translocoDecimal: {} : en-US // 1,234,567,890
13
+ * 1234567890 | translocoDecimal: {useGrouping: false}: en-US // 1234567890
14
+ *
15
+ */
16
+ transform(value: string | number, numberFormatOptions?: NumberFormatOptions, locale?: Locale): string;
17
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslocoDecimalPipe, never>;
18
+ static ɵpipe: i0.ɵɵPipeDeclaration<TranslocoDecimalPipe, "translocoDecimal", true>;
19
+ }
@@ -0,0 +1,19 @@
1
+ import { PipeTransform } from '@angular/core';
2
+ import { Locale, NumberFormatOptions } from '../transloco-locale.types';
3
+ import { BaseLocalePipe } from './base-locale.pipe';
4
+ import * as i0 from "@angular/core";
5
+ export declare class TranslocoPercentPipe extends BaseLocalePipe implements PipeTransform {
6
+ private localeConfig;
7
+ /**
8
+ * Transform a given number into the locale's currency format.
9
+ *
10
+ * @example
11
+ *
12
+ * 1 | translocoPercent : {} : en-US // 100%
13
+ * "1" | translocoPercent : {} : en-US // 100%
14
+ *
15
+ */
16
+ transform(value: number | string, numberFormatOptions?: NumberFormatOptions, locale?: Locale): string;
17
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslocoPercentPipe, never>;
18
+ static ɵpipe: i0.ɵɵPipeDeclaration<TranslocoPercentPipe, "translocoPercent", true>;
19
+ }
@@ -0,0 +1,2 @@
1
+ import { Locale, LocaleFormatOptions, LocaleConfig } from './transloco-locale.types';
2
+ export declare function getDefaultOptions<T extends keyof LocaleFormatOptions>(locale: Locale, style: T, localeConfig: LocaleConfig): NonNullable<LocaleFormatOptions[T]>;
@@ -0,0 +1,8 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { TranslocoLocaleConfig, LocaleConfigMapping, LangToLocaleMapping, LocaleToCurrencyMapping } from './transloco-locale.types';
3
+ export declare const defaultConfig: Required<TranslocoLocaleConfig>;
4
+ export declare const TRANSLOCO_LOCALE_DEFAULT_LOCALE: InjectionToken<string>;
5
+ export declare const TRANSLOCO_LOCALE_DEFAULT_CURRENCY: InjectionToken<string>;
6
+ export declare const TRANSLOCO_LOCALE_LANG_MAPPING: InjectionToken<LangToLocaleMapping>;
7
+ export declare const TRANSLOCO_LOCALE_CONFIG: InjectionToken<LocaleConfigMapping>;
8
+ export declare const TRANSLOCO_LOCALE_CURRENCY_MAPPING: InjectionToken<LocaleToCurrencyMapping>;
@@ -0,0 +1,10 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./pipes/transloco-currency.pipe";
3
+ import * as i2 from "./pipes/transloco-date.pipe";
4
+ import * as i3 from "./pipes/transloco-decimal.pipe";
5
+ import * as i4 from "./pipes/transloco-percent.pipe";
6
+ export declare class TranslocoLocaleModule {
7
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslocoLocaleModule, never>;
8
+ static ɵmod: i0.ɵɵNgModuleDeclaration<TranslocoLocaleModule, never, [typeof i1.TranslocoCurrencyPipe, typeof i2.TranslocoDatePipe, typeof i3.TranslocoDecimalPipe, typeof i4.TranslocoPercentPipe], [typeof i1.TranslocoCurrencyPipe, typeof i2.TranslocoDatePipe, typeof i3.TranslocoDecimalPipe, typeof i4.TranslocoPercentPipe]>;
9
+ static ɵinj: i0.ɵɵInjectorDeclaration<TranslocoLocaleModule>;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { Type } from '@angular/core';
2
+ import { Currency, LangToLocaleMapping, Locale, LocaleConfig, LocaleToCurrencyMapping, TranslocoLocaleConfig } from './transloco-locale.types';
3
+ import { TranslocoDateTransformer, TranslocoNumberTransformer } from './transloco-locale.transformers';
4
+ export declare function provideTranslocoLocale(config?: TranslocoLocaleConfig): import("@angular/core").EnvironmentProviders[];
5
+ export declare function provideTranslocoLocaleConfig(config: LocaleConfig): import("@angular/core").EnvironmentProviders;
6
+ export declare function provideTranslocoLocaleLangMapping(langToLocale: LangToLocaleMapping): import("@angular/core").EnvironmentProviders;
7
+ export declare function provideTranslocoLocaleCurrencyMapping(localeToCurrency: LocaleToCurrencyMapping): import("@angular/core").EnvironmentProviders;
8
+ export declare function provideTranslocoDefaultLocale(defaultLocale: Locale): import("@angular/core").EnvironmentProviders;
9
+ export declare function provideTranslocoDefaultCurrency(defaultCurrency: Currency): import("@angular/core").EnvironmentProviders;
10
+ export declare function provideTranslocoDateTransformer(transformer: Type<TranslocoDateTransformer>): import("@angular/core").EnvironmentProviders;
11
+ export declare function provideTranslocoNumberTransformer(transformer: Type<TranslocoNumberTransformer>): import("@angular/core").EnvironmentProviders;
@@ -0,0 +1,54 @@
1
+ import { OnDestroy } from '@angular/core';
2
+ import { DateFormatOptions, Locale, NumberStyles, ValidDate } from './transloco-locale.types';
3
+ import * as i0 from "@angular/core";
4
+ export declare class TranslocoLocaleService implements OnDestroy {
5
+ private translocoService;
6
+ private langLocaleMapping;
7
+ private defaultLocale;
8
+ private defaultCurrency;
9
+ private localeCurrencyMapping;
10
+ private numberTransformer;
11
+ private dateTransformer;
12
+ private localeConfig;
13
+ private _locale;
14
+ private locale;
15
+ private subscription;
16
+ localeChanges$: import("rxjs").Observable<string>;
17
+ getLocale(): string;
18
+ setLocale(locale: Locale): void;
19
+ /**
20
+ * Get the currency symbol for the currently set locale.
21
+ */
22
+ getCurrencySymbol(locale?: string): string | undefined;
23
+ /**
24
+ * Transform a date into the locale's date format.
25
+ *
26
+ * The date expression: a `Date` object, a number
27
+ * (milliseconds since UTC epoch), or an ISO string (https://www.w3.org/TR/NOTE-datetime).
28
+ *
29
+ * @example
30
+ *
31
+ * localizeDate(new Date(2019, 9, 7, 12, 0, 0)) // 10/7/2019
32
+ * localizeDate(date, 'en-US', { dateStyle: 'medium', timeStyle: 'medium' }) // Sep 10, 2019, 10:46:12 PM
33
+ * localizeDate(date) 'en-US', { timeZone: 'UTC', timeStyle: 'full' } // 7:40:32 PM Coordinated Universal Time
34
+ * localizeDate(1, 'en-US', { dateStyle: 'medium' }) // Jan 1, 1970
35
+ * localizeDate('2019-02-08', 'en-US', { dateStyle: 'medium' }) // Feb 8, 2019
36
+ */
37
+ localizeDate(date: ValidDate, locale?: Locale, options?: DateFormatOptions): string;
38
+ /**
39
+ * Transform a number into the locale's number format according to the number type.
40
+ *
41
+ * localizeNumber(1234567890, 'decimal') // 1,234,567,890
42
+ * localizeNumber(0.5, 'percent') // 50%
43
+ * localizeNumber(1000, 'currency') // $1,000.00
44
+ */
45
+ localizeNumber(value: number | string, style: NumberStyles, locale?: Locale, options?: Intl.NumberFormatOptions): string;
46
+ /**
47
+ * @internal
48
+ */
49
+ _resolveCurrencyCode(locale?: Locale): string;
50
+ ngOnDestroy(): void;
51
+ private toLocale;
52
+ static ɵfac: i0.ɵɵFactoryDeclaration<TranslocoLocaleService, never>;
53
+ static ɵprov: i0.ɵɵInjectableDeclaration<TranslocoLocaleService>;
54
+ }
@@ -0,0 +1,16 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { Locale, DateFormatOptions, NumberStyles } from './transloco-locale.types';
3
+ export interface TranslocoDateTransformer {
4
+ transform(date: Date, locale: Locale, options: DateFormatOptions): string;
5
+ }
6
+ export interface TranslocoNumberTransformer {
7
+ transform(value: number | string, type: NumberStyles, locale: Locale, options: Intl.NumberFormatOptions): string;
8
+ }
9
+ export declare const TRANSLOCO_DATE_TRANSFORMER: InjectionToken<TranslocoDateTransformer>;
10
+ export declare const TRANSLOCO_NUMBER_TRANSFORMER: InjectionToken<TranslocoNumberTransformer>;
11
+ export declare class DefaultDateTransformer implements TranslocoDateTransformer {
12
+ transform(date: Date, locale: Locale, options: DateFormatOptions): string;
13
+ }
14
+ export declare class DefaultNumberTransformer implements TranslocoNumberTransformer {
15
+ transform(value: number | string, type: NumberStyles, locale: string, options: Intl.NumberFormatOptions): string;
16
+ }
@@ -0,0 +1,151 @@
1
+ export interface NumberFormatOptions {
2
+ /**
3
+ * When to display the sign for the number.
4
+ */
5
+ signDisplay?: Intl.NumberFormatOptions['signDisplay'];
6
+ /**
7
+ * The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro
8
+ */
9
+ currency?: Intl.NumberFormatOptions['currency'];
10
+ /**
11
+ * Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. Possible values are true and false; the default is true.
12
+ */
13
+ useGrouping?: Intl.NumberFormatOptions['useGrouping'];
14
+ /**
15
+ * The minimum number of integer digits to use. Possible values are from 1 to 21.
16
+ */
17
+ minimumIntegerDigits?: Intl.NumberFormatOptions['minimumIntegerDigits'];
18
+ /**
19
+ * The minimum number of fraction digits to use. Possible values are from 0 to 20.
20
+ */
21
+ minimumFractionDigits?: Intl.NumberFormatOptions['minimumFractionDigits'];
22
+ /**
23
+ * The maximum number of fraction digits to use. Possible values are from 0 to 20.
24
+ */
25
+ maximumFractionDigits?: Intl.NumberFormatOptions['maximumFractionDigits'];
26
+ /**
27
+ * The minimum number of significant digits to use. Possible values are from 1 to 21.
28
+ */
29
+ minimumSignificantDigits?: Intl.NumberFormatOptions['minimumSignificantDigits'];
30
+ /**
31
+ * The maximum number of significant digits to use. Possible values are from 1 to 21
32
+ */
33
+ maximumSignificantDigits?: Intl.NumberFormatOptions['maximumSignificantDigits'];
34
+ }
35
+ /**
36
+ * The number display formatting type.
37
+ */
38
+ export type NumberStyles = 'currency' | 'decimal' | 'percent';
39
+ /**
40
+ * Allowed values with Date and Time formats
41
+ */
42
+ export type DateFormatStyles = 'full' | 'long' | 'medium' | 'short';
43
+ /**
44
+ * Common allowed formats for time zones
45
+ */
46
+ export type TimezoneNameFormats = 'short' | 'long';
47
+ /**
48
+ * Common allowed formats for date strings
49
+ */
50
+ export type DateStringFormats = TimezoneNameFormats | 'narrow';
51
+ /**
52
+ * Common allowed formats for numbers
53
+ */
54
+ export type DateNumberFormats = 'numeric' | '2-digit';
55
+ /**
56
+ * Supported Intl calender types
57
+ */
58
+ export interface DateFormatOptions {
59
+ /**
60
+ * The date formatting style.
61
+ */
62
+ dateStyle?: DateFormatStyles;
63
+ /**
64
+ * The time formatting style.
65
+ */
66
+ timeStyle?: DateFormatStyles;
67
+ /**
68
+ * Number of fractional seconds to show
69
+ */
70
+ fractionalSecondDigits?: 0 | 1 | 2 | 3;
71
+ /**
72
+ * The way day periods should be displayed
73
+ */
74
+ dayPeriod?: DateStringFormats;
75
+ /**
76
+ * The option for 12/24 hour display
77
+ */
78
+ hour12?: boolean;
79
+ /**
80
+ * Locale matcher options
81
+ */
82
+ localeMatcher?: 'lookup' | 'best fit';
83
+ /**
84
+ * Format matcher options
85
+ */
86
+ formatMatcher?: 'lookup' | 'best fit';
87
+ /**
88
+ * The weekday formatting style
89
+ */
90
+ weekday?: DateStringFormats;
91
+ /**
92
+ * The era formatting style
93
+ */
94
+ era?: DateStringFormats;
95
+ /**
96
+ * The year formatting style
97
+ */
98
+ year?: DateNumberFormats;
99
+ /**
100
+ * The Month formatting style
101
+ */
102
+ month?: DateStringFormats | DateNumberFormats;
103
+ /**
104
+ * The Day formatting style
105
+ */
106
+ day?: DateNumberFormats;
107
+ /**
108
+ * The Hour formatting style
109
+ */
110
+ hour?: DateNumberFormats;
111
+ /**
112
+ * The Minute formatting style
113
+ */
114
+ minute?: DateNumberFormats;
115
+ /**
116
+ * The Seconds formatting style
117
+ */
118
+ second?: DateNumberFormats;
119
+ /**
120
+ * The time zone to use. The only value implementations must recognize is "UTC"; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the IANA time zone database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
121
+ */
122
+ timeZone?: Intl.DateTimeFormatOptions['timeZone'];
123
+ /**
124
+ * The formatting for the time zone name
125
+ */
126
+ timeZoneName?: TimezoneNameFormats;
127
+ }
128
+ export type Locale = string;
129
+ export type Currency = string;
130
+ export type ValidDate = Date | string | number;
131
+ export interface LocaleFormatOptions {
132
+ date?: DateFormatOptions;
133
+ decimal?: NumberFormatOptions;
134
+ currency?: NumberFormatOptions;
135
+ percent?: NumberFormatOptions;
136
+ unit?: NumberFormatOptions;
137
+ }
138
+ export type LocaleConfigMapping = Record<string, LocaleFormatOptions>;
139
+ export type LangToLocaleMapping = Record<string, Locale>;
140
+ export type LocaleToCurrencyMapping = Record<string, Currency>;
141
+ export interface LocaleConfig {
142
+ global?: LocaleFormatOptions;
143
+ localeBased?: LocaleConfigMapping;
144
+ }
145
+ export interface TranslocoLocaleConfig {
146
+ defaultLocale?: Locale;
147
+ defaultCurrency?: Currency;
148
+ localeConfig?: LocaleConfig;
149
+ langToLocaleMapping?: LangToLocaleMapping;
150
+ localeToCurrencyMapping?: LocaleToCurrencyMapping;
151
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@jsverse/transloco-locale",
3
+ "version": "7.0.0",
4
+ "description": "The localization (l10n) library plugin for Transloco",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "bugs": {
9
+ "url": "https://github.com/jsverse/transloco/issues"
10
+ },
11
+ "homepage": "https://jsverse.github.io/transloco/docs/plugins/locale",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/jsverse/transloco"
15
+ },
16
+ "keywords": [
17
+ "angular",
18
+ "angular 2",
19
+ "i18n",
20
+ "localization",
21
+ "l10n",
22
+ "angular translate",
23
+ "angular i18n",
24
+ "transloco"
25
+ ],
26
+ "license": "MIT",
27
+ "peerDependencies": {
28
+ "@angular/core": ">=16.0.0",
29
+ "@jsverse/transloco": ">=7.0.0",
30
+ "rxjs": ">=6.0.0"
31
+ },
32
+ "dependencies": {
33
+ "tslib": "^2.2.0"
34
+ },
35
+ "module": "fesm2022/jsverse-transloco-locale.mjs",
36
+ "typings": "index.d.ts",
37
+ "exports": {
38
+ "./package.json": {
39
+ "default": "./package.json"
40
+ },
41
+ ".": {
42
+ "types": "./index.d.ts",
43
+ "esm2022": "./esm2022/jsverse-transloco-locale.mjs",
44
+ "esm": "./esm2022/jsverse-transloco-locale.mjs",
45
+ "default": "./fesm2022/jsverse-transloco-locale.mjs"
46
+ }
47
+ },
48
+ "sideEffects": false
49
+ }