inline-i18n-multi 0.15.0 → 0.17.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
@@ -86,6 +86,8 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
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
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)
90
+ - **Translation Completeness Ratio** -- `getCompletenessRatio(locale, baseLocale?, namespace?)` returns the fraction of base-locale keys present in a target locale (v0.17.0)
89
91
 
90
92
  ---
91
93
 
@@ -1025,6 +1027,8 @@ Available helpers:
1025
1027
  | `formatList(values, options?, locale?)` | Format lists (conjunction, disjunction) |
1026
1028
  | `tRaw(key, locale?)` | Get raw template string without interpolation |
1027
1029
  | `tBatch(keys, vars?, locale?)` | Translate multiple keys at once |
1030
+ | `getMissingLocales(key)` | List locales missing a translation key |
1031
+ | `getCompletenessRatio(locale, baseLocale?, namespace?)` | Get translation completeness ratio (0-1) |
1028
1032
 
1029
1033
  ### Custom Formatters
1030
1034
 
package/dist/index.d.mts CHANGED
@@ -250,6 +250,20 @@ declare function tBatch(keys: string[], vars?: TranslationVars, locale?: Locale)
250
250
  * @param context - Optional context for contextual translations (v0.9.0)
251
251
  */
252
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[];
253
267
  /**
254
268
  * Get all loaded locales
255
269
  * @param namespace - Optional namespace (returns from all if not specified)
@@ -265,6 +279,22 @@ declare function getDictionary(locale: Locale, namespace?: string): Dictionary |
265
279
  * Get all loaded namespaces
266
280
  */
267
281
  declare function getLoadedNamespaces(): string[];
282
+ /**
283
+ * Get translation completeness ratio of a locale relative to a base locale (v0.17.0)
284
+ * Returns a value between 0 and 1 representing the fraction of base locale keys
285
+ * that exist in the target locale.
286
+ *
287
+ * @param locale - Target locale to measure
288
+ * @param baseLocale - Reference locale (defaults to config.defaultLocale)
289
+ * @param namespace - Optional namespace to scope the comparison
290
+ * @returns Ratio in [0, 1]; 1 if base has no keys or locale === base
291
+ *
292
+ * @example
293
+ * loadDictionaries({ en: { a: '1', b: '2', c: '3' }, ko: { a: '가' } })
294
+ * getCompletenessRatio('ko') // → 0.333... (1 of 3 keys translated)
295
+ * getCompletenessRatio('en') // → 1 (same as base)
296
+ */
297
+ declare function getCompletenessRatio(locale: Locale, baseLocale?: Locale, namespace?: string): number;
268
298
  /**
269
299
  * Get the display name of a locale using Intl.DisplayNames (v0.11.0)
270
300
  * @param locale - Locale code to get display name for (e.g., 'ko', 'ja', 'en-US')
@@ -446,4 +476,4 @@ interface RichTextSegment {
446
476
  */
447
477
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
448
478
 
449
- 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, tBatch, tRaw, trackMissingKeys, zh_es };
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 };
package/dist/index.d.ts CHANGED
@@ -250,6 +250,20 @@ declare function tBatch(keys: string[], vars?: TranslationVars, locale?: Locale)
250
250
  * @param context - Optional context for contextual translations (v0.9.0)
251
251
  */
252
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[];
253
267
  /**
254
268
  * Get all loaded locales
255
269
  * @param namespace - Optional namespace (returns from all if not specified)
@@ -265,6 +279,22 @@ declare function getDictionary(locale: Locale, namespace?: string): Dictionary |
265
279
  * Get all loaded namespaces
266
280
  */
267
281
  declare function getLoadedNamespaces(): string[];
282
+ /**
283
+ * Get translation completeness ratio of a locale relative to a base locale (v0.17.0)
284
+ * Returns a value between 0 and 1 representing the fraction of base locale keys
285
+ * that exist in the target locale.
286
+ *
287
+ * @param locale - Target locale to measure
288
+ * @param baseLocale - Reference locale (defaults to config.defaultLocale)
289
+ * @param namespace - Optional namespace to scope the comparison
290
+ * @returns Ratio in [0, 1]; 1 if base has no keys or locale === base
291
+ *
292
+ * @example
293
+ * loadDictionaries({ en: { a: '1', b: '2', c: '3' }, ko: { a: '가' } })
294
+ * getCompletenessRatio('ko') // → 0.333... (1 of 3 keys translated)
295
+ * getCompletenessRatio('en') // → 1 (same as base)
296
+ */
297
+ declare function getCompletenessRatio(locale: Locale, baseLocale?: Locale, namespace?: string): number;
268
298
  /**
269
299
  * Get the display name of a locale using Intl.DisplayNames (v0.11.0)
270
300
  * @param locale - Locale code to get display name for (e.g., 'ko', 'ja', 'en-US')
@@ -446,4 +476,4 @@ interface RichTextSegment {
446
476
  */
447
477
  declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
448
478
 
449
- 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, tBatch, tRaw, trackMissingKeys, zh_es };
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 };
package/dist/index.js CHANGED
@@ -1008,6 +1008,18 @@ function hasTranslation(key, locale, context) {
1008
1008
  }
1009
1009
  return getNestedValue(dict, actualKey) !== void 0;
1010
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
+ }
1011
1023
  function getLoadedLocales(namespace) {
1012
1024
  if (namespace) {
1013
1025
  return Object.keys(namespacedDictionaries[namespace] || {});
@@ -1027,6 +1039,18 @@ function getDictionary(locale, namespace) {
1027
1039
  function getLoadedNamespaces() {
1028
1040
  return Object.keys(namespacedDictionaries);
1029
1041
  }
1042
+ function getCompletenessRatio(locale, baseLocale, namespace) {
1043
+ const base = baseLocale ?? getConfig().defaultLocale;
1044
+ if (locale === base) return 1;
1045
+ const baseKeys = getTranslationKeys(base, namespace);
1046
+ if (baseKeys.length === 0) return 1;
1047
+ const localeKeys = new Set(getTranslationKeys(locale, namespace));
1048
+ let matched = 0;
1049
+ for (const k of baseKeys) {
1050
+ if (localeKeys.has(k)) matched++;
1051
+ }
1052
+ return matched / baseKeys.length;
1053
+ }
1030
1054
  function getLocaleDisplayName(locale, displayLocale) {
1031
1055
  const dl = displayLocale ?? getLocale();
1032
1056
  try {
@@ -1241,6 +1265,7 @@ exports.en_zh = en_zh;
1241
1265
  exports.formatDate = formatDate;
1242
1266
  exports.formatList = formatList;
1243
1267
  exports.formatNumber = formatNumber;
1268
+ exports.getCompletenessRatio = getCompletenessRatio;
1244
1269
  exports.getConfig = getConfig;
1245
1270
  exports.getDictionary = getDictionary;
1246
1271
  exports.getLoadedLocales = getLoadedLocales;
@@ -1248,6 +1273,7 @@ exports.getLoadedNamespaces = getLoadedNamespaces;
1248
1273
  exports.getLocale = getLocale;
1249
1274
  exports.getLocaleDisplayName = getLocaleDisplayName;
1250
1275
  exports.getMissingKeys = getMissingKeys;
1276
+ exports.getMissingLocales = getMissingLocales;
1251
1277
  exports.getTranslationKeys = getTranslationKeys;
1252
1278
  exports.hasTranslation = hasTranslation;
1253
1279
  exports.isLoaded = isLoaded;