@cocoar/vue-localization 0.1.0-beta.25 → 1.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/LICENSE +201 -0
- package/README.md +27 -0
- package/dist/composables.d.ts +54 -0
- package/dist/composables.d.ts.map +1 -0
- package/dist/i18n/interpolate.d.ts +17 -0
- package/dist/i18n/interpolate.d.ts.map +1 -0
- package/dist/i18n/intl-translation-source.d.ts +16 -0
- package/dist/i18n/intl-translation-source.d.ts.map +1 -0
- package/dist/i18n/translation-store.d.ts +47 -0
- package/dist/i18n/translation-store.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/injection-keys.d.ts +9 -0
- package/dist/injection-keys.d.ts.map +1 -0
- package/dist/l10n/formatters.d.ts +19 -0
- package/dist/l10n/formatters.d.ts.map +1 -0
- package/dist/l10n/intl-locale-data-source.d.ts +9 -0
- package/dist/l10n/intl-locale-data-source.d.ts.map +1 -0
- package/dist/l10n/localization-data-store.d.ts +18 -0
- package/dist/l10n/localization-data-store.d.ts.map +1 -0
- package/dist/l10n/merge-localization-data.d.ts +7 -0
- package/dist/l10n/merge-localization-data.d.ts.map +1 -0
- package/dist/localization-service.d.ts +61 -0
- package/dist/localization-service.d.ts.map +1 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/timezone/timezone-service.d.ts +23 -0
- package/dist/timezone/timezone-service.d.ts.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +19 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @cocoar/vue-localization
|
|
2
|
+
|
|
3
|
+
Locale-aware formatting (l10n), translations (i18n), and timezone detection for Vue 3.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @cocoar/vue-localization
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createCoarLocalization } from '@cocoar/vue-localization';
|
|
15
|
+
|
|
16
|
+
app.use(createCoarLocalization({
|
|
17
|
+
defaultLanguage: 'en',
|
|
18
|
+
}));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Documentation
|
|
22
|
+
|
|
23
|
+
Full documentation: **[docs.cocoar.dev/cocoar-ui-vue](https://docs.cocoar.dev/cocoar-ui-vue/foundations/localization)**
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
Apache-2.0
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { CoarLocalizationService } from './localization-service';
|
|
3
|
+
import { CoarLocalizationData } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Access the full localization service.
|
|
6
|
+
* Returns null if the localization plugin is not installed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useLocalization(): CoarLocalizationService | null;
|
|
9
|
+
/**
|
|
10
|
+
* Reactive localization composable with formatting utilities.
|
|
11
|
+
* Provides reactive language, locale data, and formatting functions
|
|
12
|
+
* that automatically update when the language changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useL10n(): {
|
|
15
|
+
/** Current language (reactive) */
|
|
16
|
+
language: Ref<string, string>;
|
|
17
|
+
/** Current locale data (reactive) */
|
|
18
|
+
localeData: ComputedRef<CoarLocalizationData | undefined>;
|
|
19
|
+
/** Format a number */
|
|
20
|
+
fmtNumber: (value: number, decimals?: number) => string;
|
|
21
|
+
/** Format a currency value */
|
|
22
|
+
fmtCurrency: (value: number, currencyCode?: string) => string;
|
|
23
|
+
/** Format a percentage (0.25 → "25%") */
|
|
24
|
+
fmtPercent: (value: number, decimals?: number) => string;
|
|
25
|
+
/** Format a date */
|
|
26
|
+
fmtDate: (value: Date | string, includeTime?: boolean) => string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* i18n composable for translations.
|
|
30
|
+
* Provides a reactive translation function.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useI18n(): {
|
|
33
|
+
/** Current language (reactive) */
|
|
34
|
+
language: Readonly<Ref<string, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Translate a key. Returns the key if no translation found.
|
|
37
|
+
* Reactive — updates when language changes.
|
|
38
|
+
*/
|
|
39
|
+
t: (key: string, params?: Record<string, unknown>, fallback?: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Create a computed translation ref that reacts to language changes.
|
|
42
|
+
*/
|
|
43
|
+
tRef: (key: string, params?: Record<string, unknown>, fallback?: string) => ComputedRef<string>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Timezone composable.
|
|
47
|
+
*/
|
|
48
|
+
export declare function useTimezone(): {
|
|
49
|
+
/** Current timezone (reactive IANA identifier) */
|
|
50
|
+
timezone: Readonly<Ref<string, string>>;
|
|
51
|
+
/** Re-resolve timezone from providers */
|
|
52
|
+
refresh: () => void | undefined;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=composables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composables.d.ts","sourceRoot":"","sources":["../src/composables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAEnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,uBAAuB,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,OAAO;IAYnB,kCAAkC;;IAElC,qCAAqC;;IAErC,sBAAsB;uBACH,MAAM,aAAa,MAAM,KAAG,MAAM;IAKrD,8BAA8B;yBACT,MAAM,iBAAiB,MAAM,KAAG,MAAM;IAK3D,yCAAyC;wBACrB,MAAM,aAAa,MAAM,KAAG,MAAM;IAKtD,oBAAoB;qBACH,IAAI,GAAG,MAAM,4BAAwB,MAAM;EAM/D;AAED;;;GAGG;AACH,wBAAgB,OAAO;IAInB,kCAAkC;;IAGlC;;;OAGG;aACM,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,MAAM,KAAG,MAAM;IAK7E;;OAEG;gBACS,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,MAAM,KAAG,WAAW,CAAC,MAAM,CAAC;EAKhG;AAED;;GAEG;AACH,wBAAgB,WAAW;IAIvB,kDAAkD;;IAUlD,yCAAyC;;EAG5C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpolate parameters into a translation string.
|
|
3
|
+
* Replaces {param} placeholders with values from the params object.
|
|
4
|
+
* Missing params are replaced with empty string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* interpolate('Hello, {name}!', { name: 'Alice' }) → 'Hello, Alice!'
|
|
8
|
+
* interpolate('{count} items', { count: 42 }) → '42 items'
|
|
9
|
+
* interpolate('Hello, {name}!', {}) → 'Hello, !'
|
|
10
|
+
*/
|
|
11
|
+
export declare function interpolate(template: string, params?: Record<string, unknown>): string;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a returned translation value is actually missing.
|
|
14
|
+
* Missing means: null, undefined, empty, whitespace-only, or equals the key itself.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isMissingTranslation(key: string, value: string | null | undefined): boolean;
|
|
17
|
+
//# sourceMappingURL=interpolate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/i18n/interpolate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAOR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAI3F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CoarTranslationSource, CoarTranslations } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Generates common translations from browser Intl APIs.
|
|
4
|
+
* Always registered as the first translation source so HTTP translations can override.
|
|
5
|
+
*
|
|
6
|
+
* Generated keys:
|
|
7
|
+
* - common.today, common.yesterday, common.tomorrow (Intl.RelativeTimeFormat)
|
|
8
|
+
* - common.month.1–12 (full month names, 1=January)
|
|
9
|
+
* - common.month.short.1–12 (abbreviated month names)
|
|
10
|
+
* - common.weekday.1–7 (full day names, 1=Monday, 7=Sunday)
|
|
11
|
+
* - common.weekday.short.1–7 (abbreviated day names)
|
|
12
|
+
*/
|
|
13
|
+
export declare class IntlTranslationSource implements CoarTranslationSource {
|
|
14
|
+
load(language: string): Promise<CoarTranslations | null>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=intl-translation-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-translation-source.d.ts","sourceRoot":"","sources":["../../src/i18n/intl-translation-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAExE;;;;;;;;;;GAUG;AACH,qBAAa,qBAAsB,YAAW,qBAAqB;IAC3D,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;CA0C/D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
import { CoarTranslations } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Reactive store for translations.
|
|
5
|
+
* Stores flat key-value maps per language, supports nested JSON flattening.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CoarTranslationStore {
|
|
8
|
+
private readonly data;
|
|
9
|
+
private readonly _version;
|
|
10
|
+
/** Reactive version counter — use in computed() to react to changes */
|
|
11
|
+
readonly version: Readonly<Ref<number>>;
|
|
12
|
+
/** Reactive set of loaded language codes */
|
|
13
|
+
readonly loadedLanguages: ComputedRef<Set<string>>;
|
|
14
|
+
/**
|
|
15
|
+
* Set translations for a language. Replaces any existing translations.
|
|
16
|
+
* Nested objects are flattened to dot-separated keys.
|
|
17
|
+
*/
|
|
18
|
+
setTranslations(language: string, translations: CoarTranslations): void;
|
|
19
|
+
/**
|
|
20
|
+
* Merge additional translations into existing ones for a language.
|
|
21
|
+
*/
|
|
22
|
+
updateTranslations(language: string, translations: CoarTranslations): void;
|
|
23
|
+
/**
|
|
24
|
+
* Get a single translation by key.
|
|
25
|
+
*/
|
|
26
|
+
getTranslation(language: string, key: string): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get all translations for a language.
|
|
29
|
+
*/
|
|
30
|
+
getTranslations(language: string): Map<string, string> | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Set a single translation.
|
|
33
|
+
*/
|
|
34
|
+
setTranslation(language: string, key: string, value: string): void;
|
|
35
|
+
hasLanguage(language: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Remove all translations for a specific language.
|
|
38
|
+
*/
|
|
39
|
+
clearLanguage(language: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Bump version to trigger reactivity without changing data.
|
|
42
|
+
* Useful after external data updates.
|
|
43
|
+
*/
|
|
44
|
+
touch(): void;
|
|
45
|
+
clear(): void;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=translation-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-store.d.ts","sourceRoot":"","sources":["../../src/i18n/translation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0C;IAC/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAiB;IAExD,4CAA4C;IAC5C,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAG/C;IAEH;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,GAAG,IAAI;IAOvE;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,GAAG,IAAI;IAO1E;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKjE;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAKlE;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAUlE,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAKtC;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKrC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAIb,KAAK,IAAI,IAAI;CAId"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { CoarLocalizationData, CoarDateFormatData, CoarNumberFormatData, CoarCurrencyFormatData, CoarPercentFormatData, CoarLocalizationConfig, CoarTimezoneProvider, CoarTranslations, CoarLocaleDataSource, CoarTranslationSource, } from './types';
|
|
2
|
+
export { CoarLocalizationService } from './localization-service';
|
|
3
|
+
export { CoarLocalizationDataStore } from './l10n/localization-data-store';
|
|
4
|
+
export { IntlLocaleDataSource } from './l10n/intl-locale-data-source';
|
|
5
|
+
export { mergeLocalizationData } from './l10n/merge-localization-data';
|
|
6
|
+
export { formatNumber, formatCurrency, formatPercent, formatDate } from './l10n/formatters';
|
|
7
|
+
export { CoarTranslationStore } from './i18n/translation-store';
|
|
8
|
+
export { interpolate, isMissingTranslation } from './i18n/interpolate';
|
|
9
|
+
export { IntlTranslationSource } from './i18n/intl-translation-source';
|
|
10
|
+
export { CoarTimezoneService, BrowserTimezoneProvider } from './timezone/timezone-service';
|
|
11
|
+
export { createCoarLocalization } from './plugin';
|
|
12
|
+
export { COAR_LOCALIZATION_KEY } from './injection-keys';
|
|
13
|
+
export { useLocalization, useL10n, useI18n, useTimezone } from './composables';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAG3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectionKey } from 'vue';
|
|
2
|
+
import { CoarLocalizationService } from './localization-service';
|
|
3
|
+
/**
|
|
4
|
+
* Injection key for the localization service.
|
|
5
|
+
* Used by useLocalization(), useI18n(), and useTimezone() composables.
|
|
6
|
+
* Also used by vue-ui components for optional inject.
|
|
7
|
+
*/
|
|
8
|
+
export declare const COAR_LOCALIZATION_KEY: InjectionKey<CoarLocalizationService>;
|
|
9
|
+
//# sourceMappingURL=injection-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-keys.d.ts","sourceRoot":"","sources":["../src/injection-keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,YAAY,CAAC,uBAAuB,CAC3C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CoarLocalizationData, CoarNumberFormatData, CoarDateFormatData } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Format a number using locale-specific separators.
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatNumber(value: number, data: CoarNumberFormatData, decimals?: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Format a number as currency.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatCurrency(value: number, data: CoarLocalizationData, currencyCode?: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Format a decimal value as percent (0.25 → "25%").
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatPercent(value: number, data: CoarLocalizationData, decimals?: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Format a Date using locale date format data.
|
|
16
|
+
* Supports Date objects and ISO date strings.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatDate(value: Date | string, data: CoarDateFormatData, includeTime?: boolean): string;
|
|
19
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/l10n/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAqBR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,oBAAoB,EAC1B,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,IAAI,EAAE,kBAAkB,EACxB,WAAW,UAAQ,GAClB,MAAM,CAgCR"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoarLocalizationData, CoarLocaleDataSource } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts locale formatting data from the browser's Intl API.
|
|
4
|
+
* Always available as the base/fallback data source.
|
|
5
|
+
*/
|
|
6
|
+
export declare class IntlLocaleDataSource implements CoarLocaleDataSource {
|
|
7
|
+
load(language: string): Promise<CoarLocalizationData>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=intl-locale-data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-locale-data-source.d.ts","sourceRoot":"","sources":["../../src/l10n/intl-locale-data-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAKpB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,oBAAoB;IACzD,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAS5D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { CoarLocalizationData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Reactive store for locale-specific formatting data.
|
|
5
|
+
* Uses a Map keyed by locale code with a version counter for reactivity.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CoarLocalizationDataStore {
|
|
8
|
+
private readonly data;
|
|
9
|
+
private readonly _version;
|
|
10
|
+
/** Reactive version counter — watch this to react to data changes */
|
|
11
|
+
readonly version: Readonly<Ref<number>>;
|
|
12
|
+
setLocaleData(locale: string, data: CoarLocalizationData): void;
|
|
13
|
+
getLocaleData(locale: string): CoarLocalizationData | undefined;
|
|
14
|
+
hasLocaleData(locale: string): boolean;
|
|
15
|
+
removeLocaleData(locale: string): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=localization-data-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-data-store.d.ts","sourceRoot":"","sources":["../../src/l10n/localization-data-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2C;IAChE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAiB;IAExD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI;IAK/D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAM/D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAKtC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKtC,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CoarLocalizationData } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Deep-merge partial locale data into a base locale data object.
|
|
4
|
+
* Partial values override base values; arrays and objects are merged at one level.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mergeLocalizationData(base: CoarLocalizationData, partial: Partial<CoarLocalizationData>): CoarLocalizationData;
|
|
7
|
+
//# sourceMappingURL=merge-localization-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-localization-data.d.ts","sourceRoot":"","sources":["../../src/l10n/merge-localization-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACrC,oBAAoB,CActB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
import { CoarLocalizationConfig, CoarLocalizationData, CoarLocaleDataSource, CoarTranslationSource } from './types';
|
|
3
|
+
import { CoarLocalizationDataStore } from './l10n/localization-data-store';
|
|
4
|
+
import { CoarTranslationStore } from './i18n/translation-store';
|
|
5
|
+
import { CoarTimezoneService } from './timezone/timezone-service';
|
|
6
|
+
/**
|
|
7
|
+
* Core localization service.
|
|
8
|
+
* Manages language state, locale data loading, translations, and timezone.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CoarLocalizationService {
|
|
11
|
+
private readonly defaultLanguage;
|
|
12
|
+
private readonly _language;
|
|
13
|
+
private readonly _loading;
|
|
14
|
+
readonly l10nStore: CoarLocalizationDataStore;
|
|
15
|
+
readonly i18nStore: CoarTranslationStore;
|
|
16
|
+
readonly timezoneService: CoarTimezoneService;
|
|
17
|
+
private readonly l10nSources;
|
|
18
|
+
private readonly i18nSources;
|
|
19
|
+
/** Reactive current language */
|
|
20
|
+
get language(): Readonly<Ref<string>>;
|
|
21
|
+
/** Reactive loading state */
|
|
22
|
+
get loading(): Readonly<Ref<boolean>>;
|
|
23
|
+
/** Computed current locale data — reactive, updates on language change */
|
|
24
|
+
readonly localeData: ComputedRef<CoarLocalizationData | undefined>;
|
|
25
|
+
constructor(config?: CoarLocalizationConfig);
|
|
26
|
+
/** Get the configured default language */
|
|
27
|
+
getDefaultLanguage(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Change the current language.
|
|
30
|
+
* Loads locale data and translations if not already cached.
|
|
31
|
+
*/
|
|
32
|
+
setLanguage(language: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Preload data for a language without switching to it.
|
|
35
|
+
*/
|
|
36
|
+
preloadLanguage(language: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Force reload data for a language from all sources, clearing the cache.
|
|
39
|
+
* Useful when external data changes at runtime (e.g. SignalR push, user profile update).
|
|
40
|
+
* If no language is specified, reloads the current language.
|
|
41
|
+
*/
|
|
42
|
+
reloadLanguage(language?: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Translate a key using the current language.
|
|
45
|
+
* For regional locales (e.g. de-AT), falls back to the base language (de).
|
|
46
|
+
* Returns the key itself if no translation is found.
|
|
47
|
+
*/
|
|
48
|
+
t(key: string, params?: Record<string, unknown>, fallback?: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Add a custom locale data source (loaded after Intl, before HTTP).
|
|
51
|
+
*/
|
|
52
|
+
addLocaleDataSource(source: CoarLocaleDataSource): void;
|
|
53
|
+
/**
|
|
54
|
+
* Add a custom translation source.
|
|
55
|
+
*/
|
|
56
|
+
addTranslationSource(source: CoarTranslationSource): void;
|
|
57
|
+
private loadDataForLanguage;
|
|
58
|
+
private loadLocaleData;
|
|
59
|
+
private loadTranslations;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=localization-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization-service.d.ts","sourceRoot":"","sources":["../src/localization-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,KAAK,EACV,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAG3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;GAGG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,QAAQ,CAAC,SAAS,EAAE,yBAAyB,CAAC;IAC9C,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IACzC,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyB;IACrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;IAEtD,gCAAgC;IAChC,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAEpC;IAED,6BAA6B;IAC7B,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAEpC;IAED,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;gBAEvD,MAAM,GAAE,sBAA2B;IA+B/C,0CAA0C;IAC1C,kBAAkB,IAAI,MAAM;IAI5B;;;OAGG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlD;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;;OAIG;IACG,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAetD;;;;OAIG;IACH,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAY3E;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAUvD;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI;YAI3C,mBAAmB;YAgBnB,cAAc;YAuBd,gBAAgB;CAqB/B"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from 'vue';
|
|
2
|
+
import { CoarLocalizationConfig } from './types';
|
|
3
|
+
import { CoarLocalizationService } from './localization-service';
|
|
4
|
+
/**
|
|
5
|
+
* Create the Coar Localization Vue plugin.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createCoarLocalization } from '@cocoar/vue-localization';
|
|
10
|
+
*
|
|
11
|
+
* const app = createApp(App);
|
|
12
|
+
* app.use(createCoarLocalization({
|
|
13
|
+
* defaultLanguage: 'en',
|
|
14
|
+
* i18nUrl: (lang) => `/i18n/${lang}.json`,
|
|
15
|
+
* l10nUrl: (lang) => `/locales/${lang}.json`,
|
|
16
|
+
* }));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createCoarLocalization(config?: CoarLocalizationConfig): Plugin & {
|
|
20
|
+
service: CoarLocalizationService;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,MAAM,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGjE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,sBAA2B,GAAG,MAAM,GAAG;IACpF,OAAO,EAAE,uBAAuB,CAAC;CAClC,CAWA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { CoarTimezoneProvider } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Default timezone provider using the browser's Intl API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BrowserTimezoneProvider implements CoarTimezoneProvider {
|
|
7
|
+
getTimezone(): string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reactive timezone service.
|
|
11
|
+
* Resolves timezone from pluggable providers with browser fallback.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CoarTimezoneService {
|
|
14
|
+
private readonly providers;
|
|
15
|
+
private readonly _timezone;
|
|
16
|
+
/** Reactive current timezone (IANA identifier) */
|
|
17
|
+
get timezone(): Readonly<Ref<string>>;
|
|
18
|
+
constructor(customProviders?: CoarTimezoneProvider[]);
|
|
19
|
+
/** Re-resolve the timezone from providers and update the reactive value */
|
|
20
|
+
refresh(): void;
|
|
21
|
+
private resolve;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=timezone-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timezone-service.d.ts","sourceRoot":"","sources":["../../src/timezone/timezone-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;GAEG;AACH,qBAAa,uBAAwB,YAAW,oBAAoB;IAClE,WAAW,IAAI,MAAM,GAAG,IAAI;CAO7B;AAED;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IAExC,kDAAkD;IAClD,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAEpC;gBAEW,eAAe,GAAE,oBAAoB,EAAO;IAKxD,2EAA2E;IAC3E,OAAO,IAAI,IAAI;IAIf,OAAO,CAAC,OAAO;CAOhB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date format data for a locale.
|
|
3
|
+
*/
|
|
4
|
+
export interface CoarDateFormatData {
|
|
5
|
+
/** Date pattern, e.g. 'dd.mm.yyyy', 'mm/dd/yyyy' */
|
|
6
|
+
pattern: 'dd.mm.yyyy' | 'dd/mm/yyyy' | 'mm/dd/yyyy' | 'yyyy-mm-dd';
|
|
7
|
+
/** First day of week: 0=Sunday, 1=Monday, ..., 6=Saturday */
|
|
8
|
+
firstDayOfWeek: number;
|
|
9
|
+
/** Full month names, e.g. ['January', 'February', ...] */
|
|
10
|
+
monthNames: string[];
|
|
11
|
+
/** Abbreviated month names, e.g. ['Jan', 'Feb', ...] */
|
|
12
|
+
monthNamesShort: string[];
|
|
13
|
+
/** Full day names, e.g. ['Sunday', 'Monday', ...] */
|
|
14
|
+
dayNames: string[];
|
|
15
|
+
/** Abbreviated day names, e.g. ['Sun', 'Mon', ...] */
|
|
16
|
+
dayNamesShort: string[];
|
|
17
|
+
/** AM/PM labels */
|
|
18
|
+
amPm: [string, string];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Number format data for a locale.
|
|
22
|
+
*/
|
|
23
|
+
export interface CoarNumberFormatData {
|
|
24
|
+
/** Decimal separator, e.g. '.' or ',' */
|
|
25
|
+
decimal: string;
|
|
26
|
+
/** Grouping separator, e.g. ',' or '.' */
|
|
27
|
+
group: string;
|
|
28
|
+
/** Grouping sizes, e.g. [3] for standard 3-digit grouping */
|
|
29
|
+
grouping: number[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Currency format data for a locale.
|
|
33
|
+
*/
|
|
34
|
+
export interface CoarCurrencyFormatData {
|
|
35
|
+
/** Default currency code, e.g. 'USD', 'EUR' */
|
|
36
|
+
default: string;
|
|
37
|
+
/** Map of currency code → symbol, e.g. { USD: '$', EUR: '€' } */
|
|
38
|
+
symbols: Record<string, string>;
|
|
39
|
+
/** Symbol position relative to the number */
|
|
40
|
+
position: 'before' | 'after';
|
|
41
|
+
/** Whether there's a space between symbol and number */
|
|
42
|
+
spacing: boolean;
|
|
43
|
+
/** Default number of decimal places */
|
|
44
|
+
decimals: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Percent format data for a locale.
|
|
48
|
+
*/
|
|
49
|
+
export interface CoarPercentFormatData {
|
|
50
|
+
/** Percent symbol */
|
|
51
|
+
symbol: string;
|
|
52
|
+
/** Whether there's a space between number and symbol */
|
|
53
|
+
spacing: boolean;
|
|
54
|
+
/** Default number of decimal places */
|
|
55
|
+
decimals: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Complete localization data for a single locale.
|
|
59
|
+
*/
|
|
60
|
+
export interface CoarLocalizationData {
|
|
61
|
+
/** Locale code, e.g. 'en', 'de', 'en-US' */
|
|
62
|
+
code: string;
|
|
63
|
+
/** Date formatting data */
|
|
64
|
+
date: CoarDateFormatData;
|
|
65
|
+
/** Number formatting data */
|
|
66
|
+
number: CoarNumberFormatData;
|
|
67
|
+
/** Currency formatting data */
|
|
68
|
+
currency: CoarCurrencyFormatData;
|
|
69
|
+
/** Percent formatting data */
|
|
70
|
+
percent: CoarPercentFormatData;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Configuration for the localization system.
|
|
74
|
+
*/
|
|
75
|
+
export interface CoarLocalizationConfig {
|
|
76
|
+
/** Default language to use. Defaults to 'en'. */
|
|
77
|
+
defaultLanguage?: string;
|
|
78
|
+
/** Custom timezone providers (checked before browser default) */
|
|
79
|
+
timezoneProviders?: CoarTimezoneProvider[];
|
|
80
|
+
/** HTTP URL builder for loading locale data. Receives language code, returns URL. */
|
|
81
|
+
l10nUrl?: (language: string) => string;
|
|
82
|
+
/** HTTP URL builder for loading translations. Receives language code, returns URL. */
|
|
83
|
+
i18nUrl?: (language: string) => string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A pluggable timezone provider.
|
|
87
|
+
* Returns the current IANA timezone identifier, or null if unknown.
|
|
88
|
+
*/
|
|
89
|
+
export interface CoarTimezoneProvider {
|
|
90
|
+
/** Returns the current timezone, or null to defer to next provider */
|
|
91
|
+
getTimezone(): string | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Nested or flat translation object.
|
|
95
|
+
* Nested objects are flattened to dot-separated keys.
|
|
96
|
+
*/
|
|
97
|
+
export interface CoarTranslations {
|
|
98
|
+
[key: string]: string | CoarTranslations;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A source that can load locale data for a given language.
|
|
102
|
+
*/
|
|
103
|
+
export interface CoarLocaleDataSource {
|
|
104
|
+
load(language: string): Promise<Partial<CoarLocalizationData> | null>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A source that can load translations for a given language.
|
|
108
|
+
*/
|
|
109
|
+
export interface CoarTranslationSource {
|
|
110
|
+
load(language: string): Promise<CoarTranslations | null>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;IACnE,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,wDAAwD;IACxD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,sDAAsD;IACtD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,mBAAmB;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,6CAA6C;IAC7C,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC7B,wDAAwD;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,IAAI,EAAE,kBAAkB,CAAC;IACzB,6BAA6B;IAC7B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,+BAA+B;IAC/B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,8BAA8B;IAC9B,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,iBAAiB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC3C,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACvC,sFAAsF;IACtF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,sEAAsE;IACtE,WAAW,IAAI,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAAC;CACvE;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocoar/vue-localization",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Locale-aware formatting (l10n), translations (i18n), and timezone detection for Vue 3",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/cocoar-dev/cocoar-ui-vue.git",
|
|
9
|
+
"directory": "packages/localization"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://docs.cocoar.dev/cocoar-ui-vue/",
|
|
12
|
+
"bugs": "https://github.com/cocoar-dev/cocoar-ui-vue/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vue",
|
|
15
|
+
"vue3",
|
|
16
|
+
"localization",
|
|
17
|
+
"i18n",
|
|
18
|
+
"l10n",
|
|
19
|
+
"timezone",
|
|
20
|
+
"intl"
|
|
21
|
+
],
|
|
4
22
|
"type": "module",
|
|
5
23
|
"sideEffects": false,
|
|
6
24
|
"main": "./dist/index.js",
|