inline-i18n-multi 0.13.0 → 0.15.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 +4 -0
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,8 @@ See "Hello" in your app? Just search for "Hello" in your codebase. **Done.**
|
|
|
84
84
|
- **Missing Translation Tracker** - Runtime collection of missing translation keys (`trackMissingKeys(true/false)`, `getMissingKeys()`, `clearMissingKeys()`)
|
|
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
|
+
- **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)
|
|
87
89
|
|
|
88
90
|
---
|
|
89
91
|
|
|
@@ -1021,6 +1023,8 @@ Available helpers:
|
|
|
1021
1023
|
| `formatNumber(value, options?, locale?)` | Format numbers (currency, percent, etc.) |
|
|
1022
1024
|
| `formatDate(value, options?, locale?)` | Format dates and times |
|
|
1023
1025
|
| `formatList(values, options?, locale?)` | Format lists (conjunction, disjunction) |
|
|
1026
|
+
| `tRaw(key, locale?)` | Get raw template string without interpolation |
|
|
1027
|
+
| `tBatch(keys, vars?, locale?)` | Translate multiple keys at once |
|
|
1024
1028
|
|
|
1025
1029
|
### Custom Formatters
|
|
1026
1030
|
|
package/dist/index.d.mts
CHANGED
|
@@ -219,6 +219,30 @@ declare function isLoaded(locale: Locale, namespace?: string): boolean;
|
|
|
219
219
|
* t('items.count', { count: 5 }) // "5 items"
|
|
220
220
|
*/
|
|
221
221
|
declare function t(key: string, vars?: TranslationVars, locale?: Locale): string;
|
|
222
|
+
/**
|
|
223
|
+
* Get the raw template string for a translation key without interpolation (v0.14.0)
|
|
224
|
+
* Returns undefined if the key is not found.
|
|
225
|
+
*
|
|
226
|
+
* @param key - Dot-separated translation key, optionally prefixed with namespace
|
|
227
|
+
* @param locale - Override locale (optional)
|
|
228
|
+
* @example
|
|
229
|
+
* tRaw('welcome') // → "Welcome, {name}!"
|
|
230
|
+
* tRaw('items.count', 'ko') // → "{count}개 항목"
|
|
231
|
+
* tRaw('common:greeting') // → "Hello"
|
|
232
|
+
*/
|
|
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>;
|
|
222
246
|
/**
|
|
223
247
|
* Check if a translation key exists
|
|
224
248
|
* @param key - Translation key (may include namespace prefix)
|
|
@@ -422,4 +446,4 @@ interface RichTextSegment {
|
|
|
422
446
|
*/
|
|
423
447
|
declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
|
|
424
448
|
|
|
425
|
-
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, trackMissingKeys, zh_es };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -219,6 +219,30 @@ declare function isLoaded(locale: Locale, namespace?: string): boolean;
|
|
|
219
219
|
* t('items.count', { count: 5 }) // "5 items"
|
|
220
220
|
*/
|
|
221
221
|
declare function t(key: string, vars?: TranslationVars, locale?: Locale): string;
|
|
222
|
+
/**
|
|
223
|
+
* Get the raw template string for a translation key without interpolation (v0.14.0)
|
|
224
|
+
* Returns undefined if the key is not found.
|
|
225
|
+
*
|
|
226
|
+
* @param key - Dot-separated translation key, optionally prefixed with namespace
|
|
227
|
+
* @param locale - Override locale (optional)
|
|
228
|
+
* @example
|
|
229
|
+
* tRaw('welcome') // → "Welcome, {name}!"
|
|
230
|
+
* tRaw('items.count', 'ko') // → "{count}개 항목"
|
|
231
|
+
* tRaw('common:greeting') // → "Hello"
|
|
232
|
+
*/
|
|
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>;
|
|
222
246
|
/**
|
|
223
247
|
* Check if a translation key exists
|
|
224
248
|
* @param key - Translation key (may include namespace prefix)
|
|
@@ -422,4 +446,4 @@ interface RichTextSegment {
|
|
|
422
446
|
*/
|
|
423
447
|
declare function parseRichText(template: string, componentNames: string[]): RichTextSegment[];
|
|
424
448
|
|
|
425
|
-
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, trackMissingKeys, zh_es };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -976,6 +976,26 @@ function t(key, vars, locale) {
|
|
|
976
976
|
};
|
|
977
977
|
return applyDebugFormat(result, debugInfo);
|
|
978
978
|
}
|
|
979
|
+
function tRaw(key, locale) {
|
|
980
|
+
const { namespace, key: actualKey } = parseKey(key);
|
|
981
|
+
const currentLocale2 = locale ?? getLocale();
|
|
982
|
+
const fallbackChain = buildFallbackChain(currentLocale2);
|
|
983
|
+
const nsDictionaries = namespacedDictionaries[namespace] || {};
|
|
984
|
+
for (const tryLocale of fallbackChain) {
|
|
985
|
+
const dict = nsDictionaries[tryLocale];
|
|
986
|
+
if (!dict) continue;
|
|
987
|
+
const found = getNestedValue(dict, actualKey);
|
|
988
|
+
if (found !== void 0) return found;
|
|
989
|
+
}
|
|
990
|
+
return void 0;
|
|
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
|
+
}
|
|
979
999
|
function hasTranslation(key, locale, context) {
|
|
980
1000
|
const { namespace, key: actualKey } = parseKey(key);
|
|
981
1001
|
const currentLocale2 = locale ?? getLocale();
|
|
@@ -1249,6 +1269,8 @@ exports.resetConfig = resetConfig;
|
|
|
1249
1269
|
exports.restoreLocale = restoreLocale;
|
|
1250
1270
|
exports.setLocale = setLocale;
|
|
1251
1271
|
exports.t = t;
|
|
1272
|
+
exports.tBatch = tBatch;
|
|
1273
|
+
exports.tRaw = tRaw;
|
|
1252
1274
|
exports.trackMissingKeys = trackMissingKeys;
|
|
1253
1275
|
exports.zh_es = zh_es;
|
|
1254
1276
|
//# sourceMappingURL=index.js.map
|