mapa-frontend-i18n 1.3.4 → 2.0.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 +264 -0
- package/fesm2022/mapa-frontend-i18n.mjs +247 -5
- package/fesm2022/mapa-frontend-i18n.mjs.map +1 -1
- package/index.d.ts +78 -2
- package/mapa-frontend-i18n-2.0.0.tgz +0 -0
- package/package.json +1 -1
- package/mapa-frontend-i18n-1.3.4.tgz +0 -0
package/index.d.ts
CHANGED
|
@@ -36,6 +36,56 @@ declare const MP_TRANSLATIONS: Record<AppLanguage, Record<string, string>>;
|
|
|
36
36
|
|
|
37
37
|
declare const MV_TRANSLATIONS: Record<AppLanguage, Record<string, string>>;
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Flat map of `$localize` message id -> translated text, the shape expected by
|
|
41
|
+
* `@angular/localize`'s `loadTranslations()` and the shape served per language
|
|
42
|
+
* from the remote (AWS) JSON files.
|
|
43
|
+
*/
|
|
44
|
+
type FlatTranslations = Record<string, string>;
|
|
45
|
+
interface RemoteTranslationOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Base URL where the per-language JSON files live (without trailing slash or
|
|
48
|
+
* file name). Each language is fetched from `${baseUrl}/${language}.json`,
|
|
49
|
+
* e.g. `https://cdn.example.com/i18n` -> `https://cdn.example.com/i18n/pt-BR.json`.
|
|
50
|
+
*/
|
|
51
|
+
baseUrl: string;
|
|
52
|
+
/**
|
|
53
|
+
* Optional version/build tag appended as `?v=` for manual cache-busting
|
|
54
|
+
* (requires the CDN to vary its cache key by query string).
|
|
55
|
+
*/
|
|
56
|
+
version?: string;
|
|
57
|
+
/** Abort the request after this many milliseconds. Defaults to 5000. */
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
/** Custom fetch implementation (tests / SSR). Defaults to the global `fetch`. */
|
|
60
|
+
fetchImpl?: typeof fetch;
|
|
61
|
+
/** Invoked when a fetch/parse error happens. Non-fatal: a fallback is used. */
|
|
62
|
+
onError?: (error: unknown) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Reads the cached translations for a language from localStorage. Returns
|
|
66
|
+
* `null` when there is no cache, it is unreadable, or its shape is invalid.
|
|
67
|
+
* Safe to call during SSR (returns `null` when localStorage is unavailable).
|
|
68
|
+
*/
|
|
69
|
+
declare function readCachedTranslations(language: AppLanguage): {
|
|
70
|
+
version: string | null;
|
|
71
|
+
data: FlatTranslations;
|
|
72
|
+
} | null;
|
|
73
|
+
/**
|
|
74
|
+
* Fetches the remote translations for a language, updating the localStorage
|
|
75
|
+
* cache.
|
|
76
|
+
*
|
|
77
|
+
* Uses a plain GET (no custom request headers) on purpose: this keeps it a
|
|
78
|
+
* "simple" CORS request, so the only server requirement is an
|
|
79
|
+
* `Access-Control-Allow-Origin` header — no OPTIONS preflight. Freshness is
|
|
80
|
+
* delegated to the HTTP layer via `cache: "no-cache"`, which makes the browser
|
|
81
|
+
* revalidate against the CDN's `ETag`/`Last-Modified` transparently (a 304 is
|
|
82
|
+
* resolved by the browser and surfaces here as a normal 200).
|
|
83
|
+
*
|
|
84
|
+
* Resolution order on failure: cached data (if any), otherwise `null` so the
|
|
85
|
+
* caller can fall back to the embedded catalogs. Never throws.
|
|
86
|
+
*/
|
|
87
|
+
declare function loadRemoteTranslations(language: AppLanguage, options: RemoteTranslationOptions): Promise<FlatTranslations | null>;
|
|
88
|
+
|
|
39
89
|
declare function getStoredAppLanguage(): AppLanguage;
|
|
40
90
|
declare function persistAppLanguage(language: AppLanguage): void;
|
|
41
91
|
declare function getAngularLocale(language: AppLanguage): string;
|
|
@@ -45,6 +95,32 @@ interface InitializeAppLanguageOptions {
|
|
|
45
95
|
clearExistingTranslations?: boolean;
|
|
46
96
|
}
|
|
47
97
|
declare function initializeAppLanguage(options?: InitializeAppLanguageOptions): AppLanguage;
|
|
98
|
+
interface InitializeAppLanguageAsyncOptions extends RemoteTranslationOptions {
|
|
99
|
+
clearExistingTranslations?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Initializes translations by loading them from the remote (AWS) JSON files,
|
|
103
|
+
* with the embedded catalogs as a fallback. MUST be awaited before the host
|
|
104
|
+
* application bootstraps, because `$localize` resolves messages at evaluation
|
|
105
|
+
* time from the global map populated here.
|
|
106
|
+
*
|
|
107
|
+
* Behaviour:
|
|
108
|
+
* - With a local cache: applies the cached copy immediately (instant boot) and
|
|
109
|
+
* revalidates in the background; an updated copy takes effect on the next reload.
|
|
110
|
+
* - Without a cache: awaits the remote fetch and, on any failure, falls back to
|
|
111
|
+
* the embedded catalogs (never the raw keys).
|
|
112
|
+
*/
|
|
113
|
+
declare function initializeAppLanguageAsync(options: InitializeAppLanguageAsyncOptions): Promise<AppLanguage>;
|
|
114
|
+
interface InitializeAppLanguageFromDataOptions {
|
|
115
|
+
clearExistingTranslations?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Initializes translations from data the caller already fetched. Intended for
|
|
119
|
+
* micro-frontend setups where a host fetches the remote translations once and
|
|
120
|
+
* shares them with each MFE, avoiding one network request per MFE. The data is
|
|
121
|
+
* merged over the embedded fallback, like {@link initializeAppLanguageAsync}.
|
|
122
|
+
*/
|
|
123
|
+
declare function initializeAppLanguageFromData(language: AppLanguage, remote: FlatTranslations, options?: InitializeAppLanguageFromDataOptions): AppLanguage;
|
|
48
124
|
|
|
49
125
|
interface ValidationContext {
|
|
50
126
|
actualLength?: number;
|
|
@@ -183,5 +259,5 @@ declare const MAPA_UI_TEXTS_PT_BR: {
|
|
|
183
259
|
};
|
|
184
260
|
declare function getMapaUiTexts(language: AppLanguage): PartialMapaUiTexts;
|
|
185
261
|
|
|
186
|
-
export { ANGULAR_RUNTIME_TRANSLATIONS, APP_LANGUAGE_OPTIONS, APP_LANGUAGE_STORAGE_KEY, DEFAULT_APP_LANGUAGE, MAPA_UI_TEXTS_PT_BR, MA_TRANSLATIONS, MCA_TRANSLATIONS, MENU_TRANSLATIONS, MF_TRANSLATIONS, MGA_TRANSLATIONS, MGC_TRANSLATIONS, MO_TRANSLATIONS, MP_TRANSLATIONS, MV_TRANSLATIONS, applyDocumentLanguage, applyPaginatorIntl, formatPaginatorRange, formatPaginatorShowingRange, getAngularLocale, getAppLanguageOption, getIntlLocale, getMapaUiTexts, getPaginatorNavigationLabels, getStoredAppLanguage, initializeAppLanguage, isAppLanguage, persistAppLanguage, resolveAppLanguage };
|
|
187
|
-
export type { AppLanguage, AppLanguageOption, InitializeAppLanguageOptions, MapaUiTextGroups, PartialMapaUiTexts, ValidationContext, ValidationTextResolver };
|
|
262
|
+
export { ANGULAR_RUNTIME_TRANSLATIONS, APP_LANGUAGE_OPTIONS, APP_LANGUAGE_STORAGE_KEY, DEFAULT_APP_LANGUAGE, MAPA_UI_TEXTS_PT_BR, MA_TRANSLATIONS, MCA_TRANSLATIONS, MENU_TRANSLATIONS, MF_TRANSLATIONS, MGA_TRANSLATIONS, MGC_TRANSLATIONS, MO_TRANSLATIONS, MP_TRANSLATIONS, MV_TRANSLATIONS, applyDocumentLanguage, applyPaginatorIntl, formatPaginatorRange, formatPaginatorShowingRange, getAngularLocale, getAppLanguageOption, getIntlLocale, getMapaUiTexts, getPaginatorNavigationLabels, getStoredAppLanguage, initializeAppLanguage, initializeAppLanguageAsync, initializeAppLanguageFromData, isAppLanguage, loadRemoteTranslations, persistAppLanguage, readCachedTranslations, resolveAppLanguage };
|
|
263
|
+
export type { AppLanguage, AppLanguageOption, FlatTranslations, InitializeAppLanguageAsyncOptions, InitializeAppLanguageFromDataOptions, InitializeAppLanguageOptions, MapaUiTextGroups, PartialMapaUiTexts, RemoteTranslationOptions, ValidationContext, ValidationTextResolver };
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|