inline-i18n-multi 0.12.0 → 0.14.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/README.md CHANGED
@@ -83,6 +83,8 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
83
83
  - **Translation Key Listing** - `getTranslationKeys(locale?, namespace?)` returns all loaded translation keys
84
84
  - **Missing Translation Tracker** - Runtime collection of missing translation keys (`trackMissingKeys(true/false)`, `getMissingKeys()`, `clearMissingKeys()`)
85
85
  - **Locale Change Event** — Subscribe to locale changes with `onLocaleChange()` (v0.12.0)
86
+ - **Formatting Utilities** — Locale-aware `formatNumber`, `formatDate`, `formatList` powered by `Intl` APIs (v0.13.0)
87
+ - **Raw Template Access** -- `tRaw(key, locale?)` returns raw template string without interpolation (v0.14.0)
86
88
 
87
89
  ---
88
90
 
@@ -1017,6 +1019,10 @@ Available helpers:
1017
1019
  | `clearMissingKeys()` | Clear the tracked missing keys list |
1018
1020
  | `onLocaleChange(callback)` | Subscribe to locale changes, returns unsubscribe function |
1019
1021
  | `clearLocaleListeners()` | Remove all locale change listeners |
1022
+ | `formatNumber(value, options?, locale?)` | Format numbers (currency, percent, etc.) |
1023
+ | `formatDate(value, options?, locale?)` | Format dates and times |
1024
+ | `formatList(values, options?, locale?)` | Format lists (conjunction, disjunction) |
1025
+ | `tRaw(key, locale?)` | Get raw template string without interpolation |
1020
1026
 
1021
1027
  ### Custom Formatters
1022
1028
 
package/dist/index.d.mts CHANGED
@@ -219,6 +219,18 @@ declare function isLoaded(locale: Locale, namespace?: string): boolean;
219
219
  * t('items.count', { count: 5 }) // "5 items"
220
220
  */
221
221
  declare function t(key: string, vars?: TranslationVars, locale?: Locale): string;
222
+ /**
223
+ * Get the raw template string for a translation key without interpolation (v0.14.0)
224
+ * Returns undefined if the key is not found.
225
+ *
226
+ * @param key - Dot-separated translation key, optionally prefixed with namespace
227
+ * @param locale - Override locale (optional)
228
+ * @example
229
+ * tRaw('welcome') // → "Welcome, {name}!"
230
+ * tRaw('items.count', 'ko') // → "{count}개 항목"
231
+ * tRaw('common:greeting') // → "Hello"
232
+ */
233
+ declare function tRaw(key: string, locale?: Locale): string | undefined;
222
234
  /**
223
235
  * Check if a translation key exists
224
236
  * @param key - Translation key (may include namespace prefix)
@@ -367,6 +379,33 @@ declare function detectLocale(options: DetectLocaleOptions): Locale;
367
379
  */
368
380
  declare function createScope(namespace: string): (key: string, vars?: TranslationVars, locale?: Locale) => string;
369
381
 
382
+ /**
383
+ * Format a number for the given locale using Intl.NumberFormat.
384
+ *
385
+ * @example
386
+ * formatNumber(1234.5) // "1,234.5" (en)
387
+ * formatNumber(1234.5, { style: 'currency', currency: 'USD' }) // "$1,234.50"
388
+ * formatNumber(0.85, { style: 'percent' }, 'ko') // "85%"
389
+ */
390
+ declare function formatNumber(value: number, options?: Intl.NumberFormatOptions, locale?: Locale): string;
391
+ /**
392
+ * Format a date for the given locale using Intl.DateTimeFormat.
393
+ *
394
+ * @example
395
+ * formatDate(new Date()) // "3/30/2026" (en)
396
+ * formatDate(new Date(), { dateStyle: 'full' }, 'ja') // "2026年3月30日月曜日"
397
+ */
398
+ declare function formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions, locale?: Locale): string;
399
+ /**
400
+ * Format a list for the given locale using Intl.ListFormat.
401
+ *
402
+ * @example
403
+ * formatList(['A', 'B', 'C']) // "A, B, and C" (en)
404
+ * formatList(['A', 'B', 'C'], { type: 'disjunction' }) // "A, B, or C"
405
+ * formatList(['りんご', 'みかん'], {}, 'ja') // "りんごとみかん"
406
+ */
407
+ declare function formatList(values: string[], options?: Intl.ListFormatOptions, locale?: Locale): string;
408
+
370
409
  /**
371
410
  * Rich Text segment types
372
411
  */
@@ -395,4 +434,4 @@ interface RichTextSegment {
395
434
  */
396
435
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
397
436
 
398
- export { type Config, type CustomFormatter, type DebugModeOptions, type DetectLocaleOptions, type DetectSource, type Dictionaries, type Dictionary, type Locale, type PluralRules, type RichTextSegment, type TranslationVars, type TranslationWarning, type Translations, type WarningHandler, __i18n_lookup, clearDictionaries, clearFormatters, clearICUCache, clearLocaleListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, getConfig, getDictionary, getLoadedLocales, getLoadedNamespaces, getLocale, getLocaleDisplayName, getMissingKeys, getTranslationKeys, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, onLocaleChange, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, trackMissingKeys, zh_es };
437
+ export { type Config, type CustomFormatter, type DebugModeOptions, type DetectLocaleOptions, type DetectSource, type Dictionaries, type Dictionary, type Locale, type PluralRules, type RichTextSegment, type TranslationVars, type TranslationWarning, type Translations, type WarningHandler, __i18n_lookup, clearDictionaries, clearFormatters, clearICUCache, clearLocaleListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, formatDate, formatList, formatNumber, getConfig, getDictionary, getLoadedLocales, getLoadedNamespaces, getLocale, getLocaleDisplayName, getMissingKeys, getTranslationKeys, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, onLocaleChange, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, tRaw, trackMissingKeys, zh_es };
package/dist/index.d.ts CHANGED
@@ -219,6 +219,18 @@ declare function isLoaded(locale: Locale, namespace?: string): boolean;
219
219
  * t('items.count', { count: 5 }) // "5 items"
220
220
  */
221
221
  declare function t(key: string, vars?: TranslationVars, locale?: Locale): string;
222
+ /**
223
+ * Get the raw template string for a translation key without interpolation (v0.14.0)
224
+ * Returns undefined if the key is not found.
225
+ *
226
+ * @param key - Dot-separated translation key, optionally prefixed with namespace
227
+ * @param locale - Override locale (optional)
228
+ * @example
229
+ * tRaw('welcome') // → "Welcome, {name}!"
230
+ * tRaw('items.count', 'ko') // → "{count}개 항목"
231
+ * tRaw('common:greeting') // → "Hello"
232
+ */
233
+ declare function tRaw(key: string, locale?: Locale): string | undefined;
222
234
  /**
223
235
  * Check if a translation key exists
224
236
  * @param key - Translation key (may include namespace prefix)
@@ -367,6 +379,33 @@ declare function detectLocale(options: DetectLocaleOptions): Locale;
367
379
  */
368
380
  declare function createScope(namespace: string): (key: string, vars?: TranslationVars, locale?: Locale) => string;
369
381
 
382
+ /**
383
+ * Format a number for the given locale using Intl.NumberFormat.
384
+ *
385
+ * @example
386
+ * formatNumber(1234.5) // "1,234.5" (en)
387
+ * formatNumber(1234.5, { style: 'currency', currency: 'USD' }) // "$1,234.50"
388
+ * formatNumber(0.85, { style: 'percent' }, 'ko') // "85%"
389
+ */
390
+ declare function formatNumber(value: number, options?: Intl.NumberFormatOptions, locale?: Locale): string;
391
+ /**
392
+ * Format a date for the given locale using Intl.DateTimeFormat.
393
+ *
394
+ * @example
395
+ * formatDate(new Date()) // "3/30/2026" (en)
396
+ * formatDate(new Date(), { dateStyle: 'full' }, 'ja') // "2026年3月30日月曜日"
397
+ */
398
+ declare function formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions, locale?: Locale): string;
399
+ /**
400
+ * Format a list for the given locale using Intl.ListFormat.
401
+ *
402
+ * @example
403
+ * formatList(['A', 'B', 'C']) // "A, B, and C" (en)
404
+ * formatList(['A', 'B', 'C'], { type: 'disjunction' }) // "A, B, or C"
405
+ * formatList(['りんご', 'みかん'], {}, 'ja') // "りんごとみかん"
406
+ */
407
+ declare function formatList(values: string[], options?: Intl.ListFormatOptions, locale?: Locale): string;
408
+
370
409
  /**
371
410
  * Rich Text segment types
372
411
  */
@@ -395,4 +434,4 @@ interface RichTextSegment {
395
434
  */
396
435
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
397
436
 
398
- export { type Config, type CustomFormatter, type DebugModeOptions, type DetectLocaleOptions, type DetectSource, type Dictionaries, type Dictionary, type Locale, type PluralRules, type RichTextSegment, type TranslationVars, type TranslationWarning, type Translations, type WarningHandler, __i18n_lookup, clearDictionaries, clearFormatters, clearICUCache, clearLocaleListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, getConfig, getDictionary, getLoadedLocales, getLoadedNamespaces, getLocale, getLocaleDisplayName, getMissingKeys, getTranslationKeys, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, onLocaleChange, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, trackMissingKeys, zh_es };
437
+ export { type Config, type CustomFormatter, type DebugModeOptions, type DetectLocaleOptions, type DetectSource, type Dictionaries, type Dictionary, type Locale, type PluralRules, type RichTextSegment, type TranslationVars, type TranslationWarning, type Translations, type WarningHandler, __i18n_lookup, clearDictionaries, clearFormatters, clearICUCache, clearLocaleListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, formatDate, formatList, formatNumber, getConfig, getDictionary, getLoadedLocales, getLoadedNamespaces, getLocale, getLocaleDisplayName, getMissingKeys, getTranslationKeys, hasTranslation, isLoaded, it, it_de, it_es, it_fr, it_ja, it_zh, ja_es, ja_zh, loadAsync, loadDictionaries, loadDictionary, onLocaleChange, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, tRaw, trackMissingKeys, zh_es };
package/dist/index.js CHANGED
@@ -976,6 +976,19 @@ function t(key, vars, locale) {
976
976
  };
977
977
  return applyDebugFormat(result, debugInfo);
978
978
  }
979
+ function tRaw(key, locale) {
980
+ const { namespace, key: actualKey } = parseKey(key);
981
+ const currentLocale2 = locale ?? getLocale();
982
+ const fallbackChain = buildFallbackChain(currentLocale2);
983
+ const nsDictionaries = namespacedDictionaries[namespace] || {};
984
+ for (const tryLocale of fallbackChain) {
985
+ const dict = nsDictionaries[tryLocale];
986
+ if (!dict) continue;
987
+ const found = getNestedValue(dict, actualKey);
988
+ if (found !== void 0) return found;
989
+ }
990
+ return void 0;
991
+ }
979
992
  function hasTranslation(key, locale, context) {
980
993
  const { namespace, key: actualKey } = parseKey(key);
981
994
  const currentLocale2 = locale ?? getLocale();
@@ -1157,6 +1170,17 @@ function createScope(namespace) {
1157
1170
  };
1158
1171
  }
1159
1172
 
1173
+ // src/format.ts
1174
+ function formatNumber(value, options, locale) {
1175
+ return new Intl.NumberFormat(locale ?? getLocale(), options).format(value);
1176
+ }
1177
+ function formatDate(value, options, locale) {
1178
+ return new Intl.DateTimeFormat(locale ?? getLocale(), options).format(value);
1179
+ }
1180
+ function formatList(values, options, locale) {
1181
+ return new Intl.ListFormat(locale ?? getLocale(), options).format(values);
1182
+ }
1183
+
1160
1184
  // src/richtext.ts
1161
1185
  function escapeRegExp(str) {
1162
1186
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1207,6 +1231,9 @@ exports.en_es = en_es;
1207
1231
  exports.en_fr = en_fr;
1208
1232
  exports.en_ja = en_ja;
1209
1233
  exports.en_zh = en_zh;
1234
+ exports.formatDate = formatDate;
1235
+ exports.formatList = formatList;
1236
+ exports.formatNumber = formatNumber;
1210
1237
  exports.getConfig = getConfig;
1211
1238
  exports.getDictionary = getDictionary;
1212
1239
  exports.getLoadedLocales = getLoadedLocales;
@@ -1235,6 +1262,7 @@ exports.resetConfig = resetConfig;
1235
1262
  exports.restoreLocale = restoreLocale;
1236
1263
  exports.setLocale = setLocale;
1237
1264
  exports.t = t;
1265
+ exports.tRaw = tRaw;
1238
1266
  exports.trackMissingKeys = trackMissingKeys;
1239
1267
  exports.zh_es = zh_es;
1240
1268
  //# sourceMappingURL=index.js.map