@nice2dev/i18n 1.1.10 → 1.2.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 +74 -35
- package/dist/all.cjs +1 -0
- package/dist/all.d.ts +136 -0
- package/dist/all.mjs +25 -0
- package/dist/dictionaries/de.cjs +1 -1
- package/dist/dictionaries/de.mjs +1008 -1
- package/dist/dictionaries/en.cjs +1 -1
- package/dist/dictionaries/en.mjs +1008 -1
- package/dist/dictionaries/es.cjs +1 -1
- package/dist/dictionaries/es.mjs +1008 -1
- package/dist/dictionaries/fr.cjs +1 -1
- package/dist/dictionaries/fr.mjs +1008 -1
- package/dist/dictionaries/pl.cjs +1 -1
- package/dist/dictionaries/pl.mjs +1008 -1
- package/dist/dictionaries/uk.cjs +1 -1
- package/dist/dictionaries/uk.mjs +1008 -1
- package/dist/i18n.cjs +1 -1
- package/dist/i18n.mjs +10 -51
- package/dist/i18nContext.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +46 -158
- package/dist/index.mjs +108 -127
- package/dist/languages.cjs +1 -1
- package/dist/languages.mjs +14 -2
- package/dist/lazyDictionaries.cjs +1 -1
- package/dist/lazyDictionaries.mjs +20 -19
- package/package.json +6 -1
package/dist/i18n.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(u,s={}){let r=u.replace(/\{(\w+)\}/g,(t,o)=>{const e=s[o];return e!==void 0?String(e):t});return r=r.replace(/\{(\w+),\s*plural,\s*one\{([^}]+)\}\s*other\{([^}]+)\}\}/g,(t,o,e,a)=>{const n=s[o];return typeof n!="number"?t:(n===1?e:a).replace(/#/g,String(n))}),r}exports.formatMessage=l;
|
package/dist/i18n.mjs
CHANGED
|
@@ -1,57 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { NICE_SUPPORTED_LANGS as g } from "./languages.mjs";
|
|
6
|
-
import { NICE_I18N_DICTIONARIES as c } from "./dictionaries/index.mjs";
|
|
7
|
-
const x = ({
|
|
8
|
-
t: r,
|
|
9
|
-
lang: e = "en",
|
|
10
|
-
overrides: t,
|
|
11
|
-
children: o
|
|
12
|
-
}) => {
|
|
13
|
-
const i = m(() => {
|
|
14
|
-
if (r)
|
|
15
|
-
return r;
|
|
16
|
-
const n = c[e] ?? c.en, a = t ? { ...n, ...t } : n;
|
|
17
|
-
return (u, s) => a[u] ?? s;
|
|
18
|
-
}, [r, e, t]);
|
|
19
|
-
return /* @__PURE__ */ f(p, { t: i, lang: e, children: o });
|
|
20
|
-
};
|
|
21
|
-
function C(r = "en", e) {
|
|
22
|
-
const t = c[r] ?? c.en, o = e ? { ...t, ...e } : t;
|
|
23
|
-
return (i, n) => o[i] ?? n;
|
|
24
|
-
}
|
|
25
|
-
function E(r, e = {}) {
|
|
26
|
-
let t = r.replace(/\{(\w+)\}/g, (o, i) => {
|
|
27
|
-
const n = e[i];
|
|
28
|
-
return n !== void 0 ? String(n) : o;
|
|
1
|
+
function c(l, u = {}) {
|
|
2
|
+
let e = l.replace(/\{(\w+)\}/g, (t, n) => {
|
|
3
|
+
const r = u[n];
|
|
4
|
+
return r !== void 0 ? String(r) : t;
|
|
29
5
|
});
|
|
30
|
-
return
|
|
6
|
+
return e = e.replace(
|
|
31
7
|
/\{(\w+),\s*plural,\s*one\{([^}]+)\}\s*other\{([^}]+)\}\}/g,
|
|
32
|
-
(
|
|
33
|
-
const
|
|
34
|
-
return typeof
|
|
8
|
+
(t, n, r, s) => {
|
|
9
|
+
const o = u[n];
|
|
10
|
+
return typeof o != "number" ? t : (o === 1 ? r : s).replace(/#/g, String(o));
|
|
35
11
|
}
|
|
36
|
-
),
|
|
37
|
-
}
|
|
38
|
-
function l(r) {
|
|
39
|
-
return g.includes(r);
|
|
40
|
-
}
|
|
41
|
-
function P() {
|
|
42
|
-
var e;
|
|
43
|
-
if (typeof navigator > "u")
|
|
44
|
-
return "en";
|
|
45
|
-
const r = (e = navigator.language) == null ? void 0 : e.split("-")[0];
|
|
46
|
-
return l(r) ? r : "en";
|
|
12
|
+
), e;
|
|
47
13
|
}
|
|
48
14
|
export {
|
|
49
|
-
c as
|
|
50
|
-
g as NICE_SUPPORTED_LANGS,
|
|
51
|
-
x as NiceI18nProvider,
|
|
52
|
-
C as createTranslator,
|
|
53
|
-
P as detectBrowserLanguage,
|
|
54
|
-
E as formatMessage,
|
|
55
|
-
l as isSupported,
|
|
56
|
-
L as useNiceTranslation
|
|
15
|
+
c as formatMessage
|
|
57
16
|
};
|
package/dist/i18nContext.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useContext as o, createContext as r } from "react";
|
|
3
3
|
const a = (e, t) => t, c = r(a), i = r("en"), u = ({ t: e, lang: t, children: s }) => /* @__PURE__ */ n(i.Provider, { value: t, children: /* @__PURE__ */ n(c.Provider, { value: e, children: s }) });
|
|
4
4
|
function v() {
|
|
5
5
|
const e = o(c), t = o(i);
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./lazyDictionaries.cjs"),d=require("./i18n.cjs"),s=require("./languages.cjs"),l=require("./i18nContext.cjs"),n=require("./icu.cjs"),a=require("./rtl.cjs"),i=require("./locale.cjs"),t=require("./timezone.cjs"),e=require("./calendar-systems.cjs"),r=require("./pseudo-localization.cjs"),o=require("./dynamic-loading.cjs");exports.NiceI18nLazyProvider=c.NiceI18nLazyProvider;exports.NiceI18nProvider=c.NiceI18nProvider;exports.getLoadedNiceDictionary=c.getLoadedNiceDictionary;exports.loadNiceDictionary=c.loadNiceDictionary;exports.formatMessage=d.formatMessage;exports.NICE_SUPPORTED_LANGS=s.NICE_SUPPORTED_LANGS;exports.detectBrowserLanguage=s.detectBrowserLanguage;exports.isSupported=s.isSupported;exports.useNiceTranslation=l.useNiceTranslation;exports.createICUTranslator=n.createICUTranslator;exports.formatICU=n.formatICU;exports.getOrdinalCategory=n.getOrdinalCategory;exports.getPluralCategory=n.getPluralCategory;exports.ordinal=n.ordinal;exports.plural=n.plural;exports.select=n.select;exports.RTLProvider=a.RTLProvider;exports.RTL_CSS_VARS=a.RTL_CSS_VARS;exports.RTL_LANGUAGES=a.RTL_LANGUAGES;exports.analyzeStylesForRTL=a.analyzeStylesForRTL;exports.flipAlignment=a.flipAlignment;exports.flipHorizontal=a.flipHorizontal;exports.getDocumentDirection=a.getDocumentDirection;exports.getLogicalProperty=a.getLogicalProperty;exports.getRTLCSSVars=a.getRTLCSSVars;exports.getTextDirection=a.getTextDirection;exports.isRTLLanguage=a.isRTLLanguage;exports.rtlValue=a.rtlValue;exports.setDocumentDirection=a.setDocumentDirection;exports.useIsRTL=a.useIsRTL;exports.useRTL=a.useRTL;exports.createCurrencyFormatter=i.createCurrencyFormatter;exports.createDateFormatter=i.createDateFormatter;exports.createNumberFormatter=i.createNumberFormatter;exports.createTimeFormatter=i.createTimeFormatter;exports.getLocaleTag=i.getLocaleTag;exports.useNiceCurrencyFormat=i.useNiceCurrencyFormat;exports.useNiceDateFormat=i.useNiceDateFormat;exports.useNiceNumberFormat=i.useNiceNumberFormat;exports.useNiceTimeFormat=i.useNiceTimeFormat;exports.TIMEZONE_GROUPS=t.TIMEZONE_GROUPS;exports.convertTimezone=t.convertTimezone;exports.createTimezoneFormatter=t.createTimezoneFormatter;exports.detectTimezone=t.detectTimezone;exports.fromUTC=t.fromUTC;exports.getAllTimezones=t.getAllTimezones;exports.getNextDSTTransition=t.getNextDSTTransition;exports.getTimezoneInfo=t.getTimezoneInfo;exports.getTimezonesGrouped=t.getTimezonesGrouped;exports.isDSTActive=t.isDSTActive;exports.isValidTimezone=t.isValidTimezone;exports.toUTC=t.toUTC;exports.useTimezone=t.useTimezone;exports.CALENDAR_INFO=e.CALENDAR_INFO;exports.CELESTIAL_STEMS=e.CELESTIAL_STEMS;exports.CHINESE_ZODIAC=e.CHINESE_ZODIAC;exports.DEFAULT_CALENDAR=e.DEFAULT_CALENDAR;exports.HEBREW_MONTHS=e.HEBREW_MONTHS;exports.HEBREW_MONTHS_LEAP=e.HEBREW_MONTHS_LEAP;exports.HIJRI_MONTHS=e.HIJRI_MONTHS;exports.JAPANESE_ERAS=e.JAPANESE_ERAS;exports.PERSIAN_MONTHS=e.PERSIAN_MONTHS;exports.createCalendarFormatter=e.createCalendarFormatter;exports.getAvailableCalendars=e.getAvailableCalendars;exports.getCalendarInfo=e.getCalendarInfo;exports.getCelestialStem=e.getCelestialStem;exports.getChineseZodiac=e.getChineseZodiac;exports.getCurrentCalendarDate=e.getCurrentCalendarDate;exports.getHijriMonthDays=e.getHijriMonthDays;exports.getJapaneseEra=e.getJapaneseEra;exports.getJapaneseYear=e.getJapaneseYear;exports.getRecommendedCalendars=e.getRecommendedCalendars;exports.isHebrewLeapYear=e.isHebrewLeapYear;exports.isHijriLeapYear=e.isHijriLeapYear;exports.isPersianLeapYear=e.isPersianLeapYear;exports.toCalendar=e.toCalendar;exports.useCalendar=e.useCalendar;exports.PSEUDO_PRESETS=r.PSEUDO_PRESETS;exports.PseudoLocalizationProvider=r.PseudoLocalizationProvider;exports.addAccents=r.addAccents;exports.addBidiMarkers=r.addBidiMarkers;exports.addBrackets=r.addBrackets;exports.analyzeDictionary=r.analyzeDictionary;exports.containsNonAscii=r.containsNonAscii;exports.detectHardcodedText=r.detectHardcodedText;exports.expandText=r.expandText;exports.getPseudoLocalizationPreset=r.getPseudoLocalizationPreset;exports.pseudoLocalize=r.pseudoLocalize;exports.pseudoLocalizeDictionary=r.pseudoLocalizeDictionary;exports.usePseudoLocalization=r.usePseudoLocalization;exports.DynamicI18nProvider=o.DynamicI18nProvider;exports.createDynamicLoader=o.createDynamicLoader;exports.createFetchLoader=o.createFetchLoader;exports.createImportLoader=o.createImportLoader;exports.detectAndLoad=o.detectAndLoad;exports.preloadWithStrategy=o.preloadWithStrategy;exports.useDynamicI18n=o.useDynamicI18n;exports.useDynamicTranslation=o.useDynamicTranslation;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Features:
|
|
6
6
|
* - NiceI18nProvider for React context-based translations
|
|
7
|
-
* - Built-in dictionaries for
|
|
7
|
+
* - Built-in dictionaries for 30 languages, loaded one language at a time
|
|
8
8
|
* - ICU MessageFormat with pluralization, gender, ordinals, and select
|
|
9
9
|
* - Browser language detection
|
|
10
10
|
* - Custom translation function support (e.g. react-i18next)
|
|
11
11
|
*
|
|
12
|
+
* Nothing on this entry imports a dictionary (1.2.0). What needs all thirty at once — the
|
|
13
|
+
* dictionary map, `createTranslator`, the translation tooling — is in `@nice2dev/i18n/all`.
|
|
14
|
+
*
|
|
12
15
|
* @packageDocumentation
|
|
13
16
|
*/
|
|
14
17
|
|
|
@@ -185,9 +188,6 @@ export declare function createTimeFormatter(lang: NiceSupportedLang, style?: Dat
|
|
|
185
188
|
*/
|
|
186
189
|
export declare function createTimezoneFormatter(lang: NiceSupportedLang, timezone: string, options?: TimezoneFormatterOptions): TimezoneFormatter;
|
|
187
190
|
|
|
188
|
-
/** Get a translation function without React context (for non-component code). */
|
|
189
|
-
export declare function createTranslator(lang?: NiceSupportedLang, overrides?: Record<string, string>): NiceTranslateFn;
|
|
190
|
-
|
|
191
191
|
export declare type DateFormatStyle = 'short' | 'medium' | 'long' | 'full';
|
|
192
192
|
|
|
193
193
|
export declare const DEFAULT_CALENDAR: Record<NiceSupportedLang, CalendarSystem>;
|
|
@@ -269,17 +269,6 @@ export declare interface DynamicLoader {
|
|
|
269
269
|
*/
|
|
270
270
|
export declare function expandText(text: string, factor?: number, useVowelDoubling?: boolean): string;
|
|
271
271
|
|
|
272
|
-
/**
|
|
273
|
-
* Find fuzzy matches in existing translations for reuse.
|
|
274
|
-
* Compares the English value to find similar existing translations.
|
|
275
|
-
*/
|
|
276
|
-
export declare function findSimilarTranslation(englishValue: string, lang: NiceSupportedLang, threshold?: number): {
|
|
277
|
-
key: string;
|
|
278
|
-
english: string;
|
|
279
|
-
translated: string;
|
|
280
|
-
similarity: number;
|
|
281
|
-
} | undefined;
|
|
282
|
-
|
|
283
272
|
/**
|
|
284
273
|
* Flip a horizontal alignment for RTL.
|
|
285
274
|
* start ↔ end, left ↔ right
|
|
@@ -316,6 +305,13 @@ export declare function flipHorizontal(position: 'left' | 'right'): 'left' | 'ri
|
|
|
316
305
|
*/
|
|
317
306
|
export declare function formatICU(template: string, values?: Record<string, string | number | Date>, options?: ICUFormatOptions): string;
|
|
318
307
|
|
|
308
|
+
/**
|
|
309
|
+
* ICU MessageFormat-lite interpolation, the one helper of this module that is not a provider.
|
|
310
|
+
*
|
|
311
|
+
* 1.2.0: the provider moved to ./lazyDictionaries (it loads one language at a time), the
|
|
312
|
+
* language helpers to ./languages and `createTranslator` to ./all — this module used to
|
|
313
|
+
* import every dictionary for the eager provider.
|
|
314
|
+
*/
|
|
319
315
|
/**
|
|
320
316
|
* ICU MessageFormat-lite interpolation.
|
|
321
317
|
* Supports basic {placeholder} and {plural, count, ...} patterns.
|
|
@@ -327,26 +323,11 @@ export declare function formatMessage(template: string, values?: Record<string,
|
|
|
327
323
|
*/
|
|
328
324
|
export declare function fromUTC(date: Date, toTimezone?: string): Date;
|
|
329
325
|
|
|
330
|
-
/**
|
|
331
|
-
* Generate a coverage report in markdown format.
|
|
332
|
-
*/
|
|
333
|
-
export declare function generateCoverageReport(): string;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Generate TypeScript code for translations to be added to the dictionary.
|
|
337
|
-
*/
|
|
338
|
-
export declare function generateTranslationCode(lang: NiceSupportedLang, translations: TranslationResult[]): string;
|
|
339
|
-
|
|
340
326
|
/**
|
|
341
327
|
* Get all available timezones with their info.
|
|
342
328
|
*/
|
|
343
329
|
export declare function getAllTimezones(lang?: NiceSupportedLang, referenceDate?: Date): TimezoneInfo[];
|
|
344
330
|
|
|
345
|
-
/**
|
|
346
|
-
* Get translation statistics for all languages.
|
|
347
|
-
*/
|
|
348
|
-
export declare function getAllTranslationStats(): TranslationStats[];
|
|
349
|
-
|
|
350
331
|
/**
|
|
351
332
|
* Get all available calendar systems.
|
|
352
333
|
*/
|
|
@@ -377,14 +358,6 @@ export declare function getCurrentCalendarDate(calendar: CalendarSystem, lang?:
|
|
|
377
358
|
*/
|
|
378
359
|
export declare function getDocumentDirection(): 'ltr' | 'rtl';
|
|
379
360
|
|
|
380
|
-
/**
|
|
381
|
-
* Get all glossary entries for a specific language.
|
|
382
|
-
*/
|
|
383
|
-
export declare function getGlossaryForLanguage(lang: NiceSupportedLang): Array<{
|
|
384
|
-
en: string;
|
|
385
|
-
translation: string;
|
|
386
|
-
}>;
|
|
387
|
-
|
|
388
361
|
/**
|
|
389
362
|
* Get number of days in a Hijri month.
|
|
390
363
|
*/
|
|
@@ -414,11 +387,6 @@ export declare function getLocaleTag(lang: NiceSupportedLang): string;
|
|
|
414
387
|
*/
|
|
415
388
|
export declare function getLogicalProperty(physical: string): string;
|
|
416
389
|
|
|
417
|
-
/**
|
|
418
|
-
* Find missing translations for a specific language.
|
|
419
|
-
*/
|
|
420
|
-
export declare function getMissingTranslations(lang: NiceSupportedLang): MissingTranslation[];
|
|
421
|
-
|
|
422
390
|
/**
|
|
423
391
|
* Get the next DST transition date for a timezone.
|
|
424
392
|
*/
|
|
@@ -451,11 +419,6 @@ export declare function getRecommendedCalendars(lang: NiceSupportedLang): Calend
|
|
|
451
419
|
*/
|
|
452
420
|
export declare function getRTLCSSVars(isRTL: boolean): Record<string, string>;
|
|
453
421
|
|
|
454
|
-
/**
|
|
455
|
-
* Get all keys from the English dictionary (source of truth).
|
|
456
|
-
*/
|
|
457
|
-
export declare function getSourceKeys(): string[];
|
|
458
|
-
|
|
459
422
|
/**
|
|
460
423
|
* Get text direction for a language.
|
|
461
424
|
*/
|
|
@@ -471,17 +434,6 @@ export declare function getTimezoneInfo(timezone: string, lang?: NiceSupportedLa
|
|
|
471
434
|
*/
|
|
472
435
|
export declare function getTimezonesGrouped(lang?: NiceSupportedLang, referenceDate?: Date): Record<string, TimezoneInfo[]>;
|
|
473
436
|
|
|
474
|
-
/**
|
|
475
|
-
* Get translation statistics for a language.
|
|
476
|
-
*/
|
|
477
|
-
export declare function getTranslationStats(lang: NiceSupportedLang): TranslationStats;
|
|
478
|
-
|
|
479
|
-
export declare interface GlossaryEntry {
|
|
480
|
-
en: string;
|
|
481
|
-
translations: Partial<Record<NiceSupportedLang, string>>;
|
|
482
|
-
context?: string;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
437
|
/**
|
|
486
438
|
* Hebrew month names.
|
|
487
439
|
*/
|
|
@@ -613,37 +565,17 @@ export declare interface LoaderState {
|
|
|
613
565
|
* root.render(<NiceI18nLazyProvider lang="pl"><App /></NiceI18nLazyProvider>);
|
|
614
566
|
* ```
|
|
615
567
|
*
|
|
616
|
-
* An unknown code loads English
|
|
568
|
+
* An unknown code loads English.
|
|
617
569
|
*/
|
|
618
570
|
export declare function loadNiceDictionary(lang: NiceSupportedLang): Promise<NiceDictionary>;
|
|
619
571
|
|
|
620
572
|
/**
|
|
621
|
-
*
|
|
622
|
-
* Returns the approved translation or undefined.
|
|
623
|
-
*/
|
|
624
|
-
export declare function lookupGlossary(englishTerm: string, lang: NiceSupportedLang): string | undefined;
|
|
625
|
-
|
|
626
|
-
export declare interface MissingTranslation {
|
|
627
|
-
key: string;
|
|
628
|
-
englishValue: string;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
export declare const NICE_GLOSSARY: GlossaryEntry[];
|
|
632
|
-
|
|
633
|
-
export declare const NICE_I18N_DICTIONARIES: Record<NiceSupportedLang, Record<string, string>>;
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Locale-and-register variants. Built on top of the base pl dictionary;
|
|
637
|
-
* unspecified keys fall back to NICE_I18N_DICTIONARIES.pl.
|
|
638
|
-
*/
|
|
639
|
-
export declare const NICE_I18N_VARIANTS: Partial<Record<string, Partial<Record<NiceI18nVariant, Record<string, string>>>>>;
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* The languages with a built-in dictionary.
|
|
573
|
+
* The languages with a built-in dictionary, and the two helpers that only need the list.
|
|
643
574
|
*
|
|
644
575
|
* Its own module, free of dictionary imports: the context, `useNiceTranslation` and the
|
|
645
|
-
*
|
|
646
|
-
* `
|
|
576
|
+
* provider need the list but must not pull thirty dictionaries in with it. Until 1.1.x
|
|
577
|
+
* `isSupported` and `detectBrowserLanguage` sat next to the eager provider, in a module that
|
|
578
|
+
* imported all of them.
|
|
647
579
|
*/
|
|
648
580
|
export declare const NICE_SUPPORTED_LANGS: readonly ["en", "pl", "de", "fr", "es", "it", "pt", "nl", "sv", "no", "da", "fi", "cs", "sk", "hu", "ro", "bg", "uk", "ja", "ko", "zh", "ar", "hi", "bn", "th", "vi", "id", "sw", "fil", "ms"];
|
|
649
581
|
|
|
@@ -660,50 +592,29 @@ export declare interface NiceDateFormatter {
|
|
|
660
592
|
declare type NiceDictionary = Record<string, string>;
|
|
661
593
|
|
|
662
594
|
/**
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* <NiceI18nLazyProvider lang="pl">
|
|
668
|
-
* <App />
|
|
669
|
-
* </NiceI18nLazyProvider>
|
|
595
|
+
* {@link NiceI18nProvider} under its 1.1.10 name — the same component, so code written for
|
|
596
|
+
* 1.1.10 needs no change.
|
|
670
597
|
*/
|
|
671
|
-
export declare const NiceI18nLazyProvider: default_2.FC<
|
|
598
|
+
export declare const NiceI18nLazyProvider: default_2.FC<NiceI18nProviderProps>;
|
|
672
599
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
* Custom translation function — takes priority over `lang` and nothing is loaded, as with
|
|
676
|
-
* `NiceI18nProvider`. Lets this provider replace that one everywhere, so nothing in an app
|
|
677
|
-
* has to reach for the module that holds all thirty dictionaries.
|
|
678
|
-
*/
|
|
679
|
-
t?: NiceTranslateFn;
|
|
680
|
-
/** Built-in language code; its dictionary is loaded on first use. Default `'en'`. */
|
|
681
|
-
lang?: NiceSupportedLang;
|
|
682
|
-
/** Extra translations merged on top of the loaded dictionary. */
|
|
683
|
-
overrides?: Record<string, string>;
|
|
684
|
-
/**
|
|
685
|
-
* Rendered instead of `children` until the first dictionary has loaded. Leave it out to
|
|
686
|
-
* render the children straight away, in the controls' built-in English. On a language
|
|
687
|
-
* switch the previous language stays on screen until the new one arrives.
|
|
688
|
-
*/
|
|
689
|
-
fallback?: default_2.ReactNode;
|
|
690
|
-
/** Called when a dictionary fails to load; the controls keep their current language. */
|
|
691
|
-
onError?: (error: unknown) => void;
|
|
692
|
-
children: default_2.ReactNode;
|
|
693
|
-
}
|
|
600
|
+
/** The props of {@link NiceI18nLazyProvider} — the same as {@link NiceI18nProviderProps}. */
|
|
601
|
+
export declare type NiceI18nLazyProviderProps = NiceI18nProviderProps;
|
|
694
602
|
|
|
695
603
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
604
|
+
* Puts a translator in context for every Nice control below it: your own translation function
|
|
605
|
+
* (e.g. from react-i18next), or the built-in dictionary of `lang`, loaded on first use.
|
|
698
606
|
*
|
|
699
607
|
* @example
|
|
700
|
-
* //
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
608
|
+
* // Built-in dictionaries (30 languages); start in Polish rather than in English:
|
|
609
|
+
* await loadNiceDictionary('pl');
|
|
610
|
+
* root.render(
|
|
611
|
+
* <NiceI18nProvider lang="pl">
|
|
612
|
+
* <MyApp />
|
|
613
|
+
* </NiceI18nProvider>,
|
|
614
|
+
* );
|
|
704
615
|
*
|
|
705
616
|
* @example
|
|
706
|
-
* //
|
|
617
|
+
* // Custom translation function (e.g. react-i18next) — nothing is loaded:
|
|
707
618
|
* import { useTranslation } from 'react-i18next';
|
|
708
619
|
* function App() {
|
|
709
620
|
* const { t } = useTranslation();
|
|
@@ -715,23 +626,32 @@ export declare interface NiceI18nLazyProviderProps {
|
|
|
715
626
|
* }
|
|
716
627
|
*
|
|
717
628
|
* @example
|
|
718
|
-
* //
|
|
629
|
+
* // No provider: the controls' built-in English.
|
|
719
630
|
* <NiceButton>Click me</NiceButton>
|
|
720
631
|
*/
|
|
721
632
|
export declare const NiceI18nProvider: default_2.FC<NiceI18nProviderProps>;
|
|
722
633
|
|
|
723
634
|
export declare interface NiceI18nProviderProps {
|
|
724
|
-
/**
|
|
635
|
+
/**
|
|
636
|
+
* Custom translation function (e.g. from react-i18next) — takes priority over `lang`, and
|
|
637
|
+
* no dictionary is loaded.
|
|
638
|
+
*/
|
|
725
639
|
t?: NiceTranslateFn;
|
|
726
|
-
/** Built-in language code
|
|
640
|
+
/** Built-in language code; its dictionary is loaded on first use. Default `'en'`. */
|
|
727
641
|
lang?: NiceSupportedLang;
|
|
728
|
-
/** Extra translations
|
|
642
|
+
/** Extra translations merged on top of the loaded dictionary. */
|
|
729
643
|
overrides?: Record<string, string>;
|
|
644
|
+
/**
|
|
645
|
+
* Rendered instead of `children` until the first dictionary has loaded. Leave it out to
|
|
646
|
+
* render the children straight away, in the controls' built-in English. On a language
|
|
647
|
+
* switch the previous language stays on screen until the new one arrives.
|
|
648
|
+
*/
|
|
649
|
+
fallback?: default_2.ReactNode;
|
|
650
|
+
/** Called when a dictionary fails to load; the controls keep their current language. */
|
|
651
|
+
onError?: (error: unknown) => void;
|
|
730
652
|
children: default_2.ReactNode;
|
|
731
653
|
}
|
|
732
654
|
|
|
733
|
-
export declare type NiceI18nVariant = 'formal' | 'informal';
|
|
734
|
-
|
|
735
655
|
export declare interface NiceNumberFormatter {
|
|
736
656
|
format: (value: number) => string;
|
|
737
657
|
formatCompact: (value: number) => string;
|
|
@@ -885,14 +805,6 @@ export declare function pseudoLocalize(text: string, options?: PseudoLocalizatio
|
|
|
885
805
|
*/
|
|
886
806
|
export declare function pseudoLocalizeDictionary(dictionary: Record<string, string>, options?: PseudoLocalizationOptions): Record<string, string>;
|
|
887
807
|
|
|
888
|
-
/**
|
|
889
|
-
* Resolve a register-aware dictionary by locale + variant.
|
|
890
|
-
*
|
|
891
|
-
* Reads `pl` from its own module rather than through the aggregate, so this
|
|
892
|
-
* function pulls one language instead of all thirty.
|
|
893
|
-
*/
|
|
894
|
-
export declare function resolvePlVariant(variant: NiceI18nVariant): Record<string, string>;
|
|
895
|
-
|
|
896
808
|
/**
|
|
897
809
|
* CSS custom properties for RTL-aware components.
|
|
898
810
|
* Use these as fallbacks in CSS-in-JS or CSS modules.
|
|
@@ -1029,20 +941,6 @@ export declare type TranslationDictionary = Record<string, string>;
|
|
|
1029
941
|
|
|
1030
942
|
export declare type TranslationNamespace = Record<string, TranslationDictionary>;
|
|
1031
943
|
|
|
1032
|
-
export declare interface TranslationResult {
|
|
1033
|
-
key: string;
|
|
1034
|
-
original: string;
|
|
1035
|
-
translated: string;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
export declare interface TranslationStats {
|
|
1039
|
-
lang: NiceSupportedLang;
|
|
1040
|
-
totalKeys: number;
|
|
1041
|
-
translatedKeys: number;
|
|
1042
|
-
missingKeys: number;
|
|
1043
|
-
coverage: number;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
944
|
/**
|
|
1047
945
|
* React hook for calendar formatting.
|
|
1048
946
|
*/
|
|
@@ -1136,14 +1034,4 @@ export declare function useTimezone(lang: NiceSupportedLang, timezone?: string,
|
|
|
1136
1034
|
fromUTC: (date: Date) => Date;
|
|
1137
1035
|
};
|
|
1138
1036
|
|
|
1139
|
-
/**
|
|
1140
|
-
* Validate translations against the glossary.
|
|
1141
|
-
* Returns entries where the translation doesn't match the glossary.
|
|
1142
|
-
*/
|
|
1143
|
-
export declare function validateAgainstGlossary(lang: NiceSupportedLang): Array<{
|
|
1144
|
-
key: string;
|
|
1145
|
-
currentTranslation: string;
|
|
1146
|
-
glossaryTranslation: string;
|
|
1147
|
-
}>;
|
|
1148
|
-
|
|
1149
1037
|
export { }
|