inline-i18n-multi 0.14.0 → 0.16.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
@@ -85,6 +85,8 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
85
85
  - **Locale Change Event** — Subscribe to locale changes with `onLocaleChange()` (v0.12.0)
86
86
  - **Formatting Utilities** — Locale-aware `formatNumber`, `formatDate`, `formatList` powered by `Intl` APIs (v0.13.0)
87
87
  - **Raw Template Access** -- `tRaw(key, locale?)` returns raw template string without interpolation (v0.14.0)
88
+ - **Batch Translation** -- `tBatch(keys, vars?, locale?)` translates multiple keys at once (v0.15.0)
89
+ - **Missing Locales Detection** -- `getMissingLocales(key)` returns locales where a key is absent (v0.16.0)
88
90
 
89
91
  ---
90
92
 
@@ -1023,6 +1025,8 @@ Available helpers:
1023
1025
  | `formatDate(value, options?, locale?)` | Format dates and times |
1024
1026
  | `formatList(values, options?, locale?)` | Format lists (conjunction, disjunction) |
1025
1027
  | `tRaw(key, locale?)` | Get raw template string without interpolation |
1028
+ | `tBatch(keys, vars?, locale?)` | Translate multiple keys at once |
1029
+ | `getMissingLocales(key)` | List locales missing a translation key |
1026
1030
 
1027
1031
  ### Custom Formatters
1028
1032
 
package/dist/index.d.mts CHANGED
@@ -231,6 +231,18 @@ declare function t(key: string, vars?: TranslationVars, locale?: Locale): string
231
231
  * tRaw('common:greeting') // → "Hello"
232
232
  */
233
233
  declare function tRaw(key: string, locale?: Locale): string | undefined;
234
+ /**
235
+ * Translate multiple keys at once (v0.15.0)
236
+ * @param keys - Array of translation keys
237
+ * @param vars - Optional variables applied to all translations
238
+ * @param locale - Override locale (optional)
239
+ * @returns Object mapping each key to its translated string
240
+ *
241
+ * @example
242
+ * tBatch(['greeting', 'farewell'])
243
+ * // → { greeting: 'Hello', farewell: 'Goodbye' }
244
+ */
245
+ declare function tBatch(keys: string[], vars?: TranslationVars, locale?: Locale): Record<string, string>;
234
246
  /**
235
247
  * Check if a translation key exists
236
248
  * @param key - Translation key (may include namespace prefix)
@@ -238,6 +250,20 @@ declare function tRaw(key: string, locale?: Locale): string | undefined;
238
250
  * @param context - Optional context for contextual translations (v0.9.0)
239
251
  */
240
252
  declare function hasTranslation(key: string, locale?: Locale, context?: string): boolean;
253
+ /**
254
+ * Get all locales where a translation key is missing (v0.16.0)
255
+ * Inverse of `hasTranslation` — checks every loaded locale in the key's namespace
256
+ * and returns those that do not contain the key.
257
+ *
258
+ * @param key - Translation key (may include namespace prefix)
259
+ * @returns Array of locale codes missing the key
260
+ *
261
+ * @example
262
+ * loadDictionaries({ en: { hello: 'Hi' }, ko: { hello: '안녕' }, ja: {} })
263
+ * getMissingLocales('hello') // → ['ja']
264
+ * getMissingLocales('common:greeting') // → ['en', 'ko', 'ja'] (key missing in all)
265
+ */
266
+ declare function getMissingLocales(key: string): Locale[];
241
267
  /**
242
268
  * Get all loaded locales
243
269
  * @param namespace - Optional namespace (returns from all if not specified)
@@ -434,4 +460,4 @@ interface RichTextSegment {
434
460
  */
435
461
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
436
462
 
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 };
463
+ 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, getMissingLocales, 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, tBatch, tRaw, trackMissingKeys, zh_es };
package/dist/index.d.ts CHANGED
@@ -231,6 +231,18 @@ declare function t(key: string, vars?: TranslationVars, locale?: Locale): string
231
231
  * tRaw('common:greeting') // → "Hello"
232
232
  */
233
233
  declare function tRaw(key: string, locale?: Locale): string | undefined;
234
+ /**
235
+ * Translate multiple keys at once (v0.15.0)
236
+ * @param keys - Array of translation keys
237
+ * @param vars - Optional variables applied to all translations
238
+ * @param locale - Override locale (optional)
239
+ * @returns Object mapping each key to its translated string
240
+ *
241
+ * @example
242
+ * tBatch(['greeting', 'farewell'])
243
+ * // → { greeting: 'Hello', farewell: 'Goodbye' }
244
+ */
245
+ declare function tBatch(keys: string[], vars?: TranslationVars, locale?: Locale): Record<string, string>;
234
246
  /**
235
247
  * Check if a translation key exists
236
248
  * @param key - Translation key (may include namespace prefix)
@@ -238,6 +250,20 @@ declare function tRaw(key: string, locale?: Locale): string | undefined;
238
250
  * @param context - Optional context for contextual translations (v0.9.0)
239
251
  */
240
252
  declare function hasTranslation(key: string, locale?: Locale, context?: string): boolean;
253
+ /**
254
+ * Get all locales where a translation key is missing (v0.16.0)
255
+ * Inverse of `hasTranslation` — checks every loaded locale in the key's namespace
256
+ * and returns those that do not contain the key.
257
+ *
258
+ * @param key - Translation key (may include namespace prefix)
259
+ * @returns Array of locale codes missing the key
260
+ *
261
+ * @example
262
+ * loadDictionaries({ en: { hello: 'Hi' }, ko: { hello: '안녕' }, ja: {} })
263
+ * getMissingLocales('hello') // → ['ja']
264
+ * getMissingLocales('common:greeting') // → ['en', 'ko', 'ja'] (key missing in all)
265
+ */
266
+ declare function getMissingLocales(key: string): Locale[];
241
267
  /**
242
268
  * Get all loaded locales
243
269
  * @param namespace - Optional namespace (returns from all if not specified)
@@ -434,4 +460,4 @@ interface RichTextSegment {
434
460
  */
435
461
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
436
462
 
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 };
463
+ 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, getMissingLocales, 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, tBatch, tRaw, trackMissingKeys, zh_es };
package/dist/index.js CHANGED
@@ -989,6 +989,13 @@ function tRaw(key, locale) {
989
989
  }
990
990
  return void 0;
991
991
  }
992
+ function tBatch(keys, vars, locale) {
993
+ const result = {};
994
+ for (const key of keys) {
995
+ result[key] = t(key, vars, locale);
996
+ }
997
+ return result;
998
+ }
992
999
  function hasTranslation(key, locale, context) {
993
1000
  const { namespace, key: actualKey } = parseKey(key);
994
1001
  const currentLocale2 = locale ?? getLocale();
@@ -1001,6 +1008,18 @@ function hasTranslation(key, locale, context) {
1001
1008
  }
1002
1009
  return getNestedValue(dict, actualKey) !== void 0;
1003
1010
  }
1011
+ function getMissingLocales(key) {
1012
+ const { namespace, key: actualKey } = parseKey(key);
1013
+ const nsDictionaries = namespacedDictionaries[namespace] || {};
1014
+ const missing = [];
1015
+ for (const locale of Object.keys(nsDictionaries)) {
1016
+ const dict = nsDictionaries[locale];
1017
+ if (!dict || getNestedValue(dict, actualKey) === void 0) {
1018
+ missing.push(locale);
1019
+ }
1020
+ }
1021
+ return missing;
1022
+ }
1004
1023
  function getLoadedLocales(namespace) {
1005
1024
  if (namespace) {
1006
1025
  return Object.keys(namespacedDictionaries[namespace] || {});
@@ -1241,6 +1260,7 @@ exports.getLoadedNamespaces = getLoadedNamespaces;
1241
1260
  exports.getLocale = getLocale;
1242
1261
  exports.getLocaleDisplayName = getLocaleDisplayName;
1243
1262
  exports.getMissingKeys = getMissingKeys;
1263
+ exports.getMissingLocales = getMissingLocales;
1244
1264
  exports.getTranslationKeys = getTranslationKeys;
1245
1265
  exports.hasTranslation = hasTranslation;
1246
1266
  exports.isLoaded = isLoaded;
@@ -1262,6 +1282,7 @@ exports.resetConfig = resetConfig;
1262
1282
  exports.restoreLocale = restoreLocale;
1263
1283
  exports.setLocale = setLocale;
1264
1284
  exports.t = t;
1285
+ exports.tBatch = tBatch;
1265
1286
  exports.tRaw = tRaw;
1266
1287
  exports.trackMissingKeys = trackMissingKeys;
1267
1288
  exports.zh_es = zh_es;