@pie-qti/i18n 0.1.20 → 0.1.22

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.
@@ -2,12 +2,14 @@
2
2
  * Default I18n provider implementation
3
3
  *
4
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
5
+ * It uses standard dynamic imports for lazy locale loading and provides simple
6
6
  * interpolation and pluralization support.
7
7
  */
8
8
  import type { I18nProvider, InterpolationValues, PluralOptions } from './I18nProvider.js';
9
9
  import type { LocaleCode, FrameworkLocaleCode, MessageKey, LocaleMessages } from './types.js';
10
10
  export declare class DefaultI18nProvider implements I18nProvider {
11
+ /** Shared across instances: constructing Intl.PluralRules is not cheap */
12
+ private static pluralRules;
11
13
  private currentLocale;
12
14
  private messages;
13
15
  private customMessages;
@@ -38,10 +40,39 @@ export declare class DefaultI18nProvider implements I18nProvider {
38
40
  t(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string;
39
41
  /**
40
42
  * Pluralization support
41
- * @example plural('upload.fileCount', { count: 1 }) => "1 file selected"
42
- * @example plural('upload.fileCount', { count: 5 }) => "5 files selected"
43
+ *
44
+ * The plural category comes from `Intl.PluralRules` for the active locale, so
45
+ * locales with more than two forms resolve correctly: Arabic selects between
46
+ * zero/one/two/few/many/other, Romanian between one/few/other. A locale whose
47
+ * catalog does not carry the selected category falls back to `.other`.
48
+ *
49
+ * @example plural('plurals.files', { count: 1 }) => "1 file selected"
50
+ * @example plural('plurals.files', { count: 5 }) => "5 files selected"
43
51
  */
44
52
  plural(key: string, options: PluralOptions): string;
53
+ /**
54
+ * Select the CLDR plural category for a count in the active locale
55
+ *
56
+ * Falls back to the English one/other split if the locale tag is not one
57
+ * `Intl.PluralRules` accepts — a host may set an arbitrary custom locale code.
58
+ */
59
+ private selectPluralCategory;
60
+ /**
61
+ * Writing direction of the current locale
62
+ *
63
+ * @example getDirection() => 'rtl' for ar-SA, 'ltr' for en-US
64
+ */
65
+ getDirection(): 'ltr' | 'rtl';
66
+ /**
67
+ * A view of this provider fixed to another locale
68
+ *
69
+ * Catalogs, loaded-locale bookkeeping and custom messages are shared by
70
+ * reference, so `loadLocale()` through either side is visible to both and no
71
+ * catalog is parsed twice. This is what lets two players on one page render
72
+ * different locales from one provider: the locale is per-view, the catalogs
73
+ * are per-provider.
74
+ */
75
+ withLocale(locale: LocaleCode): I18nProvider;
45
76
  /**
46
77
  * Format number according to locale
47
78
  */
@@ -57,6 +88,11 @@ export declare class DefaultI18nProvider implements I18nProvider {
57
88
  private getMessage;
58
89
  /**
59
90
  * Get message from a specific messages object
91
+ *
92
+ * Resolves to a string or nothing. A key that lands on a namespace branch
93
+ * (`t('common')`) or on a plural sub-object (`t('plurals.items')`) is a miss,
94
+ * not a hit: returning the branch would put an object where the caller
95
+ * expects a string, and interpolating one throws.
60
96
  */
61
97
  private getMessageFromObject;
62
98
  /**
package/dist/core/I18n.js CHANGED
@@ -2,19 +2,70 @@
2
2
  * Default I18n provider implementation
3
3
  *
4
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
5
+ * It uses standard dynamic imports for lazy locale loading and provides simple
6
6
  * interpolation and pluralization support.
7
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 };
8
+ import enUS from '../locales/en-US.js';
9
+ /**
10
+ * Lazy loaders for the framework locales.
11
+ *
12
+ * An explicit static map rather than a bundler macro: `tsc` emits these
13
+ * `import()` calls verbatim, so the published package evaluates anywhere ESM
14
+ * does — webpack, esbuild, Rollup, Node, or a browser loading the files
15
+ * directly. Every bundler still sees the specifiers statically, so each locale
16
+ * remains its own chunk and a host that only renders English never fetches the
17
+ * others. Adding a locale means adding a line here alongside the file.
18
+ *
19
+ * en-US is a plain static import because it is the fallback for every missing
20
+ * key in every other locale, so it must be resolvable synchronously in the
21
+ * constructor.
22
+ */
23
+ const localeLoaders = {
24
+ 'en-US': () => Promise.resolve({ default: enUS }),
25
+ 'ar-SA': () => import('../locales/ar-SA.js'),
26
+ 'es-ES': () => import('../locales/es-ES.js'),
27
+ 'fr-FR': () => import('../locales/fr-FR.js'),
28
+ 'nl-NL': () => import('../locales/nl-NL.js'),
29
+ 'ro-RO': () => import('../locales/ro-RO.js'),
30
+ 'th-TH': () => import('../locales/th-TH.js'),
31
+ 'zh-CN': () => import('../locales/zh-CN.js'),
32
+ };
33
+ /**
34
+ * Whether to log missing-translation warnings.
35
+ *
36
+ * `process` does not exist in a plain browser, so the read is guarded rather
37
+ * than bare: an unguarded `process.env.NODE_ENV` throws a ReferenceError on the
38
+ * missing-key path for any consumer that is not running the code through a
39
+ * bundler that substitutes it.
40
+ */
41
+ const isDevelopment = typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
42
+ /**
43
+ * Right-to-left primary language subtags.
44
+ *
45
+ * Only consulted when `Intl.Locale.prototype.textInfo` is unavailable — it is the
46
+ * authoritative source but shipped late in Safari, and an assessment rendered
47
+ * left-to-right for an Arabic reader is not a graceful degradation.
48
+ */
49
+ const RTL_LANGUAGES = new Set([
50
+ 'ar', // Arabic
51
+ 'ckb', // Central Kurdish
52
+ 'dv', // Dhivehi
53
+ 'fa', // Persian
54
+ 'he',
55
+ 'iw', // Hebrew (current and legacy subtags)
56
+ 'ks', // Kashmiri
57
+ 'ku', // Kurdish
58
+ 'nqo', // N'Ko
59
+ 'ps', // Pashto
60
+ 'sd', // Sindhi
61
+ 'syr', // Syriac
62
+ 'ug', // Uyghur
63
+ 'ur', // Urdu
64
+ 'yi', // Yiddish
65
+ ]);
17
66
  export class DefaultI18nProvider {
67
+ /** Shared across instances: constructing Intl.PluralRules is not cheap */
68
+ static pluralRules = new Map();
18
69
  currentLocale;
19
70
  messages;
20
71
  customMessages; // Client-provided translations
@@ -29,13 +80,9 @@ export class DefaultI18nProvider {
29
80
  this.currentLocale = storedLocale || locale;
30
81
  this.messages = {};
31
82
  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
- }
83
+ // en-US is the fallback for every other locale, so it is always present
84
+ this.messages['en-US'] = enUS;
85
+ this.loadedLocales.add('en-US');
39
86
  }
40
87
  /**
41
88
  * Load locale messages dynamically (framework locales only)
@@ -46,12 +93,9 @@ export class DefaultI18nProvider {
46
93
  return; // Already loaded
47
94
  }
48
95
  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];
96
+ const loader = localeLoaders[locale];
53
97
  if (!loader) {
54
- throw new Error(`Locale '${locale}' not found in available modules`);
98
+ throw new Error(`Locale '${locale}' is not a framework locale`);
55
99
  }
56
100
  const module = await loader();
57
101
  this.messages[locale] = module.default;
@@ -94,7 +138,7 @@ export class DefaultI18nProvider {
94
138
  : values;
95
139
  const defaultStr = typeof defaultOrValues === 'string' ? defaultOrValues : undefined;
96
140
  if (!message) {
97
- if (process.env.NODE_ENV === 'development') {
141
+ if (isDevelopment) {
98
142
  console.warn(`[i18n] Missing translation: ${key} (locale: ${this.currentLocale})`);
99
143
  }
100
144
  return defaultStr ?? key;
@@ -108,14 +152,80 @@ export class DefaultI18nProvider {
108
152
  }
109
153
  /**
110
154
  * Pluralization support
111
- * @example plural('upload.fileCount', { count: 1 }) => "1 file selected"
112
- * @example plural('upload.fileCount', { count: 5 }) => "5 files selected"
155
+ *
156
+ * The plural category comes from `Intl.PluralRules` for the active locale, so
157
+ * locales with more than two forms resolve correctly: Arabic selects between
158
+ * zero/one/two/few/many/other, Romanian between one/few/other. A locale whose
159
+ * catalog does not carry the selected category falls back to `.other`.
160
+ *
161
+ * @example plural('plurals.files', { count: 1 }) => "1 file selected"
162
+ * @example plural('plurals.files', { count: 5 }) => "5 files selected"
113
163
  */
114
164
  plural(key, options) {
115
165
  const { count } = options;
116
- const pluralKey = count === 1 ? `${key}.one` : `${key}.other`;
166
+ const category = this.selectPluralCategory(count);
167
+ const categoryKey = `${key}.${category}`;
168
+ const pluralKey = this.getMessage(categoryKey) !== undefined ? categoryKey : `${key}.other`;
117
169
  return this.t(pluralKey, options);
118
170
  }
171
+ /**
172
+ * Select the CLDR plural category for a count in the active locale
173
+ *
174
+ * Falls back to the English one/other split if the locale tag is not one
175
+ * `Intl.PluralRules` accepts — a host may set an arbitrary custom locale code.
176
+ */
177
+ selectPluralCategory(count) {
178
+ let rules = DefaultI18nProvider.pluralRules.get(this.currentLocale);
179
+ if (!rules) {
180
+ try {
181
+ rules = new Intl.PluralRules(this.currentLocale);
182
+ }
183
+ catch {
184
+ return count === 1 ? 'one' : 'other';
185
+ }
186
+ DefaultI18nProvider.pluralRules.set(this.currentLocale, rules);
187
+ }
188
+ return rules.select(count);
189
+ }
190
+ /**
191
+ * Writing direction of the current locale
192
+ *
193
+ * @example getDirection() => 'rtl' for ar-SA, 'ltr' for en-US
194
+ */
195
+ getDirection() {
196
+ try {
197
+ // textInfo is the authoritative CLDR answer where the engine has it
198
+ const textInfo = new Intl.Locale(this.currentLocale)
199
+ .textInfo;
200
+ if (textInfo?.direction === 'rtl' || textInfo?.direction === 'ltr') {
201
+ return textInfo.direction;
202
+ }
203
+ }
204
+ catch {
205
+ // Not a tag Intl.Locale accepts; the subtag check below still works
206
+ }
207
+ const language = this.currentLocale.toLowerCase().split(/[-_]/)[0] ?? '';
208
+ return RTL_LANGUAGES.has(language) ? 'rtl' : 'ltr';
209
+ }
210
+ /**
211
+ * A view of this provider fixed to another locale
212
+ *
213
+ * Catalogs, loaded-locale bookkeeping and custom messages are shared by
214
+ * reference, so `loadLocale()` through either side is visible to both and no
215
+ * catalog is parsed twice. This is what lets two players on one page render
216
+ * different locales from one provider: the locale is per-view, the catalogs
217
+ * are per-provider.
218
+ */
219
+ withLocale(locale) {
220
+ if (locale === this.currentLocale)
221
+ return this;
222
+ const view = new DefaultI18nProvider(locale, this.customMessages);
223
+ // The constructor prefers a persisted locale; an explicit view must not.
224
+ view.currentLocale = locale;
225
+ view.messages = this.messages;
226
+ view.loadedLocales = this.loadedLocales;
227
+ return view;
228
+ }
119
229
  /**
120
230
  * Format number according to locale
121
231
  */
@@ -153,6 +263,11 @@ export class DefaultI18nProvider {
153
263
  }
154
264
  /**
155
265
  * Get message from a specific messages object
266
+ *
267
+ * Resolves to a string or nothing. A key that lands on a namespace branch
268
+ * (`t('common')`) or on a plural sub-object (`t('plurals.items')`) is a miss,
269
+ * not a hit: returning the branch would put an object where the caller
270
+ * expects a string, and interpolating one throws.
156
271
  */
157
272
  getMessageFromObject(key, messages) {
158
273
  if (!messages)
@@ -160,11 +275,13 @@ export class DefaultI18nProvider {
160
275
  const parts = key.split('.');
161
276
  let current = messages;
162
277
  for (const part of parts) {
278
+ if (current === null || typeof current !== 'object')
279
+ return undefined;
163
280
  current = current[part];
164
281
  if (current === undefined)
165
282
  return undefined;
166
283
  }
167
- return current;
284
+ return typeof current === 'string' ? current : undefined;
168
285
  }
169
286
  /**
170
287
  * Get message from fallback locale (framework defaults)
@@ -1 +1 @@
1
- {"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../src/core/I18n.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,yDAAyD;AACzD,8DAA8D;AAC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,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,SAAqB,OAAO,EAC5B,cAA+C;IAE/C,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/**\n * Default I18n provider implementation\n *\n * This is the framework's default implementation of the I18nProvider interface.\n * It uses Vite's dynamic imports for lazy locale loading and provides simple\n * interpolation and pluralization support.\n */\n\nimport type { I18nProvider, InterpolationValues, PluralOptions } from './I18nProvider.js';\nimport type { LocaleCode, FrameworkLocaleCode, MessageKey, LocaleMessages } from './types.js';\n\n// Use Vite's glob import to load all locales dynamically\n// Load en-US eagerly (default/fallback locale), others lazily\n// In dev mode, Vite uses .ts files directly. In production, use .js files from dist.\n// @ts-expect-error - import.meta.glob is a Vite feature, not standard TypeScript\nconst eagerLocales = import.meta.glob('../locales/en-US.{js,ts}', { eager: true });\n// @ts-expect-error - import.meta.glob is a Vite feature, not standard TypeScript\nconst lazyLocales = import.meta.glob('../locales/*.{js,ts}', { eager: false });\n\n// Combine both for lookup\nconst localeModules = { ...lazyLocales };\n\nexport class DefaultI18nProvider implements I18nProvider {\n\tprivate currentLocale: LocaleCode;\n\tprivate messages: Record<LocaleCode, LocaleMessages>;\n\tprivate customMessages: Record<string, LocaleMessages>; // Client-provided translations\n\tprivate fallbackLocale: LocaleCode = 'en-US';\n\tprivate loadedLocales: Set<LocaleCode> = new Set();\n\n\tconstructor(locale: LocaleCode = 'en-US', customMessages?: Record<string, LocaleMessages>) {\n\t\t// Read persisted locale from localStorage if available\n\t\t// This allows locale changes to persist across page reloads\n\t\tconst storedLocale = typeof localStorage !== 'undefined'\n\t\t\t? localStorage.getItem('pie-qti-locale')\n\t\t\t: null;\n\n\t\tthis.currentLocale = (storedLocale as LocaleCode) || locale;\n\t\tthis.messages = {} as Record<LocaleCode, LocaleMessages>;\n\t\tthis.customMessages = customMessages || {};\n\n\t\t// Load en-US eagerly from the eager imports to ensure immediate availability\n\t\t// Try both .ts (dev) and .js (prod) extensions\n\t\tconst enUSModule = (eagerLocales['../locales/en-US.ts'] || eagerLocales['../locales/en-US.js']) as any;\n\t\tif (enUSModule) {\n\t\t\tthis.messages['en-US'] = enUSModule.default;\n\t\t\tthis.loadedLocales.add('en-US');\n\t\t}\n\t}\n\n\t/**\n\t * Load locale messages dynamically (framework locales only)\n\t * For custom locales, use the customMessages parameter in the constructor or addCustomMessages()\n\t */\n\tasync loadLocale(locale: FrameworkLocaleCode): Promise<void> {\n\t\tif (this.loadedLocales.has(locale)) {\n\t\t\treturn; // Already loaded\n\t\t}\n\n\t\ttry {\n\t\t\t// Try both .ts (dev) and .js (prod) extensions\n\t\t\tconst modulePathTs = `../locales/${locale}.ts`;\n\t\t\tconst modulePathJs = `../locales/${locale}.js`;\n\t\t\tconst loader = localeModules[modulePathTs] || localeModules[modulePathJs];\n\n\t\t\tif (!loader) {\n\t\t\t\tthrow new Error(`Locale '${locale}' not found in available modules`);\n\t\t\t}\n\n\t\t\tconst module = await loader();\n\t\t\tthis.messages[locale] = (module as any).default;\n\t\t\tthis.loadedLocales.add(locale);\n\t\t} catch (error) {\n\t\t\tconsole.error(`[i18n] Failed to load locale '${locale}':`, error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Set current locale\n\t * For framework locales, loadLocale() should be called first.\n\t * For custom locales, translations should be provided via customMessages.\n\t */\n\tsetLocale(locale: string): void {\n\t\t// Allow setting custom locales even if not in loadedLocales\n\t\t// They will use customMessages + fallback to en-US\n\t\tif (!this.loadedLocales.has(locale as LocaleCode) && !this.customMessages[locale]) {\n\t\t\tconsole.warn(`[i18n] Locale '${locale}' not loaded and no custom messages provided. Using fallback locale.`);\n\t\t}\n\t\tthis.currentLocale = locale as LocaleCode;\n\t}\n\n\t/**\n\t * Get current locale\n\t */\n\tgetLocale(): string {\n\t\treturn this.currentLocale;\n\t}\n\n\t/**\n\t * Translate message key with optional default and/or interpolation\n\t * @example t('upload.label') => \"Upload a file\"\n\t * @example t('upload.label', 'Upload') => translated or \"Upload\" if missing\n\t * @example t('upload.selected', { name: 'file.pdf' }) => \"Selected: file.pdf\"\n\t */\n\tt(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string {\n\t\tconst message = this.getMessage(key);\n\t\tconst interpolationValues = typeof defaultOrValues === 'object' && defaultOrValues !== null\n\t\t\t? defaultOrValues\n\t\t\t: values;\n\t\tconst defaultStr = typeof defaultOrValues === 'string' ? defaultOrValues : undefined;\n\n\t\tif (!message) {\n\t\t\tif (process.env.NODE_ENV === 'development') {\n\t\t\t\tconsole.warn(`[i18n] Missing translation: ${key} (locale: ${this.currentLocale})`);\n\t\t\t}\n\t\t\treturn defaultStr ?? key;\n\t\t}\n\n\t\tif (!interpolationValues) return message;\n\n\t\t// Simple interpolation: replace {key} with values[key]\n\t\treturn message.replace(/\\{(\\w+)\\}/g, (match, k) => {\n\t\t\treturn String(interpolationValues[k] ?? match);\n\t\t});\n\t}\n\n\t/**\n\t * Pluralization support\n\t * @example plural('upload.fileCount', { count: 1 }) => \"1 file selected\"\n\t * @example plural('upload.fileCount', { count: 5 }) => \"5 files selected\"\n\t */\n\tplural(key: string, options: PluralOptions): string {\n\t\tconst { count } = options;\n\t\tconst pluralKey = count === 1 ? `${key}.one` : `${key}.other`;\n\t\treturn this.t(pluralKey, options);\n\t}\n\n\t/**\n\t * Format number according to locale\n\t */\n\tformatNumber(value: number, options?: Intl.NumberFormatOptions): string {\n\t\treturn new Intl.NumberFormat(this.currentLocale, options).format(value);\n\t}\n\n\t/**\n\t * Format date according to locale\n\t */\n\tformatDate(date: Date, options?: Intl.DateTimeFormatOptions): string {\n\t\treturn new Intl.DateTimeFormat(this.currentLocale, options).format(date);\n\t}\n\n\t/**\n\t * Get nested message by dot notation key\n\t * Priority: custom messages > current locale > fallback locale\n\t */\n\tprivate getMessage(key: string): string | undefined {\n\t\t// 1. Try custom messages first (client overrides)\n\t\tconst customMessage = this.getMessageFromObject(key, this.customMessages[this.currentLocale]);\n\t\tif (customMessage !== undefined) return customMessage;\n\n\t\t// 2. Try current locale from framework defaults\n\t\tconst messages = this.messages[this.currentLocale];\n\t\tif (messages) {\n\t\t\tconst message = this.getMessageFromObject(key, messages);\n\t\t\tif (message !== undefined) return message;\n\t\t}\n\n\t\t// 3. Try custom fallback locale\n\t\tconst customFallback = this.getMessageFromObject(key, this.customMessages[this.fallbackLocale]);\n\t\tif (customFallback !== undefined) return customFallback;\n\n\t\t// 4. Try framework fallback locale\n\t\treturn this.getMessageFromFallback(key);\n\t}\n\n\t/**\n\t * Get message from a specific messages object\n\t */\n\tprivate getMessageFromObject(key: string, messages: any): string | undefined {\n\t\tif (!messages) return undefined;\n\n\t\tconst parts = key.split('.');\n\t\tlet current: any = messages;\n\n\t\tfor (const part of parts) {\n\t\t\tcurrent = current[part];\n\t\t\tif (current === undefined) return undefined;\n\t\t}\n\n\t\treturn current;\n\t}\n\n\t/**\n\t * Get message from fallback locale (framework defaults)\n\t */\n\tprivate getMessageFromFallback(key: string): string | undefined {\n\t\tconst messages = this.messages[this.fallbackLocale];\n\t\treturn this.getMessageFromObject(key, messages);\n\t}\n\n\t/**\n\t * Add or update custom messages for a locale\n\t * This allows clients to provide their own translations or override defaults\n\t */\n\taddCustomMessages(locale: string, messages: LocaleMessages): void {\n\t\tthis.customMessages[locale] = this.deepMerge(\n\t\t\tthis.customMessages[locale] || {},\n\t\t\tmessages\n\t\t);\n\t}\n\n\t/**\n\t * Deep merge two objects (for merging translation objects)\n\t */\n\tprivate deepMerge(target: any, source: any): any {\n\t\tconst result = { ...target };\n\t\tfor (const key in source) {\n\t\t\tif (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {\n\t\t\t\tresult[key] = this.deepMerge(result[key] || {}, source[key]);\n\t\t\t} else {\n\t\t\t\tresult[key] = source[key];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Factory function to create a default i18n provider instance\n * @param locale - Initial locale code (default: 'en-US')\n * @param customMessages - Optional custom translations to add or override framework defaults\n * @returns DefaultI18nProvider instance\n */\nexport function createDefaultI18nProvider(\n\tlocale: LocaleCode = 'en-US',\n\tcustomMessages?: Record<string, LocaleMessages>\n): I18nProvider {\n\treturn new DefaultI18nProvider(locale, customMessages);\n}\n\nexport type { LocaleCode, MessageKey, InterpolationValues, PluralOptions };\n"]}
1
+ {"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../src/core/I18n.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,MAAM,aAAa,GAA4E;IAC9F,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACjD,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC;CAC5C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,aAAa,GAClB,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,KAAK,aAAa,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC7B,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,kBAAkB;IACzB,IAAI,EAAE,UAAU;IAChB,I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AC,EAAE,CAAC;gBACnF,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9D,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;;AAGF;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,SAAqB,OAAO,EAC5B,cAA+C;IAE/C,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC","sourcesContent":["/**\n * Default I18n provider implementation\n *\n * This is the framework's default implementation of the I18nProvider interface.\n * It uses standard dynamic imports for lazy locale loading and provides simple\n * interpolation and pluralization support.\n */\n\nimport type { I18nProvider, InterpolationValues, PluralOptions } from './I18nProvider.js';\nimport type { LocaleCode, FrameworkLocaleCode, MessageKey, LocaleMessages } from './types.js';\nimport enUS from '../locales/en-US.js';\n\n/**\n * Lazy loaders for the framework locales.\n *\n * An explicit static map rather than a bundler macro: `tsc` emits these\n * `import()` calls verbatim, so the published package evaluates anywhere ESM\n * does — webpack, esbuild, Rollup, Node, or a browser loading the files\n * directly. Every bundler still sees the specifiers statically, so each locale\n * remains its own chunk and a host that only renders English never fetches the\n * others. Adding a locale means adding a line here alongside the file.\n *\n * en-US is a plain static import because it is the fallback for every missing\n * key in every other locale, so it must be resolvable synchronously in the\n * constructor.\n */\nconst localeLoaders: Record<FrameworkLocaleCode, () => Promise<{ default: LocaleMessages }>> = {\n\t'en-US': () => Promise.resolve({ default: enUS }),\n\t'ar-SA': () => import('../locales/ar-SA.js'),\n\t'es-ES': () => import('../locales/es-ES.js'),\n\t'fr-FR': () => import('../locales/fr-FR.js'),\n\t'nl-NL': () => import('../locales/nl-NL.js'),\n\t'ro-RO': () => import('../locales/ro-RO.js'),\n\t'th-TH': () => import('../locales/th-TH.js'),\n\t'zh-CN': () => import('../locales/zh-CN.js'),\n};\n\n/**\n * Whether to log missing-translation warnings.\n *\n * `process` does not exist in a plain browser, so the read is guarded rather\n * than bare: an unguarded `process.env.NODE_ENV` throws a ReferenceError on the\n * missing-key path for any consumer that is not running the code through a\n * bundler that substitutes it.\n */\nconst isDevelopment: boolean =\n\ttypeof process !== 'undefined' && process.env?.NODE_ENV === 'development';\n\n/**\n * Right-to-left primary language subtags.\n *\n * Only consulted when `Intl.Locale.prototype.textInfo` is unavailable — it is the\n * authoritative source but shipped late in Safari, and an assessment rendered\n * left-to-right for an Arabic reader is not a graceful degradation.\n */\nconst RTL_LANGUAGES = new Set([\n\t'ar', // Arabic\n\t'ckb', // Central Kurdish\n\t'dv', // Dhivehi\n\t'fa', // Persian\n\t'he',\n\t'iw', // Hebrew (current and legacy subtags)\n\t'ks', // Kashmiri\n\t'ku', // Kurdish\n\t'nqo', // N'Ko\n\t'ps', // Pashto\n\t'sd', // Sindhi\n\t'syr', // Syriac\n\t'ug', // Uyghur\n\t'ur', // Urdu\n\t'yi', // Yiddish\n]);\n\nexport class DefaultI18nProvider implements I18nProvider {\n\t/** Shared across instances: constructing Intl.PluralRules is not cheap */\n\tprivate static pluralRules: Map<LocaleCode, Intl.PluralRules> = new Map();\n\n\tprivate currentLocale: LocaleCode;\n\tprivate messages: Record<LocaleCode, LocaleMessages>;\n\tprivate customMessages: Record<string, LocaleMessages>; // Client-provided translations\n\tprivate fallbackLocale: LocaleCode = 'en-US';\n\tprivate loadedLocales: Set<LocaleCode> = new Set();\n\n\tconstructor(locale: LocaleCode = 'en-US', customMessages?: Record<string, LocaleMessages>) {\n\t\t// Read persisted locale from localStorage if available\n\t\t// This allows locale changes to persist across page reloads\n\t\tconst storedLocale = typeof localStorage !== 'undefined'\n\t\t\t? localStorage.getItem('pie-qti-locale')\n\t\t\t: null;\n\n\t\tthis.currentLocale = (storedLocale as LocaleCode) || locale;\n\t\tthis.messages = {} as Record<LocaleCode, LocaleMessages>;\n\t\tthis.customMessages = customMessages || {};\n\n\t\t// en-US is the fallback for every other locale, so it is always present\n\t\tthis.messages['en-US'] = enUS;\n\t\tthis.loadedLocales.add('en-US');\n\t}\n\n\t/**\n\t * Load locale messages dynamically (framework locales only)\n\t * For custom locales, use the customMessages parameter in the constructor or addCustomMessages()\n\t */\n\tasync loadLocale(locale: FrameworkLocaleCode): Promise<void> {\n\t\tif (this.loadedLocales.has(locale)) {\n\t\t\treturn; // Already loaded\n\t\t}\n\n\t\ttry {\n\t\t\tconst loader = localeLoaders[locale];\n\n\t\t\tif (!loader) {\n\t\t\t\tthrow new Error(`Locale '${locale}' is not a framework locale`);\n\t\t\t}\n\n\t\t\tconst module = await loader();\n\t\t\tthis.messages[locale] = module.default;\n\t\t\tthis.loadedLocales.add(locale);\n\t\t} catch (error) {\n\t\t\tconsole.error(`[i18n] Failed to load locale '${locale}':`, error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Set current locale\n\t * For framework locales, loadLocale() should be called first.\n\t * For custom locales, translations should be provided via customMessages.\n\t */\n\tsetLocale(locale: string): void {\n\t\t// Allow setting custom locales even if not in loadedLocales\n\t\t// They will use customMessages + fallback to en-US\n\t\tif (!this.loadedLocales.has(locale as LocaleCode) && !this.customMessages[locale]) {\n\t\t\tconsole.warn(`[i18n] Locale '${locale}' not loaded and no custom messages provided. Using fallback locale.`);\n\t\t}\n\t\tthis.currentLocale = locale as LocaleCode;\n\t}\n\n\t/**\n\t * Get current locale\n\t */\n\tgetLocale(): string {\n\t\treturn this.currentLocale;\n\t}\n\n\t/**\n\t * Translate message key with optional default and/or interpolation\n\t * @example t('upload.label') => \"Upload a file\"\n\t * @example t('upload.label', 'Upload') => translated or \"Upload\" if missing\n\t * @example t('upload.selected', { name: 'file.pdf' }) => \"Selected: file.pdf\"\n\t */\n\tt(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string {\n\t\tconst message = this.getMessage(key);\n\t\tconst interpolationValues = typeof defaultOrValues === 'object' && defaultOrValues !== null\n\t\t\t? defaultOrValues\n\t\t\t: values;\n\t\tconst defaultStr = typeof defaultOrValues === 'string' ? defaultOrValues : undefined;\n\n\t\tif (!message) {\n\t\t\tif (isDevelopment) {\n\t\t\t\tconsole.warn(`[i18n] Missing translation: ${key} (locale: ${this.currentLocale})`);\n\t\t\t}\n\t\t\treturn defaultStr ?? key;\n\t\t}\n\n\t\tif (!interpolationValues) return message;\n\n\t\t// Simple interpolation: replace {key} with values[key]\n\t\treturn message.replace(/\\{(\\w+)\\}/g, (match, k) => {\n\t\t\treturn String(interpolationValues[k] ?? match);\n\t\t});\n\t}\n\n\t/**\n\t * Pluralization support\n\t *\n\t * The plural category comes from `Intl.PluralRules` for the active locale, so\n\t * locales with more than two forms resolve correctly: Arabic selects between\n\t * zero/one/two/few/many/other, Romanian between one/few/other. A locale whose\n\t * catalog does not carry the selected category falls back to `.other`.\n\t *\n\t * @example plural('plurals.files', { count: 1 }) => \"1 file selected\"\n\t * @example plural('plurals.files', { count: 5 }) => \"5 files selected\"\n\t */\n\tplural(key: string, options: PluralOptions): string {\n\t\tconst { count } = options;\n\t\tconst category = this.selectPluralCategory(count);\n\t\tconst categoryKey = `${key}.${category}`;\n\t\tconst pluralKey = this.getMessage(categoryKey) !== undefined ? categoryKey : `${key}.other`;\n\t\treturn this.t(pluralKey, options);\n\t}\n\n\t/**\n\t * Select the CLDR plural category for a count in the active locale\n\t *\n\t * Falls back to the English one/other split if the locale tag is not one\n\t * `Intl.PluralRules` accepts — a host may set an arbitrary custom locale code.\n\t */\n\tprivate selectPluralCategory(count: number): Intl.LDMLPluralRule {\n\t\tlet rules = DefaultI18nProvider.pluralRules.get(this.currentLocale);\n\n\t\tif (!rules) {\n\t\t\ttry {\n\t\t\t\trules = new Intl.PluralRules(this.currentLocale);\n\t\t\t} catch {\n\t\t\t\treturn count === 1 ? 'one' : 'other';\n\t\t\t}\n\t\t\tDefaultI18nProvider.pluralRules.set(this.currentLocale, rules);\n\t\t}\n\n\t\treturn rules.select(count);\n\t}\n\n\t/**\n\t * Writing direction of the current locale\n\t *\n\t * @example getDirection() => 'rtl' for ar-SA, 'ltr' for en-US\n\t */\n\tgetDirection(): 'ltr' | 'rtl' {\n\t\ttry {\n\t\t\t// textInfo is the authoritative CLDR answer where the engine has it\n\t\t\tconst textInfo = (new Intl.Locale(this.currentLocale) as { textInfo?: { direction?: string } })\n\t\t\t\t.textInfo;\n\t\t\tif (textInfo?.direction === 'rtl' || textInfo?.direction === 'ltr') {\n\t\t\t\treturn textInfo.direction;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not a tag Intl.Locale accepts; the subtag check below still works\n\t\t}\n\n\t\tconst language = this.currentLocale.toLowerCase().split(/[-_]/)[0] ?? '';\n\t\treturn RTL_LANGUAGES.has(language) ? 'rtl' : 'ltr';\n\t}\n\n\t/**\n\t * A view of this provider fixed to another locale\n\t *\n\t * Catalogs, loaded-locale bookkeeping and custom messages are shared by\n\t * reference, so `loadLocale()` through either side is visible to both and no\n\t * catalog is parsed twice. This is what lets two players on one page render\n\t * different locales from one provider: the locale is per-view, the catalogs\n\t * are per-provider.\n\t */\n\twithLocale(locale: LocaleCode): I18nProvider {\n\t\tif (locale === this.currentLocale) return this;\n\n\t\tconst view = new DefaultI18nProvider(locale, this.customMessages);\n\t\t// The constructor prefers a persisted locale; an explicit view must not.\n\t\tview.currentLocale = locale;\n\t\tview.messages = this.messages;\n\t\tview.loadedLocales = this.loadedLocales;\n\t\treturn view;\n\t}\n\n\t/**\n\t * Format number according to locale\n\t */\n\tformatNumber(value: number, options?: Intl.NumberFormatOptions): string {\n\t\treturn new Intl.NumberFormat(this.currentLocale, options).format(value);\n\t}\n\n\t/**\n\t * Format date according to locale\n\t */\n\tformatDate(date: Date, options?: Intl.DateTimeFormatOptions): string {\n\t\treturn new Intl.DateTimeFormat(this.currentLocale, options).format(date);\n\t}\n\n\t/**\n\t * Get nested message by dot notation key\n\t * Priority: custom messages > current locale > fallback locale\n\t */\n\tprivate getMessage(key: string): string | undefined {\n\t\t// 1. Try custom messages first (client overrides)\n\t\tconst customMessage = this.getMessageFromObject(key, this.customMessages[this.currentLocale]);\n\t\tif (customMessage !== undefined) return customMessage;\n\n\t\t// 2. Try current locale from framework defaults\n\t\tconst messages = this.messages[this.currentLocale];\n\t\tif (messages) {\n\t\t\tconst message = this.getMessageFromObject(key, messages);\n\t\t\tif (message !== undefined) return message;\n\t\t}\n\n\t\t// 3. Try custom fallback locale\n\t\tconst customFallback = this.getMessageFromObject(key, this.customMessages[this.fallbackLocale]);\n\t\tif (customFallback !== undefined) return customFallback;\n\n\t\t// 4. Try framework fallback locale\n\t\treturn this.getMessageFromFallback(key);\n\t}\n\n\t/**\n\t * Get message from a specific messages object\n\t *\n\t * Resolves to a string or nothing. A key that lands on a namespace branch\n\t * (`t('common')`) or on a plural sub-object (`t('plurals.items')`) is a miss,\n\t * not a hit: returning the branch would put an object where the caller\n\t * expects a string, and interpolating one throws.\n\t */\n\tprivate getMessageFromObject(key: string, messages: any): string | undefined {\n\t\tif (!messages) return undefined;\n\n\t\tconst parts = key.split('.');\n\t\tlet current: any = messages;\n\n\t\tfor (const part of parts) {\n\t\t\tif (current === null || typeof current !== 'object') return undefined;\n\t\t\tcurrent = current[part];\n\t\t\tif (current === undefined) return undefined;\n\t\t}\n\n\t\treturn typeof current === 'string' ? current : undefined;\n\t}\n\n\t/**\n\t * Get message from fallback locale (framework defaults)\n\t */\n\tprivate getMessageFromFallback(key: string): string | undefined {\n\t\tconst messages = this.messages[this.fallbackLocale];\n\t\treturn this.getMessageFromObject(key, messages);\n\t}\n\n\t/**\n\t * Add or update custom messages for a locale\n\t * This allows clients to provide their own translations or override defaults\n\t */\n\taddCustomMessages(locale: string, messages: LocaleMessages): void {\n\t\tthis.customMessages[locale] = this.deepMerge(\n\t\t\tthis.customMessages[locale] || {},\n\t\t\tmessages\n\t\t);\n\t}\n\n\t/**\n\t * Deep merge two objects (for merging translation objects)\n\t */\n\tprivate deepMerge(target: any, source: any): any {\n\t\tconst result = { ...target };\n\t\tfor (const key in source) {\n\t\t\tif (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {\n\t\t\t\tresult[key] = this.deepMerge(result[key] || {}, source[key]);\n\t\t\t} else {\n\t\t\t\tresult[key] = source[key];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Factory function to create a default i18n provider instance\n * @param locale - Initial locale code (default: 'en-US')\n * @param customMessages - Optional custom translations to add or override framework defaults\n * @returns DefaultI18nProvider instance\n */\nexport function createDefaultI18nProvider(\n\tlocale: LocaleCode = 'en-US',\n\tcustomMessages?: Record<string, LocaleMessages>\n): I18nProvider {\n\treturn new DefaultI18nProvider(locale, customMessages);\n}\n\nexport type { LocaleCode, MessageKey, InterpolationValues, PluralOptions };\n"]}
@@ -33,6 +33,26 @@ export interface I18nProvider {
33
33
  count: number;
34
34
  [key: string]: any;
35
35
  }): string;
36
+ /**
37
+ * Optional: Writing direction of the current locale
38
+ *
39
+ * Components reflect this onto a `dir` attribute. `direction` is an inherited
40
+ * CSS property, so a `dir` on the host element crosses into shadow content
41
+ * without any per-component wiring.
42
+ *
43
+ * @returns 'rtl' for right-to-left locales, otherwise 'ltr'
44
+ */
45
+ getDirection?(): 'ltr' | 'rtl';
46
+ /**
47
+ * Optional: A view of this provider fixed to another locale
48
+ *
49
+ * Lets two players on one page render different locales without either
50
+ * mutating the other's active locale. A provider that cannot produce such a
51
+ * view simply omits this, and callers fall back to the provider itself.
52
+ *
53
+ * @param locale - BCP 47 locale code for the view
54
+ */
55
+ withLocale?(locale: string): I18nProvider;
36
56
  /**
37
57
  * Optional: Format number according to locale
38
58
  * @param value - Number to format
@@ -1 +1 @@
1
- {"version":3,"file":"I18nProvider.js","sourceRoot":"","sources":["../../src/core/I18nProvider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * Framework-agnostic i18n provider interface\n *\n * This interface defines the contract for internationalization services.\n * Users can provide their own implementations (ICU MessageFormat, i18next, etc.)\n * or use the default implementation provided by the framework.\n */\n\nexport interface I18nProvider {\n\t/**\n\t * Get the current locale code (e.g., 'en-US', 'fr-FR')\n\t */\n\tgetLocale(): string;\n\n\t/**\n\t * Set the current locale and optionally load locale messages\n\t * @param locale - BCP 47 locale code\n\t */\n\tsetLocale(locale: string): Promise<void> | void;\n\n\t/**\n\t * Translate a message key with optional default and/or interpolation\n\t * @param key - Message key (e.g., 'common.submit', 'assessment.question')\n\t * @param defaultOrValues - Optional default string or interpolation values\n\t * @param values - Optional interpolation values (if second arg is default string)\n\t * @returns Translated message, default, or key if not found\n\t */\n\tt(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string;\n\n\t/**\n\t * Optional: Pluralization support\n\t * @param key - Base message key\n\t * @param options - Options including count and interpolation values\n\t * @returns Pluralized and translated message\n\t */\n\tplural?(key: string, options: { count: number; [key: string]: any }): string;\n\n\t/**\n\t * Optional: Format number according to locale\n\t * @param value - Number to format\n\t * @param options - Intl.NumberFormat options\n\t * @returns Formatted number string\n\t */\n\tformatNumber?(value: number, options?: Intl.NumberFormatOptions): string;\n\n\t/**\n\t * Optional: Format date according to locale\n\t * @param date - Date to format\n\t * @param options - Intl.DateTimeFormat options\n\t * @returns Formatted date string\n\t */\n\tformatDate?(date: Date, options?: Intl.DateTimeFormatOptions): string;\n}\n\n/**\n * Interpolation values for dynamic message content\n */\nexport interface InterpolationValues {\n\t[key: string]: string | number;\n}\n\n/**\n * Pluralization options\n */\nexport interface PluralOptions {\n\tcount: number;\n\t[key: string]: string | number;\n}\n"]}
1
+ {"version":3,"file":"I18nProvider.js","sourceRoot":"","sources":["../../src/core/I18nProvider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG","sourcesContent":["/**\n * Framework-agnostic i18n provider interface\n *\n * This interface defines the contract for internationalization services.\n * Users can provide their own implementations (ICU MessageFormat, i18next, etc.)\n * or use the default implementation provided by the framework.\n */\n\nexport interface I18nProvider {\n\t/**\n\t * Get the current locale code (e.g., 'en-US', 'fr-FR')\n\t */\n\tgetLocale(): string;\n\n\t/**\n\t * Set the current locale and optionally load locale messages\n\t * @param locale - BCP 47 locale code\n\t */\n\tsetLocale(locale: string): Promise<void> | void;\n\n\t/**\n\t * Translate a message key with optional default and/or interpolation\n\t * @param key - Message key (e.g., 'common.submit', 'assessment.question')\n\t * @param defaultOrValues - Optional default string or interpolation values\n\t * @param values - Optional interpolation values (if second arg is default string)\n\t * @returns Translated message, default, or key if not found\n\t */\n\tt(key: string, defaultOrValues?: Record<string, any> | string, values?: Record<string, any>): string;\n\n\t/**\n\t * Optional: Pluralization support\n\t * @param key - Base message key\n\t * @param options - Options including count and interpolation values\n\t * @returns Pluralized and translated message\n\t */\n\tplural?(key: string, options: { count: number; [key: string]: any }): string;\n\n\t/**\n\t * Optional: Writing direction of the current locale\n\t *\n\t * Components reflect this onto a `dir` attribute. `direction` is an inherited\n\t * CSS property, so a `dir` on the host element crosses into shadow content\n\t * without any per-component wiring.\n\t *\n\t * @returns 'rtl' for right-to-left locales, otherwise 'ltr'\n\t */\n\tgetDirection?(): 'ltr' | 'rtl';\n\n\t/**\n\t * Optional: A view of this provider fixed to another locale\n\t *\n\t * Lets two players on one page render different locales without either\n\t * mutating the other's active locale. A provider that cannot produce such a\n\t * view simply omits this, and callers fall back to the provider itself.\n\t *\n\t * @param locale - BCP 47 locale code for the view\n\t */\n\twithLocale?(locale: string): I18nProvider;\n\n\t/**\n\t * Optional: Format number according to locale\n\t * @param value - Number to format\n\t * @param options - Intl.NumberFormat options\n\t * @returns Formatted number string\n\t */\n\tformatNumber?(value: number, options?: Intl.NumberFormatOptions): string;\n\n\t/**\n\t * Optional: Format date according to locale\n\t * @param date - Date to format\n\t * @param options - Intl.DateTimeFormat options\n\t * @returns Formatted date string\n\t */\n\tformatDate?(date: Date, options?: Intl.DateTimeFormatOptions): string;\n}\n\n/**\n * Interpolation values for dynamic message content\n */\nexport interface InterpolationValues {\n\t[key: string]: string | number;\n}\n\n/**\n * Pluralization options\n */\nexport interface PluralOptions {\n\tcount: number;\n\t[key: string]: string | number;\n}\n"]}
@@ -608,7 +608,14 @@ declare const _default: {
608
608
  readonly samples: {
609
609
  readonly title: "حزم QTI النموذجية";
610
610
  readonly description: "جرب المعالج مع حزم نموذجية محملة مسبقًا توضح أنواع التفاعل المختلفة في QTI.";
611
- readonly itemCount: "{count, plural, zero {# عنصر} one {عنصر واحد} two {عنصران} few {# عناصر} many {# عنصرًا} other {# عنصر}}";
611
+ readonly itemCount: {
612
+ readonly zero: "{count} عنصر";
613
+ readonly one: "عنصر واحد";
614
+ readonly two: "عنصران";
615
+ readonly few: "{count} عناصر";
616
+ readonly many: "{count} عنصرًا";
617
+ readonly other: "{count} عنصر";
618
+ };
612
619
  readonly hasManifest: "البيان";
613
620
  readonly load: "تحميل النموذج";
614
621
  readonly loadSample: "تحميل النموذج";
@@ -655,10 +662,24 @@ declare const _default: {
655
662
  readonly sampleItems: "عناصر نموذجية حسب نوع التفاعل";
656
663
  readonly issues: "المشكلات";
657
664
  readonly browseAssessments: "تصفح ومعاينة اختبارات التقييم";
658
- readonly browseAssessmentsDescription: "تصفح ومعاينة {count, plural, zero {# اختبار تقييم QTI} one {اختبار تقييم QTI واحد} two {اختباري تقييم QTI} few {# اختبارات تقييم QTI} many {# اختبار تقييم QTI} other {# اختبار تقييم QTI}} الموجودة في هذه الجلسة";
665
+ readonly browseAssessmentsDescription: {
666
+ readonly zero: "تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة";
667
+ readonly one: "تصفح ومعاينة اختبار تقييم QTI واحد الموجودة في هذه الجلسة";
668
+ readonly two: "تصفح ومعاينة اختباري تقييم QTI الموجودة في هذه الجلسة";
669
+ readonly few: "تصفح ومعاينة {count} اختبارات تقييم QTI الموجودة في هذه الجلسة";
670
+ readonly many: "تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة";
671
+ readonly other: "تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة";
672
+ };
659
673
  readonly individualItems: "العناصر الفردية";
660
674
  readonly browseItems: "تصفح ومعاينة العناصر";
661
- readonly browseItemsDescription: "تصفح ومعاينة {count, plural, zero {# عنصر QTI} one {عنصر QTI واحد} two {عنصري QTI} few {# عناصر QTI} many {# عنصر QTI} other {# عنصر QTI}} الموجودة في هذه الجلسة";
675
+ readonly browseItemsDescription: {
676
+ readonly zero: "تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة";
677
+ readonly one: "تصفح ومعاينة عنصر QTI واحد الموجودة في هذه الجلسة";
678
+ readonly two: "تصفح ومعاينة عنصري QTI الموجودة في هذه الجلسة";
679
+ readonly few: "تصفح ومعاينة {count} عناصر QTI الموجودة في هذه الجلسة";
680
+ readonly many: "تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة";
681
+ readonly other: "تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة";
682
+ };
662
683
  };
663
684
  readonly analysis: {
664
685
  readonly title: "نتائج التحليل";
@@ -694,14 +715,37 @@ declare const _default: {
694
715
  readonly pageTitle: "نتائج التحويل - الجلسة {sessionId}";
695
716
  readonly breadcrumb: "محول";
696
717
  readonly title: "نتائج التحويل";
697
- readonly summary: "{itemCount} عنصر{itemCount, plural, zero {} one {} two {} few {} many {} other {}}{assessmentCount, plural, =0 {} other { + {assessmentCount} تقييم{assessmentCount, plural, zero {} one {} two {} few {} many {} other {}}}} تم تحويله في {duration}";
718
+ readonly summary: "{items} تم تحويله في {duration}";
719
+ readonly summaryWithAssessments: "{items} + {assessments} تم تحويله في {duration}";
720
+ readonly summaryItems: {
721
+ readonly one: "{count} عنصر";
722
+ readonly other: "{count} عنصر";
723
+ };
724
+ readonly summaryAssessments: {
725
+ readonly one: "{count} تقييم";
726
+ readonly other: "{count} تقييم";
727
+ };
698
728
  readonly backToSession: "العودة إلى الجلسة";
699
729
  readonly content: "المحتوى المحول";
700
730
  readonly items: "العناصر";
701
731
  readonly assessments: "التقييمات";
702
732
  readonly errors: "الأخطاء";
703
- readonly warnings: "{count, plural, zero {# تحذير} one {تحذير واحد} two {تحذيران} few {# تحذيرات} many {# تحذيرًا} other {# تحذير}}";
704
- readonly transformationErrors: "{count, plural, zero {# خطأ تحويل} one {خطأ تحويل واحد} two {خطأا تحويل} few {# أخطاء تحويل} many {# خطأ تحويل} other {# خطأ تحويل}}";
733
+ readonly warnings: {
734
+ readonly zero: "{count} تحذير";
735
+ readonly one: "تحذير واحد";
736
+ readonly two: "تحذيران";
737
+ readonly few: "{count} تحذيرات";
738
+ readonly many: "{count} تحذيرًا";
739
+ readonly other: "{count} تحذير";
740
+ };
741
+ readonly transformationErrors: {
742
+ readonly zero: "{count} خطأ تحويل";
743
+ readonly one: "خطأ تحويل واحد";
744
+ readonly two: "خطأا تحويل";
745
+ readonly few: "{count} أخطاء تحويل";
746
+ readonly many: "{count} خطأ تحويل";
747
+ readonly other: "{count} خطأ تحويل";
748
+ };
705
749
  readonly noItems: "لم يتم تحويل أي عناصر";
706
750
  readonly selectPrompt: "اختر عنصرًا أو تقييمًا للمعاينة";
707
751
  };
@@ -630,7 +630,14 @@ export default {
630
630
  samples: {
631
631
  title: 'حزم QTI النموذجية',
632
632
  description: 'جرب المعالج مع حزم نموذجية محملة مسبقًا توضح أنواع التفاعل المختلفة في QTI.',
633
- itemCount: '{count, plural, zero {# عنصر} one {عنصر واحد} two {عنصران} few {# عناصر} many {# عنصرًا} other {# عنصر}}',
633
+ itemCount: {
634
+ zero: '{count} عنصر',
635
+ one: 'عنصر واحد',
636
+ two: 'عنصران',
637
+ few: '{count} عناصر',
638
+ many: '{count} عنصرًا',
639
+ other: '{count} عنصر',
640
+ },
634
641
  hasManifest: 'البيان',
635
642
  load: 'تحميل النموذج',
636
643
  loadSample: 'تحميل النموذج',
@@ -679,10 +686,24 @@ export default {
679
686
  sampleItems: 'عناصر نموذجية حسب نوع التفاعل',
680
687
  issues: 'المشكلات',
681
688
  browseAssessments: 'تصفح ومعاينة اختبارات التقييم',
682
- browseAssessmentsDescription: 'تصفح ومعاينة {count, plural, zero {# اختبار تقييم QTI} one {اختبار تقييم QTI واحد} two {اختباري تقييم QTI} few {# اختبارات تقييم QTI} many {# اختبار تقييم QTI} other {# اختبار تقييم QTI}} الموجودة في هذه الجلسة',
689
+ browseAssessmentsDescription: {
690
+ zero: 'تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة',
691
+ one: 'تصفح ومعاينة اختبار تقييم QTI واحد الموجودة في هذه الجلسة',
692
+ two: 'تصفح ومعاينة اختباري تقييم QTI الموجودة في هذه الجلسة',
693
+ few: 'تصفح ومعاينة {count} اختبارات تقييم QTI الموجودة في هذه الجلسة',
694
+ many: 'تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة',
695
+ other: 'تصفح ومعاينة {count} اختبار تقييم QTI الموجودة في هذه الجلسة',
696
+ },
683
697
  individualItems: 'العناصر الفردية',
684
698
  browseItems: 'تصفح ومعاينة العناصر',
685
- browseItemsDescription: 'تصفح ومعاينة {count, plural, zero {# عنصر QTI} one {عنصر QTI واحد} two {عنصري QTI} few {# عناصر QTI} many {# عنصر QTI} other {# عنصر QTI}} الموجودة في هذه الجلسة',
699
+ browseItemsDescription: {
700
+ zero: 'تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة',
701
+ one: 'تصفح ومعاينة عنصر QTI واحد الموجودة في هذه الجلسة',
702
+ two: 'تصفح ومعاينة عنصري QTI الموجودة في هذه الجلسة',
703
+ few: 'تصفح ومعاينة {count} عناصر QTI الموجودة في هذه الجلسة',
704
+ many: 'تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة',
705
+ other: 'تصفح ومعاينة {count} عنصر QTI الموجودة في هذه الجلسة',
706
+ },
686
707
  },
687
708
  // Analysis results
688
709
  analysis: {
@@ -722,14 +743,39 @@ export default {
722
743
  pageTitle: 'نتائج التحويل - الجلسة {sessionId}',
723
744
  breadcrumb: 'محول',
724
745
  title: 'نتائج التحويل',
725
- summary: '{itemCount} عنصر{itemCount, plural, zero {} one {} two {} few {} many {} other {}}{assessmentCount, plural, =0 {} other { + {assessmentCount} تقييم{assessmentCount, plural, zero {} one {} two {} few {} many {} other {}}}} تم تحويله في {duration}',
746
+ // The ICU original inflected neither noun; one/other reproduce it, and
747
+ // the remaining Arabic categories resolve through the .other fallback.
748
+ summary: '{items} تم تحويله في {duration}',
749
+ summaryWithAssessments: '{items} + {assessments} تم تحويله في {duration}',
750
+ summaryItems: {
751
+ one: '{count} عنصر',
752
+ other: '{count} عنصر',
753
+ },
754
+ summaryAssessments: {
755
+ one: '{count} تقييم',
756
+ other: '{count} تقييم',
757
+ },
726
758
  backToSession: 'العودة إلى الجلسة',
727
759
  content: 'المحتوى المحول',
728
760
  items: 'العناصر',
729
761
  assessments: 'التقييمات',
730
762
  errors: 'الأخطاء',
731
- warnings: '{count, plural, zero {# تحذير} one {تحذير واحد} two {تحذيران} few {# تحذيرات} many {# تحذيرًا} other {# تحذير}}',
732
- transformationErrors: '{count, plural, zero {# خطأ تحويل} one {خطأ تحويل واحد} two {خطأا تحويل} few {# أخطاء تحويل} many {# خطأ تحويل} other {# خطأ تحويل}}',
763
+ warnings: {
764
+ zero: '{count} تحذير',
765
+ one: 'تحذير واحد',
766
+ two: 'تحذيران',
767
+ few: '{count} تحذيرات',
768
+ many: '{count} تحذيرًا',
769
+ other: '{count} تحذير',
770
+ },
771
+ transformationErrors: {
772
+ zero: '{count} خطأ تحويل',
773
+ one: 'خطأ تحويل واحد',
774
+ two: 'خطأا تحويل',
775
+ few: '{count} أخطاء تحويل',
776
+ many: '{count} خطأ تحويل',
777
+ other: '{count} خطأ تحويل',
778
+ },
733
779
  noItems: 'لم يتم تحويل أي عناصر',
734
780
  selectPrompt: 'اختر عنصرًا أو تقييمًا للمعاينة',
735
781
  },