@pie-qti/i18n 0.1.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 (78) hide show
  1. package/.turbo/turbo-build.log +264 -0
  2. package/README.md +402 -0
  3. package/dist/core/I18n.d.ts +83 -0
  4. package/dist/core/I18n.d.ts.map +1 -0
  5. package/dist/core/I18n.js +203 -0
  6. package/dist/core/I18n.js.map +1 -0
  7. package/dist/core/I18nProvider.d.ts +64 -0
  8. package/dist/core/I18nProvider.d.ts.map +1 -0
  9. package/dist/core/I18nProvider.js +9 -0
  10. package/dist/core/I18nProvider.js.map +1 -0
  11. package/dist/core/types.d.ts +20 -0
  12. package/dist/core/types.d.ts.map +1 -0
  13. package/dist/core/types.js +5 -0
  14. package/dist/core/types.js.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/locales/ar-SA.d.ts +763 -0
  20. package/dist/locales/ar-SA.d.ts.map +1 -0
  21. package/dist/locales/ar-SA.js +796 -0
  22. package/dist/locales/ar-SA.js.map +1 -0
  23. package/dist/locales/en-US.d.ts +731 -0
  24. package/dist/locales/en-US.d.ts.map +1 -0
  25. package/dist/locales/en-US.js +764 -0
  26. package/dist/locales/en-US.js.map +1 -0
  27. package/dist/locales/es-ES.d.ts +734 -0
  28. package/dist/locales/es-ES.d.ts.map +1 -0
  29. package/dist/locales/es-ES.js +758 -0
  30. package/dist/locales/es-ES.js.map +1 -0
  31. package/dist/locales/fr-FR.d.ts +733 -0
  32. package/dist/locales/fr-FR.d.ts.map +1 -0
  33. package/dist/locales/fr-FR.js +757 -0
  34. package/dist/locales/fr-FR.js.map +1 -0
  35. package/dist/locales/nl-NL.d.ts +733 -0
  36. package/dist/locales/nl-NL.d.ts.map +1 -0
  37. package/dist/locales/nl-NL.js +757 -0
  38. package/dist/locales/nl-NL.js.map +1 -0
  39. package/dist/locales/ro-RO.d.ts +733 -0
  40. package/dist/locales/ro-RO.d.ts.map +1 -0
  41. package/dist/locales/ro-RO.js +757 -0
  42. package/dist/locales/ro-RO.js.map +1 -0
  43. package/dist/locales/th-TH.d.ts +733 -0
  44. package/dist/locales/th-TH.d.ts.map +1 -0
  45. package/dist/locales/th-TH.js +758 -0
  46. package/dist/locales/th-TH.js.map +1 -0
  47. package/dist/locales/zh-CN.d.ts +731 -0
  48. package/dist/locales/zh-CN.d.ts.map +1 -0
  49. package/dist/locales/zh-CN.js +764 -0
  50. package/dist/locales/zh-CN.js.map +1 -0
  51. package/dist/providers/SvelteI18nProvider.d.ts +40 -0
  52. package/dist/providers/SvelteI18nProvider.d.ts.map +1 -0
  53. package/dist/providers/SvelteI18nProvider.js +133 -0
  54. package/dist/providers/SvelteI18nProvider.js.map +1 -0
  55. package/docs/ADVANCED_FEATURES.md +556 -0
  56. package/docs/COMPONENT_PATTERNS.md +896 -0
  57. package/docs/INTEGRATION_GUIDE.md +695 -0
  58. package/package.json +42 -0
  59. package/scripts/check-translations.ts +289 -0
  60. package/scripts/scan-hardcoded-strings.ts +266 -0
  61. package/src/components/LocaleSwitcher.svelte +145 -0
  62. package/src/components/README.md +224 -0
  63. package/src/core/I18n.ts +235 -0
  64. package/src/core/I18nProvider.ts +68 -0
  65. package/src/core/types.ts +45 -0
  66. package/src/index.ts +22 -0
  67. package/src/locales/ar-SA.ts +860 -0
  68. package/src/locales/en-US.ts +828 -0
  69. package/src/locales/es-ES.ts +816 -0
  70. package/src/locales/fr-FR.ts +815 -0
  71. package/src/locales/nl-NL.ts +815 -0
  72. package/src/locales/ro-RO.ts +815 -0
  73. package/src/locales/th-TH.ts +816 -0
  74. package/src/locales/zh-CN.ts +828 -0
  75. package/src/providers/SvelteI18nProvider.ts +170 -0
  76. package/tests/i18n.test.ts +146 -0
  77. package/tsconfig.json +10 -0
  78. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Default I18n provider implementation
3
+ *
4
+ * This is the framework's default implementation of the I18nProvider interface.
5
+ * It uses Vite's dynamic imports for lazy locale loading and provides simple
6
+ * interpolation and pluralization support.
7
+ */
8
+ import type { I18nProvider, InterpolationValues, PluralOptions } from './I18nProvider.js';
9
+ import type { LocaleCode, FrameworkLocaleCode, MessageKey, LocaleMessages } from './types.js';
10
+ export declare class DefaultI18nProvider implements I18nProvider {
11
+ private currentLocale;
12
+ private messages;
13
+ private customMessages;
14
+ private fallbackLocale;
15
+ private loadedLocales;
16
+ constructor(locale?: LocaleCode, customMessages?: Record<string, LocaleMessages>);
17
+ /**
18
+ * Load locale messages dynamically (framework locales only)
19
+ * For custom locales, use the customMessages parameter in the constructor or addCustomMessages()
20
+ */
21
+ loadLocale(locale: FrameworkLocaleCode): Promise<void>;
22
+ /**
23
+ * Set current locale
24
+ * For framework locales, loadLocale() should be called first.
25
+ * For custom locales, translations should be provided via customMessages.
26
+ */
27
+ setLocale(locale: string): void;
28
+ /**
29
+ * Get current locale
30
+ */
31
+ getLocale(): string;
32
+ /**
33
+ * Translate message key with optional interpolation
34
+ * @example t('upload.label') => "Upload a file"
35
+ * @example t('upload.selected', { name: 'file.pdf' }) => "Selected: file.pdf"
36
+ */
37
+ t(key: string, values?: Record<string, any>): string;
38
+ /**
39
+ * Pluralization support
40
+ * @example plural('upload.fileCount', { count: 1 }) => "1 file selected"
41
+ * @example plural('upload.fileCount', { count: 5 }) => "5 files selected"
42
+ */
43
+ plural(key: string, options: PluralOptions): string;
44
+ /**
45
+ * Format number according to locale
46
+ */
47
+ formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
48
+ /**
49
+ * Format date according to locale
50
+ */
51
+ formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string;
52
+ /**
53
+ * Get nested message by dot notation key
54
+ * Priority: custom messages > current locale > fallback locale
55
+ */
56
+ private getMessage;
57
+ /**
58
+ * Get message from a specific messages object
59
+ */
60
+ private getMessageFromObject;
61
+ /**
62
+ * Get message from fallback locale (framework defaults)
63
+ */
64
+ private getMessageFromFallback;
65
+ /**
66
+ * Add or update custom messages for a locale
67
+ * This allows clients to provide their own translations or override defaults
68
+ */
69
+ addCustomMessages(locale: string, messages: LocaleMessages): void;
70
+ /**
71
+ * Deep merge two objects (for merging translation objects)
72
+ */
73
+ private deepMerge;
74
+ }
75
+ /**
76
+ * Factory function to create a default i18n provider instance
77
+ * @param locale - Initial locale code (default: 'en-US')
78
+ * @param customMessages - Optional custom translations to add or override framework defaults
79
+ * @returns DefaultI18nProvider instance
80
+ */
81
+ export declare function createDefaultI18nProvider(locale?: LocaleCode, customMessages?: Record<string, LocaleMessages>): I18nProvider;
82
+ export type { LocaleCode, MessageKey, InterpolationValues, PluralOptions };
83
+ //# sourceMappingURL=I18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/core/I18n.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAa9F,qBAAa,mBAAoB,YAAW,YAAY;IACvD,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAqC;IACrD,OAAO,CAAC,cAAc,CAAiC;IACvD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,aAAa,CAA8B;gBAEvC,MAAM,GAAE,UAAoB,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;IAoBzF;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5D;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAS/B;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;;;OAIG;IACH,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;IAiBpD;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM;IAMnD;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM;IAIvE;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM;IAIpE;;;OAGG;IACH,OAAO,CAAC,UAAU;IAoBlB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAK9B;;;OAGG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI;IAOjE;;OAEG;IACH,OAAO,CAAC,SAAS;CAWjB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACxC,MAAM,GAAE,UAAoB,EAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAC7C,YAAY,CAEd;AAED,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Default I18n provider implementation
3
+ *
4
+ * This is the framework's default implementation of the I18nProvider interface.
5
+ * It uses Vite's dynamic imports for lazy locale loading and provides simple
6
+ * interpolation and pluralization support.
7
+ */
8
+ // Use Vite's glob import to load all locales dynamically
9
+ // Load en-US eagerly (default/fallback locale), others lazily
10
+ // In dev mode, Vite uses .ts files directly. In production, use .js files from dist.
11
+ // @ts-expect-error - import.meta.glob is a Vite feature, not standard TypeScript
12
+ const eagerLocales = import.meta.glob('../locales/en-US.{js,ts}', { eager: true });
13
+ // @ts-expect-error - import.meta.glob is a Vite feature, not standard TypeScript
14
+ const lazyLocales = import.meta.glob('../locales/*.{js,ts}', { eager: false });
15
+ // Combine both for lookup
16
+ const localeModules = { ...lazyLocales };
17
+ export class DefaultI18nProvider {
18
+ currentLocale;
19
+ messages;
20
+ customMessages; // Client-provided translations
21
+ fallbackLocale = 'en-US';
22
+ loadedLocales = new Set();
23
+ constructor(locale = 'en-US', customMessages) {
24
+ // Read persisted locale from localStorage if available
25
+ // This allows locale changes to persist across page reloads
26
+ const storedLocale = typeof localStorage !== 'undefined'
27
+ ? localStorage.getItem('pie-qti-locale')
28
+ : null;
29
+ this.currentLocale = storedLocale || locale;
30
+ this.messages = {};
31
+ this.customMessages = customMessages || {};
32
+ // Load en-US eagerly from the eager imports to ensure immediate availability
33
+ // Try both .ts (dev) and .js (prod) extensions
34
+ const enUSModule = (eagerLocales['../locales/en-US.ts'] || eagerLocales['../locales/en-US.js']);
35
+ if (enUSModule) {
36
+ this.messages['en-US'] = enUSModule.default;
37
+ this.loadedLocales.add('en-US');
38
+ }
39
+ }
40
+ /**
41
+ * Load locale messages dynamically (framework locales only)
42
+ * For custom locales, use the customMessages parameter in the constructor or addCustomMessages()
43
+ */
44
+ async loadLocale(locale) {
45
+ if (this.loadedLocales.has(locale)) {
46
+ return; // Already loaded
47
+ }
48
+ try {
49
+ // Try both .ts (dev) and .js (prod) extensions
50
+ const modulePathTs = `../locales/${locale}.ts`;
51
+ const modulePathJs = `../locales/${locale}.js`;
52
+ const loader = localeModules[modulePathTs] || localeModules[modulePathJs];
53
+ if (!loader) {
54
+ throw new Error(`Locale '${locale}' not found in available modules`);
55
+ }
56
+ const module = await loader();
57
+ this.messages[locale] = module.default;
58
+ this.loadedLocales.add(locale);
59
+ }
60
+ catch (error) {
61
+ console.error(`[i18n] Failed to load locale '${locale}':`, error);
62
+ throw error;
63
+ }
64
+ }
65
+ /**
66
+ * Set current locale
67
+ * For framework locales, loadLocale() should be called first.
68
+ * For custom locales, translations should be provided via customMessages.
69
+ */
70
+ setLocale(locale) {
71
+ // Allow setting custom locales even if not in loadedLocales
72
+ // They will use customMessages + fallback to en-US
73
+ if (!this.loadedLocales.has(locale) && !this.customMessages[locale]) {
74
+ console.warn(`[i18n] Locale '${locale}' not loaded and no custom messages provided. Using fallback locale.`);
75
+ }
76
+ this.currentLocale = locale;
77
+ }
78
+ /**
79
+ * Get current locale
80
+ */
81
+ getLocale() {
82
+ return this.currentLocale;
83
+ }
84
+ /**
85
+ * Translate message key with optional interpolation
86
+ * @example t('upload.label') => "Upload a file"
87
+ * @example t('upload.selected', { name: 'file.pdf' }) => "Selected: file.pdf"
88
+ */
89
+ t(key, values) {
90
+ const message = this.getMessage(key);
91
+ if (!message) {
92
+ if (process.env.NODE_ENV === 'development') {
93
+ console.warn(`[i18n] Missing translation: ${key} (locale: ${this.currentLocale})`);
94
+ }
95
+ return key; // Fallback to key itself
96
+ }
97
+ if (!values)
98
+ return message;
99
+ // Simple interpolation: replace {key} with values[key]
100
+ return message.replace(/\{(\w+)\}/g, (match, key) => {
101
+ return String(values[key] ?? match);
102
+ });
103
+ }
104
+ /**
105
+ * Pluralization support
106
+ * @example plural('upload.fileCount', { count: 1 }) => "1 file selected"
107
+ * @example plural('upload.fileCount', { count: 5 }) => "5 files selected"
108
+ */
109
+ plural(key, options) {
110
+ const { count } = options;
111
+ const pluralKey = count === 1 ? `${key}.one` : `${key}.other`;
112
+ return this.t(pluralKey, options);
113
+ }
114
+ /**
115
+ * Format number according to locale
116
+ */
117
+ formatNumber(value, options) {
118
+ return new Intl.NumberFormat(this.currentLocale, options).format(value);
119
+ }
120
+ /**
121
+ * Format date according to locale
122
+ */
123
+ formatDate(date, options) {
124
+ return new Intl.DateTimeFormat(this.currentLocale, options).format(date);
125
+ }
126
+ /**
127
+ * Get nested message by dot notation key
128
+ * Priority: custom messages > current locale > fallback locale
129
+ */
130
+ getMessage(key) {
131
+ // 1. Try custom messages first (client overrides)
132
+ const customMessage = this.getMessageFromObject(key, this.customMessages[this.currentLocale]);
133
+ if (customMessage !== undefined)
134
+ return customMessage;
135
+ // 2. Try current locale from framework defaults
136
+ const messages = this.messages[this.currentLocale];
137
+ if (messages) {
138
+ const message = this.getMessageFromObject(key, messages);
139
+ if (message !== undefined)
140
+ return message;
141
+ }
142
+ // 3. Try custom fallback locale
143
+ const customFallback = this.getMessageFromObject(key, this.customMessages[this.fallbackLocale]);
144
+ if (customFallback !== undefined)
145
+ return customFallback;
146
+ // 4. Try framework fallback locale
147
+ return this.getMessageFromFallback(key);
148
+ }
149
+ /**
150
+ * Get message from a specific messages object
151
+ */
152
+ getMessageFromObject(key, messages) {
153
+ if (!messages)
154
+ return undefined;
155
+ const parts = key.split('.');
156
+ let current = messages;
157
+ for (const part of parts) {
158
+ current = current[part];
159
+ if (current === undefined)
160
+ return undefined;
161
+ }
162
+ return current;
163
+ }
164
+ /**
165
+ * Get message from fallback locale (framework defaults)
166
+ */
167
+ getMessageFromFallback(key) {
168
+ const messages = this.messages[this.fallbackLocale];
169
+ return this.getMessageFromObject(key, messages);
170
+ }
171
+ /**
172
+ * Add or update custom messages for a locale
173
+ * This allows clients to provide their own translations or override defaults
174
+ */
175
+ addCustomMessages(locale, messages) {
176
+ this.customMessages[locale] = this.deepMerge(this.customMessages[locale] || {}, messages);
177
+ }
178
+ /**
179
+ * Deep merge two objects (for merging translation objects)
180
+ */
181
+ deepMerge(target, source) {
182
+ const result = { ...target };
183
+ for (const key in source) {
184
+ if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
185
+ result[key] = this.deepMerge(result[key] || {}, source[key]);
186
+ }
187
+ else {
188
+ result[key] = source[key];
189
+ }
190
+ }
191
+ return result;
192
+ }
193
+ }
194
+ /**
195
+ * Factory function to create a default i18n provider instance
196
+ * @param locale - Initial locale code (default: 'en-US')
197
+ * @param customMessages - Optional custom translations to add or override framework defaults
198
+ * @returns DefaultI18nProvider instance
199
+ */
200
+ export function createDefaultI18nProvider(locale = 'en-US', customMessages) {
201
+ return new DefaultI18nProvider(locale, customMessages);
202
+ }
203
+ //# sourceMappingURL=I18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../src/core/I18n.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,yDAAyD;AACzD,8DAA8D;AAC9D,qFAAqF;AACrF,iFAAiF;AACjF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACnF,iFAAiF;AACjF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAE/E,0BAA0B;AAC1B,MAAM,aAAa,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;AAEzC,MAAM,OAAO,mBAAmB;IACvB,aAAa,CAAa;IAC1B,QAAQ,CAAqC;IAC7C,cAAc,CAAiC,CAAC,+BAA+B;IAC/E,cAAc,GAAe,OAAO,CAAC;IACrC,aAAa,GAAoB,IAAI,GAAG,EAAE,CAAC;IAEnD,YAAY,SAAqB,OAAO,EAAE,cAA+C;QACxF,uDAAuD;QACvD,4DAA4D;QAC5D,MAAM,YAAY,GAAG,OAAO,YAAY,KAAK,WAAW;YACvD,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC;YACxC,CAAC,CAAC,IAAI,CAAC;QAER,IAAI,CAAC,aAAa,GAAI,YAA2B,IAAI,MAAM,CAAC;QAC5D,IAAI,CAAC,QAAQ,GAAG,EAAwC,CAAC;QACzD,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,EAAE,CAAC;QAE3C,6EAA6E;QAC7E,+CAA+C;QAC/C,MAAM,UAAU,GAAG,CAAC,YAAY,CAAC,qBAAqB,CAAC,IAAI,YAAY,CAAC,qBAAqB,C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;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,SAAqB,OAAO,EAC5B,cAA+C;IAE/C,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Framework-agnostic i18n provider interface
3
+ *
4
+ * This interface defines the contract for internationalization services.
5
+ * Users can provide their own implementations (ICU MessageFormat, i18next, etc.)
6
+ * or use the default implementation provided by the framework.
7
+ */
8
+ export interface I18nProvider {
9
+ /**
10
+ * Get the current locale code (e.g., 'en-US', 'fr-FR')
11
+ */
12
+ getLocale(): string;
13
+ /**
14
+ * Set the current locale and optionally load locale messages
15
+ * @param locale - BCP 47 locale code
16
+ */
17
+ setLocale(locale: string): Promise<void> | void;
18
+ /**
19
+ * Translate a message key with optional default and/or interpolation
20
+ * @param key - Message key (e.g., 'common.submit', 'assessment.question')
21
+ * @param defaultOrValues - Optional default string or interpolation values
22
+ * @param values - Optional interpolation values (if second arg is default string)
23
+ * @returns Translated message, default, or key if not found
24
+ */
25
+ t(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string;
26
+ /**
27
+ * Optional: Pluralization support
28
+ * @param key - Base message key
29
+ * @param options - Options including count and interpolation values
30
+ * @returns Pluralized and translated message
31
+ */
32
+ plural?(key: string, options: {
33
+ count: number;
34
+ [key: string]: any;
35
+ }): string;
36
+ /**
37
+ * Optional: Format number according to locale
38
+ * @param value - Number to format
39
+ * @param options - Intl.NumberFormat options
40
+ * @returns Formatted number string
41
+ */
42
+ formatNumber?(value: number, options?: Intl.NumberFormatOptions): string;
43
+ /**
44
+ * Optional: Format date according to locale
45
+ * @param date - Date to format
46
+ * @param options - Intl.DateTimeFormat options
47
+ * @returns Formatted date string
48
+ */
49
+ formatDate?(date: Date, options?: Intl.DateTimeFormatOptions): string;
50
+ }
51
+ /**
52
+ * Interpolation values for dynamic message content
53
+ */
54
+ export interface InterpolationValues {
55
+ [key: string]: string | number;
56
+ }
57
+ /**
58
+ * Pluralization options
59
+ */
60
+ export interface PluralOptions {
61
+ count: number;
62
+ [key: string]: string | number;
63
+ }
64
+ //# sourceMappingURL=I18nProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18nProvider.d.ts","sourceRoot":"","sources":["../../src/core/I18nProvider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEhD;;;;;;OAMG;IACH,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;IAErG;;;;;OAKG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,MAAM,CAAC;IAE7E;;;;;OAKG;IACH,YAAY,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC;IAEzE;;;;;OAKG;IACH,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAC/B"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Framework-agnostic i18n provider interface
3
+ *
4
+ * This interface defines the contract for internationalization services.
5
+ * Users can provide their own implementations (ICU MessageFormat, i18next, etc.)
6
+ * or use the default implementation provided by the framework.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=I18nProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18nProvider.js","sourceRoot":"","sources":["../../src/core/I18nProvider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Type definitions for i18n system
3
+ */
4
+ import type enUS from '../locales/en-US.js';
5
+ export type FrameworkLocaleCode = 'en-US' | 'es-ES' | 'fr-FR' | 'nl-NL' | 'ro-RO' | 'th-TH' | 'zh-CN' | 'ar-SA';
6
+ export type LocaleCode = FrameworkLocaleCode | (string & {});
7
+ type NestedKeyOfHelper<ObjectType extends object> = {
8
+ [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object ? `${Key}` | `${Key}.${NestedKeyOfHelper<ObjectType[Key]>}` : `${Key}`;
9
+ }[keyof ObjectType & (string | number)];
10
+ export type MessageKey = NestedKeyOfHelper<typeof enUS>;
11
+ export interface InterpolationValues {
12
+ [key: string]: string | number;
13
+ }
14
+ export interface PluralOptions {
15
+ count: number;
16
+ [key: string]: string | number;
17
+ }
18
+ export type LocaleMessages = Record<string, any>;
19
+ export {};
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAC;AAK5C,MAAM,MAAM,mBAAmB,GAC5B,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,CAAC;AAGX,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAG7D,KAAK,iBAAiB,CAAC,UAAU,SAAS,MAAM,IAAI;KAClD,GAAG,IAAI,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,MAAM,GAC1E,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,GACzD,GAAG,GAAG,EAAE;CACX,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;AAGxC,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,IAAI,CAAC,CAAC;AAGxD,MAAM,WAAW,mBAAmB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAC/B;AAGD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAC/B;AAGD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type definitions for i18n system
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public API exports for @pie-qti/i18n package
3
+ */
4
+ export type { I18nProvider, InterpolationValues, PluralOptions } from './core/I18nProvider.js';
5
+ export { DefaultI18nProvider, createDefaultI18nProvider } from './core/I18n.js';
6
+ export { SvelteI18nProvider, createSvelteI18nProvider, createDefaultSvelteI18nProvider } from './providers/SvelteI18nProvider.js';
7
+ export type { LocaleCode, MessageKey, LocaleMessages, } from './core/types.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAG/F,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAGhF,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAGlI,YAAY,EACX,UAAU,EACV,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Public API exports for @pie-qti/i18n package
3
+ */
4
+ // Default implementation
5
+ export { DefaultI18nProvider, createDefaultI18nProvider } from './core/I18n.js';
6
+ // Svelte-specific provider with reactive stores
7
+ export { SvelteI18nProvider, createSvelteI18nProvider, createDefaultSvelteI18nProvider } from './providers/SvelteI18nProvider.js';
8
+ // Example components (commented out - Svelte files need special build process)
9
+ // export { default as LocaleSwitcher } from './components/LocaleSwitcher.svelte';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,yBAAyB;AACzB,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,gDAAgD;AAChD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AASlI,+EAA+E;AAC/E,kFAAkF"}