inline-i18n-multi 0.16.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/dist/index.mjs CHANGED
@@ -936,7 +936,7 @@ function t(key, vars, locale) {
936
936
  }
937
937
  }
938
938
  if (!template) {
939
- recordMissingKey(key);
939
+ recordMissingKey(key, currentLocale2);
940
940
  emitWarning({
941
941
  type: "missing_translation",
942
942
  key,
@@ -1037,6 +1037,18 @@ function getDictionary(locale, namespace) {
1037
1037
  function getLoadedNamespaces() {
1038
1038
  return Object.keys(namespacedDictionaries);
1039
1039
  }
1040
+ function getCompletenessRatio(locale, baseLocale, namespace) {
1041
+ const base = baseLocale ?? getConfig().defaultLocale;
1042
+ if (locale === base) return 1;
1043
+ const baseKeys = getTranslationKeys(base, namespace);
1044
+ if (baseKeys.length === 0) return 1;
1045
+ const localeKeys = new Set(getTranslationKeys(locale, namespace));
1046
+ let matched = 0;
1047
+ for (const k of baseKeys) {
1048
+ if (localeKeys.has(k)) matched++;
1049
+ }
1050
+ return matched / baseKeys.length;
1051
+ }
1040
1052
  function getLocaleDisplayName(locale, displayLocale) {
1041
1053
  const dl = displayLocale ?? getLocale();
1042
1054
  try {
@@ -1075,6 +1087,16 @@ function getTranslationKeys(locale, namespace) {
1075
1087
  }
1076
1088
  var missingKeys = /* @__PURE__ */ new Set();
1077
1089
  var trackMissing = false;
1090
+ var missingKeyListeners = /* @__PURE__ */ new Set();
1091
+ function onMissingKey(callback) {
1092
+ missingKeyListeners.add(callback);
1093
+ return () => {
1094
+ missingKeyListeners.delete(callback);
1095
+ };
1096
+ }
1097
+ function clearMissingKeyListeners() {
1098
+ missingKeyListeners.clear();
1099
+ }
1078
1100
  function trackMissingKeys(enabled) {
1079
1101
  trackMissing = enabled;
1080
1102
  if (!enabled) {
@@ -1087,10 +1109,16 @@ function getMissingKeys() {
1087
1109
  function clearMissingKeys() {
1088
1110
  missingKeys = /* @__PURE__ */ new Set();
1089
1111
  }
1090
- function recordMissingKey(key) {
1112
+ function recordMissingKey(key, locale) {
1091
1113
  if (trackMissing) {
1092
1114
  missingKeys.add(key);
1093
1115
  }
1116
+ if (missingKeyListeners.size > 0) {
1117
+ const loc = locale ?? getLocale();
1118
+ for (const cb of missingKeyListeners) {
1119
+ cb(key, loc);
1120
+ }
1121
+ }
1094
1122
  }
1095
1123
 
1096
1124
  // src/detect.ts
@@ -1234,6 +1262,6 @@ function parseRichText(template, componentNames) {
1234
1262
  return segments;
1235
1263
  }
1236
1264
 
1237
- export { __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 };
1265
+ export { __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 };
1238
1266
  //# sourceMappingURL=index.mjs.map
1239
1267
  //# sourceMappingURL=index.mjs.map