inline-i18n-multi 0.17.0 → 0.18.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
@@ -88,6 +88,7 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
88
88
  - **Batch Translation** -- `tBatch(keys, vars?, locale?)` translates multiple keys at once (v0.15.0)
89
89
  - **Missing Locales Detection** -- `getMissingLocales(key)` returns locales where a key is absent (v0.16.0)
90
90
  - **Translation Completeness Ratio** -- `getCompletenessRatio(locale, baseLocale?, namespace?)` returns the fraction of base-locale keys present in a target locale (v0.17.0)
91
+ - **Missing Key Listener** -- `onMissingKey(callback)` subscribes to missing translation events with `(key, locale)` (v0.18.0)
91
92
 
92
93
  ---
93
94
 
@@ -1029,6 +1030,7 @@ Available helpers:
1029
1030
  | `tBatch(keys, vars?, locale?)` | Translate multiple keys at once |
1030
1031
  | `getMissingLocales(key)` | List locales missing a translation key |
1031
1032
  | `getCompletenessRatio(locale, baseLocale?, namespace?)` | Get translation completeness ratio (0-1) |
1033
+ | `onMissingKey(callback)` | Subscribe to missing translation key events |
1032
1034
 
1033
1035
  ### Custom Formatters
1034
1036
 
package/dist/index.d.mts CHANGED
@@ -318,6 +318,27 @@ declare function getLocaleDisplayName(locale: Locale, displayLocale?: Locale): s
318
318
  * getTranslationKeys('en', 'common') // → ['hello', 'goodbye']
319
319
  */
320
320
  declare function getTranslationKeys(locale?: Locale, namespace?: string): string[];
321
+ type MissingKeyCallback = (key: string, locale: Locale) => void;
322
+ /**
323
+ * Subscribe to missing translation key events (v0.18.0)
324
+ * Callback fires every time `t()` encounters a key with no translation
325
+ * (independent of `trackMissingKeys`).
326
+ *
327
+ * @param callback - Receives `(key, requestedLocale)` for each missing key
328
+ * @returns Unsubscribe function
329
+ *
330
+ * @example
331
+ * const off = onMissingKey((key, locale) => {
332
+ * reportToMonitoring({ key, locale })
333
+ * })
334
+ * t('missing.key') // callback fires with ('missing.key', 'en')
335
+ * off() // stop listening
336
+ */
337
+ declare function onMissingKey(callback: MissingKeyCallback): () => void;
338
+ /**
339
+ * Remove all missing-key listeners (for testing) (v0.18.0)
340
+ */
341
+ declare function clearMissingKeyListeners(): void;
321
342
  /**
322
343
  * Enable or disable missing translation tracking (v0.11.0)
323
344
  * When enabled, all missing translation keys encountered via t() are recorded.
@@ -476,4 +497,4 @@ interface RichTextSegment {
476
497
  */
477
498
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
478
499
 
479
- 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, getCompletenessRatio, 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 };
500
+ 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, clearMissingKeyListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, formatDate, formatList, formatNumber, getCompletenessRatio, 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, onMissingKey, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, tBatch, tRaw, trackMissingKeys, zh_es };
package/dist/index.d.ts CHANGED
@@ -318,6 +318,27 @@ declare function getLocaleDisplayName(locale: Locale, displayLocale?: Locale): s
318
318
  * getTranslationKeys('en', 'common') // → ['hello', 'goodbye']
319
319
  */
320
320
  declare function getTranslationKeys(locale?: Locale, namespace?: string): string[];
321
+ type MissingKeyCallback = (key: string, locale: Locale) => void;
322
+ /**
323
+ * Subscribe to missing translation key events (v0.18.0)
324
+ * Callback fires every time `t()` encounters a key with no translation
325
+ * (independent of `trackMissingKeys`).
326
+ *
327
+ * @param callback - Receives `(key, requestedLocale)` for each missing key
328
+ * @returns Unsubscribe function
329
+ *
330
+ * @example
331
+ * const off = onMissingKey((key, locale) => {
332
+ * reportToMonitoring({ key, locale })
333
+ * })
334
+ * t('missing.key') // callback fires with ('missing.key', 'en')
335
+ * off() // stop listening
336
+ */
337
+ declare function onMissingKey(callback: MissingKeyCallback): () => void;
338
+ /**
339
+ * Remove all missing-key listeners (for testing) (v0.18.0)
340
+ */
341
+ declare function clearMissingKeyListeners(): void;
321
342
  /**
322
343
  * Enable or disable missing translation tracking (v0.11.0)
323
344
  * When enabled, all missing translation keys encountered via t() are recorded.
@@ -476,4 +497,4 @@ interface RichTextSegment {
476
497
  */
477
498
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
478
499
 
479
- 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, getCompletenessRatio, 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 };
500
+ 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, clearMissingKeyListeners, clearMissingKeys, configure, createScope, detectLocale, en_de, en_es, en_fr, en_ja, en_zh, formatDate, formatList, formatNumber, getCompletenessRatio, 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, onMissingKey, parseRichText, registerFormatter, resetConfig, restoreLocale, setLocale, t, tBatch, tRaw, trackMissingKeys, zh_es };
package/dist/index.js CHANGED
@@ -938,7 +938,7 @@ function t(key, vars, locale) {
938
938
  }
939
939
  }
940
940
  if (!template) {
941
- recordMissingKey(key);
941
+ recordMissingKey(key, currentLocale2);
942
942
  emitWarning({
943
943
  type: "missing_translation",
944
944
  key,
@@ -1089,6 +1089,16 @@ function getTranslationKeys(locale, namespace) {
1089
1089
  }
1090
1090
  var missingKeys = /* @__PURE__ */ new Set();
1091
1091
  var trackMissing = false;
1092
+ var missingKeyListeners = /* @__PURE__ */ new Set();
1093
+ function onMissingKey(callback) {
1094
+ missingKeyListeners.add(callback);
1095
+ return () => {
1096
+ missingKeyListeners.delete(callback);
1097
+ };
1098
+ }
1099
+ function clearMissingKeyListeners() {
1100
+ missingKeyListeners.clear();
1101
+ }
1092
1102
  function trackMissingKeys(enabled) {
1093
1103
  trackMissing = enabled;
1094
1104
  if (!enabled) {
@@ -1101,10 +1111,16 @@ function getMissingKeys() {
1101
1111
  function clearMissingKeys() {
1102
1112
  missingKeys = /* @__PURE__ */ new Set();
1103
1113
  }
1104
- function recordMissingKey(key) {
1114
+ function recordMissingKey(key, locale) {
1105
1115
  if (trackMissing) {
1106
1116
  missingKeys.add(key);
1107
1117
  }
1118
+ if (missingKeyListeners.size > 0) {
1119
+ const loc = locale ?? getLocale();
1120
+ for (const cb of missingKeyListeners) {
1121
+ cb(key, loc);
1122
+ }
1123
+ }
1108
1124
  }
1109
1125
 
1110
1126
  // src/detect.ts
@@ -1253,6 +1269,7 @@ exports.clearDictionaries = clearDictionaries;
1253
1269
  exports.clearFormatters = clearFormatters;
1254
1270
  exports.clearICUCache = clearICUCache;
1255
1271
  exports.clearLocaleListeners = clearLocaleListeners;
1272
+ exports.clearMissingKeyListeners = clearMissingKeyListeners;
1256
1273
  exports.clearMissingKeys = clearMissingKeys;
1257
1274
  exports.configure = configure;
1258
1275
  exports.createScope = createScope;
@@ -1289,6 +1306,7 @@ exports.loadAsync = loadAsync;
1289
1306
  exports.loadDictionaries = loadDictionaries;
1290
1307
  exports.loadDictionary = loadDictionary;
1291
1308
  exports.onLocaleChange = onLocaleChange;
1309
+ exports.onMissingKey = onMissingKey;
1292
1310
  exports.parseRichText = parseRichText;
1293
1311
  exports.registerFormatter = registerFormatter;
1294
1312
  exports.resetConfig = resetConfig;