inline-i18n-multi 0.16.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 +2 -0
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,6 +87,7 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
|
|
|
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
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)
|
|
90
91
|
|
|
91
92
|
---
|
|
92
93
|
|
|
@@ -1027,6 +1028,7 @@ Available helpers:
|
|
|
1027
1028
|
| `tRaw(key, locale?)` | Get raw template string without interpolation |
|
|
1028
1029
|
| `tBatch(keys, vars?, locale?)` | Translate multiple keys at once |
|
|
1029
1030
|
| `getMissingLocales(key)` | List locales missing a translation key |
|
|
1031
|
+
| `getCompletenessRatio(locale, baseLocale?, namespace?)` | Get translation completeness ratio (0-1) |
|
|
1030
1032
|
|
|
1031
1033
|
### Custom Formatters
|
|
1032
1034
|
|
package/dist/index.d.mts
CHANGED
|
@@ -279,6 +279,22 @@ declare function getDictionary(locale: Locale, namespace?: string): Dictionary |
|
|
|
279
279
|
* Get all loaded namespaces
|
|
280
280
|
*/
|
|
281
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;
|
|
282
298
|
/**
|
|
283
299
|
* Get the display name of a locale using Intl.DisplayNames (v0.11.0)
|
|
284
300
|
* @param locale - Locale code to get display name for (e.g., 'ko', 'ja', 'en-US')
|
|
@@ -460,4 +476,4 @@ interface RichTextSegment {
|
|
|
460
476
|
*/
|
|
461
477
|
declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
|
|
462
478
|
|
|
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 };
|
|
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
|
@@ -279,6 +279,22 @@ declare function getDictionary(locale: Locale, namespace?: string): Dictionary |
|
|
|
279
279
|
* Get all loaded namespaces
|
|
280
280
|
*/
|
|
281
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;
|
|
282
298
|
/**
|
|
283
299
|
* Get the display name of a locale using Intl.DisplayNames (v0.11.0)
|
|
284
300
|
* @param locale - Locale code to get display name for (e.g., 'ko', 'ja', 'en-US')
|
|
@@ -460,4 +476,4 @@ interface RichTextSegment {
|
|
|
460
476
|
*/
|
|
461
477
|
declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
|
|
462
478
|
|
|
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 };
|
|
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
|
@@ -1039,6 +1039,18 @@ function getDictionary(locale, namespace) {
|
|
|
1039
1039
|
function getLoadedNamespaces() {
|
|
1040
1040
|
return Object.keys(namespacedDictionaries);
|
|
1041
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
|
+
}
|
|
1042
1054
|
function getLocaleDisplayName(locale, displayLocale) {
|
|
1043
1055
|
const dl = displayLocale ?? getLocale();
|
|
1044
1056
|
try {
|
|
@@ -1253,6 +1265,7 @@ exports.en_zh = en_zh;
|
|
|
1253
1265
|
exports.formatDate = formatDate;
|
|
1254
1266
|
exports.formatList = formatList;
|
|
1255
1267
|
exports.formatNumber = formatNumber;
|
|
1268
|
+
exports.getCompletenessRatio = getCompletenessRatio;
|
|
1256
1269
|
exports.getConfig = getConfig;
|
|
1257
1270
|
exports.getDictionary = getDictionary;
|
|
1258
1271
|
exports.getLoadedLocales = getLoadedLocales;
|