@rxap/ngx-localize 19.1.0 → 19.1.1-dev.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/CHANGELOG.md +4 -0
- package/compodoc/changelog.html +2 -0
- package/compodoc/dependencies.html +2 -4
- package/compodoc/js/menu-wc.js +3 -0
- package/compodoc/js/menu-wc_es5.js +1 -1
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/miscellaneous/functions.html +53 -307
- package/compodoc/miscellaneous/typealiases.html +235 -0
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +616 -246
- package/docs/html/assets/hierarchy.js +1 -1
- package/docs/html/assets/navigation.js +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/I18nService.html +3 -3
- package/docs/html/classes/LanguageSelectorService.html +4 -4
- package/docs/html/functions/LanguageInterceptor.html +2 -2
- package/docs/html/functions/defaultLoadModule.html +4 -0
- package/docs/html/functions/loadI18nBootstrapHook.html +1 -4
- package/docs/html/functions/loadLanguages.html +4 -3
- package/docs/html/index.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/html/types/FetchTranslationsFunction.html +1 -0
- package/docs/html/types/LoadModuleFunction.html +1 -0
- package/docs/markdown/README.md +1 -1
- package/docs/markdown/classes/I18nService.md +5 -5
- package/docs/markdown/classes/LanguageSelectorService.md +7 -7
- package/docs/markdown/functions/LanguageInterceptor.md +2 -2
- package/docs/markdown/functions/defaultLoadModule.md +27 -0
- package/docs/markdown/functions/loadI18nBootstrapHook.md +21 -11
- package/docs/markdown/functions/loadLanguages.md +10 -4
- package/docs/markdown/globals.md +8 -3
- package/docs/markdown/type-aliases/FetchTranslationsFunction.md +29 -0
- package/docs/markdown/type-aliases/LoadModuleFunction.md +21 -0
- package/docs/wiki/Class.I18nService.md +4 -4
- package/docs/wiki/Class.LanguageSelectorService.md +6 -6
- package/docs/wiki/Function.LanguageInterceptor.md +1 -1
- package/docs/wiki/Function.defaultLoadModule.md +23 -0
- package/docs/wiki/Function.loadI18nBootstrapHook.md +20 -10
- package/docs/wiki/Function.loadLanguages.md +9 -3
- package/docs/wiki/TypeAlias.FetchTranslationsFunction.md +25 -0
- package/docs/wiki/TypeAlias.LoadModuleFunction.md +17 -0
- package/docs/wiki/_Sidebar.md +6 -1
- package/docs/wiki/globals.md +7 -2
- package/fesm2022/rxap-ngx-localize.mjs +19 -131
- package/fesm2022/rxap-ngx-localize.mjs.map +1 -1
- package/index.d.ts +0 -1
- package/lib/load-i18n-bootstrap-hook.d.ts +2 -7
- package/lib/load-languages.d.ts +14 -1
- package/package.json +19 -20
- package/docs/html/functions/xliffToJson.html +0 -4
- package/docs/markdown/functions/xliffToJson.md +0 -27
- package/docs/wiki/Function.xliffToJson.md +0 -23
- package/lib/xliff-to-json.d.ts +0 -7
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
> **LanguageInterceptor**(`request`, `next`): `Observable`\<`HttpEvent`\<`unknown`\>\>
|
|
6
6
|
|
|
7
|
-
Defined in: [language-interceptor.ts:15](https://gitlab.com/rxap/packages/-/blob/
|
|
7
|
+
Defined in: [language-interceptor.ts:15](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/language-interceptor.ts#L15)
|
|
8
8
|
|
|
9
9
|
Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.
|
|
10
10
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[@rxap/ngx-localize](../wiki/globals) / defaultLoadModule
|
|
2
|
+
|
|
3
|
+
# Function: defaultLoadModule()
|
|
4
|
+
|
|
5
|
+
> **defaultLoadModule**(`locale`): `Promise`\<`void`\>
|
|
6
|
+
|
|
7
|
+
Defined in: [load-languages.ts:10](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/load-languages.ts#L10)
|
|
8
|
+
|
|
9
|
+
Loads the locale data module for the specified locale and registers it.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
### locale
|
|
14
|
+
|
|
15
|
+
`string`
|
|
16
|
+
|
|
17
|
+
The locale identifier for which the module needs to be loaded.
|
|
18
|
+
|
|
19
|
+
## Returns
|
|
20
|
+
|
|
21
|
+
`Promise`\<`void`\>
|
|
22
|
+
|
|
23
|
+
A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.
|
|
@@ -2,22 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
# Function: loadI18nBootstrapHook()
|
|
4
4
|
|
|
5
|
-
> **loadI18nBootstrapHook**(`
|
|
5
|
+
> **loadI18nBootstrapHook**(`fetchTranslations`, `loadModule`, `locale`?, `preferredLanguages`?, `fallback`?): `Promise`\<(`options`) => `Promise`\<`void`\>\>
|
|
6
6
|
|
|
7
|
-
Defined in: [load-i18n-bootstrap-hook.ts:
|
|
8
|
-
|
|
9
|
-
Loads internationalization (i18n) bootstrap settings for the application.
|
|
7
|
+
Defined in: [load-i18n-bootstrap-hook.ts:12](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/load-i18n-bootstrap-hook.ts#L12)
|
|
10
8
|
|
|
11
9
|
## Parameters
|
|
12
10
|
|
|
13
|
-
###
|
|
11
|
+
### fetchTranslations
|
|
14
12
|
|
|
15
|
-
`
|
|
13
|
+
[`FetchTranslationsFunction`](../wiki/TypeAlias.FetchTranslationsFunction)
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
### loadModule
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
[`LoadModuleFunction`](../wiki/TypeAlias.LoadModuleFunction) = `defaultLoadModule`
|
|
18
|
+
|
|
19
|
+
### locale?
|
|
20
|
+
|
|
21
|
+
`string`
|
|
22
|
+
|
|
23
|
+
### preferredLanguages?
|
|
20
24
|
|
|
21
|
-
`
|
|
25
|
+
`string`[]
|
|
26
|
+
|
|
27
|
+
### fallback?
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
## Returns
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
`Promise`\<(`options`) => `Promise`\<`void`\>\>
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Function: loadLanguages()
|
|
4
4
|
|
|
5
|
-
> **loadLanguages**(`loadModule`, `locale`?, `preferredLanguages`?, `fallback`?): `Promise`\<`string`\>
|
|
5
|
+
> **loadLanguages**(`fetchTranslations`, `loadModule`, `locale`?, `preferredLanguages`?, `fallback`?): `Promise`\<`string`\>
|
|
6
6
|
|
|
7
|
-
Defined in: [load-languages.ts:
|
|
7
|
+
Defined in: [load-languages.ts:47](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/load-languages.ts#L47)
|
|
8
8
|
|
|
9
9
|
Loads language translations and sets the locale for the application.
|
|
10
10
|
This function fetches the translations based on the specified locale, preferred languages,
|
|
@@ -12,9 +12,15 @@ and a fallback, then initializes the translations and optionally loads additiona
|
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
14
14
|
|
|
15
|
+
### fetchTranslations
|
|
16
|
+
|
|
17
|
+
[`FetchTranslationsFunction`](../wiki/TypeAlias.FetchTranslationsFunction)
|
|
18
|
+
|
|
19
|
+
A function to fetch the translation json map
|
|
20
|
+
|
|
15
21
|
### loadModule
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
[`LoadModuleFunction`](../wiki/TypeAlias.LoadModuleFunction) = `defaultLoadModule`
|
|
18
24
|
|
|
19
25
|
A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
20
26
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[@rxap/ngx-localize](../wiki/globals) / FetchTranslationsFunction
|
|
2
|
+
|
|
3
|
+
# Type Alias: FetchTranslationsFunction()
|
|
4
|
+
|
|
5
|
+
> **FetchTranslationsFunction**: (`locale`, `preferredLanguages`, `fallback`) => `Promise`\<\{ `json`: `any`; `locale`: `string`; \} \| `null`\>
|
|
6
|
+
|
|
7
|
+
Defined in: [load-languages.ts:31](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/load-languages.ts#L31)
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### locale
|
|
12
|
+
|
|
13
|
+
`string`
|
|
14
|
+
|
|
15
|
+
### preferredLanguages
|
|
16
|
+
|
|
17
|
+
`string`[]
|
|
18
|
+
|
|
19
|
+
### fallback
|
|
20
|
+
|
|
21
|
+
`string`
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`Promise`\<\{ `json`: `any`; `locale`: `string`; \} \| `null`\>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[@rxap/ngx-localize](../wiki/globals) / LoadModuleFunction
|
|
2
|
+
|
|
3
|
+
# Type Alias: LoadModuleFunction()
|
|
4
|
+
|
|
5
|
+
> **LoadModuleFunction**: (`locale`) => `Promise`\<`void`\>
|
|
6
|
+
|
|
7
|
+
Defined in: [load-languages.ts:33](https://gitlab.com/rxap/packages/-/blob/edbe45ecb6840997e71b8878ac67c3490fbe1a98/packages/angular/localize/src/lib/load-languages.ts#L33)
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### locale
|
|
12
|
+
|
|
13
|
+
`string`
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`Promise`\<`void`\>
|
package/docs/wiki/_Sidebar.md
CHANGED
|
@@ -5,9 +5,14 @@
|
|
|
5
5
|
- [I18nService](../wiki/Class.I18nService)
|
|
6
6
|
- [LanguageSelectorService](../wiki/Class.LanguageSelectorService)
|
|
7
7
|
|
|
8
|
+
### Type Aliases
|
|
9
|
+
|
|
10
|
+
- [FetchTranslationsFunction](../wiki/TypeAlias.FetchTranslationsFunction)
|
|
11
|
+
- [LoadModuleFunction](../wiki/TypeAlias.LoadModuleFunction)
|
|
12
|
+
|
|
8
13
|
### Functions
|
|
9
14
|
|
|
15
|
+
- [defaultLoadModule](../wiki/Function.defaultLoadModule)
|
|
10
16
|
- [LanguageInterceptor](../wiki/Function.LanguageInterceptor)
|
|
11
17
|
- [loadI18nBootstrapHook](../wiki/Function.loadI18nBootstrapHook)
|
|
12
18
|
- [loadLanguages](../wiki/Function.loadLanguages)
|
|
13
|
-
- [xliffToJson](../wiki/Function.xliffToJson)
|
package/docs/wiki/globals.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
# @rxap/ngx-localize v19.1.0
|
|
1
|
+
# @rxap/ngx-localize v19.1.1-dev.0
|
|
2
2
|
|
|
3
3
|
## Classes
|
|
4
4
|
|
|
5
5
|
- [~~I18nService~~](../wiki/Class.I18nService)
|
|
6
6
|
- [LanguageSelectorService](../wiki/Class.LanguageSelectorService)
|
|
7
7
|
|
|
8
|
+
## Type Aliases
|
|
9
|
+
|
|
10
|
+
- [FetchTranslationsFunction](../wiki/TypeAlias.FetchTranslationsFunction)
|
|
11
|
+
- [LoadModuleFunction](../wiki/TypeAlias.LoadModuleFunction)
|
|
12
|
+
|
|
8
13
|
## Functions
|
|
9
14
|
|
|
15
|
+
- [defaultLoadModule](../wiki/Function.defaultLoadModule)
|
|
10
16
|
- [LanguageInterceptor](../wiki/Function.LanguageInterceptor)
|
|
11
17
|
- [loadI18nBootstrapHook](../wiki/Function.loadI18nBootstrapHook)
|
|
12
18
|
- [loadLanguages](../wiki/Function.loadLanguages)
|
|
13
|
-
- [xliffToJson](../wiki/Function.xliffToJson)
|
|
@@ -4,7 +4,6 @@ import { UserSettingsLanguageService } from '@rxap/ngx-user';
|
|
|
4
4
|
import { ConfigService } from '@rxap/config';
|
|
5
5
|
import { registerLocaleData } from '@angular/common';
|
|
6
6
|
import { loadTranslations } from '@angular/localize';
|
|
7
|
-
import { xliff2js } from 'xliff/esm';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @deprecated removed
|
|
@@ -99,111 +98,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
|
|
|
99
98
|
args: [{ providedIn: 'root' }]
|
|
100
99
|
}] });
|
|
101
100
|
|
|
102
|
-
// @ts-expect-error type definition do not exists
|
|
103
|
-
/**
|
|
104
|
-
* Converts an XLIFF translation string into a JSON object with translation keys and their corresponding values.
|
|
105
|
-
*
|
|
106
|
-
* @param {string} translations - A string in XLIFF format containing translations to be parsed and transformed.
|
|
107
|
-
* @return {Promise<Object>} A promise that resolves to an object where keys are translation identifiers and values are the corresponding translations in plain text or templated string format.
|
|
108
|
-
*/
|
|
109
|
-
async function xliffToJson(translations) {
|
|
110
|
-
const parserResult = await xliff2js(translations);
|
|
111
|
-
const xliffContent = parserResult.resources["ngi18n"];
|
|
112
|
-
return Object.keys(xliffContent).reduce((result, current) => {
|
|
113
|
-
const translation = xliffContent[current].target;
|
|
114
|
-
if (typeof translation === "string") {
|
|
115
|
-
result[current] = translation;
|
|
116
|
-
}
|
|
117
|
-
else if (Array.isArray(translation)) {
|
|
118
|
-
result[current] = translation
|
|
119
|
-
.map((entry) => typeof entry === "string" ? entry : `{{${entry.Standalone.id}}}`)
|
|
120
|
-
.join("");
|
|
121
|
-
}
|
|
122
|
-
else if (typeof translation === "object" && 'Standalone' in translation && translation.Standalone.id !== '') {
|
|
123
|
-
result[current] = `{{${translation.Standalone.id}}}`;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
console.warn(`Could not parse XLIFF: (${current}) ${JSON.stringify(xliffContent[current])}`);
|
|
127
|
-
return result;
|
|
128
|
-
}
|
|
129
|
-
result[current] = result[current].replace("{{", "{$").replace("}}", "}");
|
|
130
|
-
return result;
|
|
131
|
-
}, {});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function isTranslationXml(xml) {
|
|
135
|
-
return !!xml && typeof xml === 'string' && xml.startsWith('<?xml') && xml.includes('<xliff');
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Fetches the translation file for the specified locale in XLIFF format.
|
|
139
|
-
*
|
|
140
|
-
* @param {string} locale - The locale identifier for which the translation file should be fetched.
|
|
141
|
-
* @return {Promise<string | null>} A promise that resolves to the XLIFF translation file as a string
|
|
142
|
-
* if successfully fetched and valid, or null if the file is invalid or could not be fetched.
|
|
143
|
-
*/
|
|
144
|
-
async function fetchTranslation(locale) {
|
|
145
|
-
let xml;
|
|
146
|
-
try {
|
|
147
|
-
xml = await fetch(`/i18n/${locale}.xlf`).then((r) => r.text());
|
|
148
|
-
if (!isTranslationXml(xml)) {
|
|
149
|
-
console.error(`Invalid XLIFF file for locale ${locale}`);
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
return xml;
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
console.warn(`Could not download XLIFF file for locale ${locale}: ${e.message}`);
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Fetches translations for a specified locale, attempts to use preferred languages or a fallback if necessary.
|
|
161
|
-
* The function retrieves and parses translation data from XLIFF files.
|
|
162
|
-
*
|
|
163
|
-
* @param {string} locale - The primary locale for which to fetch translations.
|
|
164
|
-
* @param {string[]} preferredLanguages - An array of preferred fallback locales to try if the primary locale fails.
|
|
165
|
-
* @param {string} fallback - The fallback locale to be used if both the primary and preferred locales fail.
|
|
166
|
-
* @return {Promise<{ json: any, locale: string } | null>} A promise resolving to an object containing the parsed translation data (json) and the effective locale, or null if loading fails.
|
|
167
|
-
*/
|
|
168
|
-
async function fetchTranslations(locale, preferredLanguages, fallback) {
|
|
169
|
-
let xml = null;
|
|
170
|
-
let currentLocale = locale;
|
|
171
|
-
do {
|
|
172
|
-
xml = await fetchTranslation(currentLocale);
|
|
173
|
-
if (!xml) {
|
|
174
|
-
currentLocale = preferredLanguages.shift();
|
|
175
|
-
}
|
|
176
|
-
} while (!xml && currentLocale);
|
|
177
|
-
if (!xml) {
|
|
178
|
-
console.error(`Could not download XLIFF file for locale ${locale} load fallback`);
|
|
179
|
-
try {
|
|
180
|
-
xml = await fetch(`/i18n/${fallback}.xlf`).then((r) => r.text());
|
|
181
|
-
currentLocale = locale;
|
|
182
|
-
if (xml && !isTranslationXml(xml)) {
|
|
183
|
-
console.error(`Invalid XLIFF file for fallback locale ${fallback}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (e) {
|
|
187
|
-
console.warn(`Could not download XLIFF file for fallback locale ${fallback}: ${e.message}`);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!xml) {
|
|
191
|
-
console.error(`Could not download XLIFF file for locale ${locale} or preferred ${preferredLanguages.join(', ')} or fallback ${fallback}`);
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
if (!isTranslationXml(xml)) {
|
|
195
|
-
console.error(`Invalid XLIFF file for fallback locale ${currentLocale}`);
|
|
196
|
-
}
|
|
197
|
-
let json;
|
|
198
|
-
try {
|
|
199
|
-
json = await xliffToJson(xml);
|
|
200
|
-
}
|
|
201
|
-
catch (e) {
|
|
202
|
-
console.error(`Could not parse XLIFF file for locale ${locale}: ${e.message}`);
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
return { json, locale: currentLocale ?? locale };
|
|
206
|
-
}
|
|
207
101
|
/**
|
|
208
102
|
* Loads the locale data module for the specified locale and registers it.
|
|
209
103
|
*
|
|
@@ -218,9 +112,6 @@ async function defaultLoadModule(locale) {
|
|
|
218
112
|
case 'en':
|
|
219
113
|
module = await import('@angular/common/locales/en');
|
|
220
114
|
break;
|
|
221
|
-
case 'de':
|
|
222
|
-
module = await import('@angular/common/locales/de');
|
|
223
|
-
break;
|
|
224
115
|
}
|
|
225
116
|
if (module) {
|
|
226
117
|
registerLocaleData(module.default);
|
|
@@ -235,13 +126,14 @@ async function defaultLoadModule(locale) {
|
|
|
235
126
|
* This function fetches the translations based on the specified locale, preferred languages,
|
|
236
127
|
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
237
128
|
*
|
|
129
|
+
* @param {function} fetchTranslations - A function to fetch the translation json map
|
|
238
130
|
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
239
131
|
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
240
132
|
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
241
133
|
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
242
134
|
* @return {Promise<string>} The resolved locale, as a string.
|
|
243
135
|
*/
|
|
244
|
-
async function loadLanguages(loadModule = defaultLoadModule, locale = localStorage.getItem("locale") || navigator.language.split('-')[0] || 'en', preferredLanguages = navigator.languages?.map((l) => l.split('-')[0]) ?? [], fallback = 'messages') {
|
|
136
|
+
async function loadLanguages(fetchTranslations, loadModule = defaultLoadModule, locale = localStorage.getItem("locale") || navigator.language.split('-')[0] || 'en', preferredLanguages = navigator.languages?.map((l) => l.split('-')[0]) ?? [], fallback = 'messages') {
|
|
245
137
|
// Fetch XLIFF translation file and transform to JSON format (JSON translations can be used directly)
|
|
246
138
|
const response = await fetchTranslations(locale, preferredLanguages, fallback);
|
|
247
139
|
if (response) {
|
|
@@ -255,33 +147,29 @@ async function loadLanguages(loadModule = defaultLoadModule, locale = localStora
|
|
|
255
147
|
return locale;
|
|
256
148
|
}
|
|
257
149
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
catch (e) {
|
|
275
|
-
console.error(`Failed to load language translations: ${e.message}`);
|
|
276
|
-
}
|
|
150
|
+
async function loadI18nBootstrapHook(fetchTranslations, loadModule = defaultLoadModule, locale, preferredLanguages, fallback) {
|
|
151
|
+
return async (options) => {
|
|
152
|
+
try {
|
|
153
|
+
const currentLocale = await loadLanguages(fetchTranslations, loadModule, locale, preferredLanguages, fallback);
|
|
154
|
+
console.debug('locale', currentLocale);
|
|
155
|
+
options.providers ??= [];
|
|
156
|
+
options.providers.push({
|
|
157
|
+
provide: LOCALE_ID,
|
|
158
|
+
useValue: currentLocale
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
console.error(`Failed to load language translations: ${e.message}`);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
277
165
|
}
|
|
278
166
|
|
|
279
|
-
// region
|
|
167
|
+
// region
|
|
280
168
|
// endregion
|
|
281
169
|
|
|
282
170
|
/**
|
|
283
171
|
* Generated bundle index. Do not edit.
|
|
284
172
|
*/
|
|
285
173
|
|
|
286
|
-
export { I18nService, LanguageInterceptor, LanguageSelectorService, loadI18nBootstrapHook, loadLanguages
|
|
174
|
+
export { I18nService, LanguageInterceptor, LanguageSelectorService, defaultLoadModule, loadI18nBootstrapHook, loadLanguages };
|
|
287
175
|
//# sourceMappingURL=rxap-ngx-localize.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-ngx-localize.mjs","sources":["../../../../../packages/angular/localize/src/lib/i18n.service.ts","../../../../../packages/angular/localize/src/lib/language-interceptor.ts","../../../../../packages/angular/localize/src/lib/language-selector.service.ts","../../../../../packages/angular/localize/src/lib/xliff-to-json.ts","../../../../../packages/angular/localize/src/lib/load-languages.ts","../../../../../packages/angular/localize/src/lib/load-i18n-bootstrap-hook.ts","../../../../../packages/angular/localize/src/index.ts","../../../../../packages/angular/localize/src/rxap-ngx-localize.ts"],"sourcesContent":["import {\n inject,\n Injectable,\n isDevMode,\n LOCALE_ID,\n signal,\n Signal,\n} from '@angular/core';\nimport { UserSettingsLanguageService } from '@rxap/ngx-user';\n\n/**\n * @deprecated removed\n */\n@Injectable({ providedIn: 'root' })\nexport class I18nService {\n\n private readonly localId: string = inject(LOCALE_ID);\n private readonly userSettingsLanguageService = inject(UserSettingsLanguageService);\n\n public readonly currentLanguage: Signal<string> = signal(this.localId.replace(/-[A-Z]+$/, ''));\n\n public async setLanguage(language: string) {\n await this.userSettingsLanguageService.setLanguage(language);\n if (!isDevMode()) {\n this.redirect(language);\n }\n if (typeof (this.currentLanguage as any)['set'] === 'function') {\n (this.currentLanguage as any).set(language);\n }\n }\n\n public redirect(next: string, current: string = this.currentLanguage()) {\n if (current === next) {\n console.warn('[I18nService] redirect not required - language unchanged');\n return;\n }\n const redirectUrl =\n location.origin +\n location.pathname.replace(new RegExp(`^/${ current }`), `/${ next }`) +\n location.search;\n console.log('[I18nService] redirect to: ' + redirectUrl);\n location.replace(redirectUrl);\n }\n\n}\n","import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport {\n inject,\n LOCALE_ID,\n} from '@angular/core';\nimport { Observable } from 'rxjs';\n\n/**\n * Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.\n *\n * @param {HttpRequest<unknown>} request - The HTTP request to be intercepted and optionally modified.\n * @param {HttpHandlerFn} next - The next handler in the HTTP request pipeline.\n * @return {Observable<HttpEvent<unknown>>} An observable of the HTTP response event.\n */\nexport function LanguageInterceptor(\n request: HttpRequest<unknown>,\n next: HttpHandlerFn,\n): Observable<HttpEvent<unknown>> {\n\n const localId = inject(LOCALE_ID, { optional: true });\n\n if (localId) {\n request = request.clone({\n headers: request.headers.set('Accept-Language', localId),\n });\n }\n\n return next(request);\n\n}\n","import {\n computed,\n inject,\n Injectable,\n Signal,\n signal,\n} from '@angular/core';\nimport {\n ConfigService,\n LanguagesConfig,\n} from '@rxap/config';\n\n/**\n * A service that manages language selection and configuration for the application.\n * Provides functionality to retrieve available languages, default language,\n * selected language, and dynamically change the application's language settings.\n */\n@Injectable({ providedIn: 'root' })\nexport class LanguageSelectorService {\n private readonly config = inject(ConfigService);\n\n public readonly languages: Signal<LanguagesConfig> = signal(this.config.get<LanguagesConfig>('i18n.languages', {}));\n public readonly defaultLanguage: Signal<string> = signal(this.config.get('i18n.defaultLanguage', Object.keys(this.languages())[0] ?? 'en'));\n public readonly selectedLanguage = signal(localStorage.getItem(\"locale\") ?? this.defaultLanguage());\n\n public readonly hasLanguages = computed(() => Object.keys(this.languages()).length > 1);\n\n /**\n * Sets the application language to the specified value if it exists in the list of supported languages.\n * Optionally reloads the page if the `reload` parameter is set to `true`.\n *\n * @param {string} language - The language code to set as the active language.\n * @param {boolean} [reload=false] - A flag indicating whether to reload the page after updating the language.\n * @return {Promise<void>} A promise that resolves once the language has been set and optional reload is completed.\n */\n public async setLanguage(language: string, reload = false) {\n if (language !== this.selectedLanguage()) {\n if (Object.keys(this.languages()).includes(language)) {\n localStorage.setItem(\"locale\", language);\n if (reload) {\n location.reload();\n }\n }\n }\n }\n\n}\n","// @ts-expect-error type definition do not exists\nimport { xliff2js } from 'xliff/esm';\n\n/**\n * Converts an XLIFF translation string into a JSON object with translation keys and their corresponding values.\n *\n * @param {string} translations - A string in XLIFF format containing translations to be parsed and transformed.\n * @return {Promise<Object>} A promise that resolves to an object where keys are translation identifiers and values are the corresponding translations in plain text or templated string format.\n */\nexport async function xliffToJson(translations: string) {\n const parserResult = await xliff2js(translations);\n const xliffContent = parserResult.resources[\"ngi18n\"];\n\n return Object.keys(xliffContent).reduce((result: any, current) => {\n const translation = xliffContent[current].target;\n if (typeof translation === \"string\") {\n result[current] = translation;\n } else if (Array.isArray(translation)) {\n result[current] = translation\n .map((entry) =>\n typeof entry === \"string\" ? entry : `{{${entry.Standalone.id}}}`,\n )\n .join(\"\");\n } else if (typeof translation === \"object\" && 'Standalone' in translation && translation.Standalone.id !== '') {\n result[current] = `{{${translation.Standalone.id}}}`;\n } else {\n console.warn(`Could not parse XLIFF: (${current}) ${ JSON.stringify(xliffContent[current]) }`);\n return result;\n }\n result[current] = result[current].replace(\"{{\", \"{$\").replace(\"}}\", \"}\");\n return result;\n }, {});\n}\n","import { registerLocaleData } from '@angular/common';\nimport { loadTranslations } from '@angular/localize';\nimport { xliffToJson } from './xliff-to-json';\n\nfunction isTranslationXml(xml: string): boolean {\n return !!xml && typeof xml === 'string' && xml.startsWith('<?xml') && xml.includes('<xliff');\n}\n\n/**\n * Fetches the translation file for the specified locale in XLIFF format.\n *\n * @param {string} locale - The locale identifier for which the translation file should be fetched.\n * @return {Promise<string | null>} A promise that resolves to the XLIFF translation file as a string\n * if successfully fetched and valid, or null if the file is invalid or could not be fetched.\n */\nasync function fetchTranslation(locale: string): Promise<string | null> {\n\n let xml: string;\n try {\n xml = await fetch(`/i18n/${ locale }.xlf`).then((r) => r.text());\n if (!isTranslationXml(xml)) {\n console.error(`Invalid XLIFF file for locale ${ locale }`);\n return null;\n }\n return xml;\n } catch (e: any) {\n console.warn(`Could not download XLIFF file for locale ${ locale }: ${ e.message }`);\n }\n\n return null;\n\n}\n\n/**\n * Fetches translations for a specified locale, attempts to use preferred languages or a fallback if necessary.\n * The function retrieves and parses translation data from XLIFF files.\n *\n * @param {string} locale - The primary locale for which to fetch translations.\n * @param {string[]} preferredLanguages - An array of preferred fallback locales to try if the primary locale fails.\n * @param {string} fallback - The fallback locale to be used if both the primary and preferred locales fail.\n * @return {Promise<{ json: any, locale: string } | null>} A promise resolving to an object containing the parsed translation data (json) and the effective locale, or null if loading fails.\n */\nasync function fetchTranslations(locale: string, preferredLanguages: string[], fallback: string): Promise<{ json: any, locale: string } | null> {\n let xml: string | null = null;\n let currentLocale: string | undefined = locale;\n do {\n xml = await fetchTranslation(currentLocale);\n if (!xml) {\n currentLocale = preferredLanguages.shift();\n }\n } while (!xml && currentLocale);\n\n if (!xml) {\n console.error(`Could not download XLIFF file for locale ${ locale } load fallback`);\n try {\n xml = await fetch(`/i18n/${ fallback }.xlf`).then((r) => r.text());\n currentLocale = locale;\n if (xml && !isTranslationXml(xml)) {\n console.error(`Invalid XLIFF file for fallback locale ${ fallback }`);\n }\n } catch (e: any) {\n console.warn(`Could not download XLIFF file for fallback locale ${ fallback }: ${ e.message }`);\n }\n }\n\n if (!xml) {\n console.error(`Could not download XLIFF file for locale ${ locale } or preferred ${preferredLanguages.join(', ')} or fallback ${ fallback }`);\n return null;\n }\n\n if (!isTranslationXml(xml)) {\n console.error(`Invalid XLIFF file for fallback locale ${ currentLocale }`);\n }\n\n let json: any;\n try {\n json = await xliffToJson(xml);\n } catch (e: any) {\n console.error(`Could not parse XLIFF file for locale ${ locale }: ${ e.message }`);\n return null;\n }\n\n return { json, locale: currentLocale ?? locale };\n\n}\n\n/**\n * Loads the locale data module for the specified locale and registers it.\n *\n * @param {string} locale - The locale identifier for which the module needs to be loaded.\n * @return {Promise<void>} A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.\n */\nasync function defaultLoadModule(locale: string) {\n\n try {\n // Load required locale module (needs to be adjusted for different locales)\n let module: { default: any } | null = null;\n switch (locale) {\n\n case 'en':\n module = await import('@angular/common/locales/en');\n break;\n\n case 'de':\n module = await import('@angular/common/locales/de');\n break;\n\n }\n if (module) {\n registerLocaleData(module.default);\n }\n } catch (e: any) {\n console.error(`Could not load locale module for locale ${ locale }: ${ e.message }`);\n }\n\n}\n\n/**\n * Loads language translations and sets the locale for the application.\n * This function fetches the translations based on the specified locale, preferred languages,\n * and a fallback, then initializes the translations and optionally loads additional modules.\n *\n * @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.\n * @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.\n * @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.\n * @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.\n * @return {Promise<string>} The resolved locale, as a string.\n */\nexport async function loadLanguages(\n loadModule: (locale: string) => Promise<void> = defaultLoadModule,\n locale: string = localStorage.getItem(\"locale\") || navigator.language.split('-')[0] || 'en',\n preferredLanguages = navigator.languages?.map((l) => l.split('-')[0]) ?? [],\n fallback = 'messages'\n) {\n // Fetch XLIFF translation file and transform to JSON format (JSON translations can be used directly)\n const response = await fetchTranslations(locale, preferredLanguages, fallback);\n\n if (response) {\n // Initialize translation\n loadTranslations(response.json);\n locale = response.locale;\n $localize.locale = locale;\n localStorage.setItem(\"locale\", locale);\n await loadModule(locale);\n }\n\n return locale;\n}\n","import {\n ApplicationConfig,\n LOCALE_ID,\n} from '@angular/core';\nimport { loadLanguages } from './load-languages';\n\n/**\n * Loads internationalization (i18n) bootstrap settings for the application.\n *\n * @param {Partial<ApplicationConfig>} options - The application configuration options.\n * @return {Promise<void>} A promise that resolves when the i18n bootstrap process completes.\n */\nexport async function loadI18nBootstrapHook(options: Partial<ApplicationConfig>): Promise<void> {\n\n try {\n const locale = await loadLanguages();\n console.debug('locale', locale);\n options.providers ??= [];\n options.providers.push({\n provide: LOCALE_ID,\n useValue: locale\n });\n } catch (e: any) {\n console.error(`Failed to load language translations: ${e.message}`);\n }\n\n}\n","// region \nexport * from './lib/i18n.service';\nexport * from './lib/language-interceptor';\nexport * from './lib/language-selector.service';\nexport * from './lib/load-i18n-bootstrap-hook';\nexport * from './lib/load-languages';\nexport * from './lib/xliff-to-json';\n// endregion\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAUA;;AAEG;MAEU,WAAW,CAAA;AADxB,IAAA,WAAA,GAAA;AAGmB,QAAA,IAAA,CAAA,OAAO,GAAW,MAAM,CAAC,SAAS,CAAC;AACnC,QAAA,IAAA,CAAA,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC;AAElE,QAAA,IAAA,CAAA,eAAe,GAAmB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAyB/F;IAvBQ,MAAM,WAAW,CAAC,QAAgB,EAAA;QACvC,MAAM,IAAI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/language-interceptor.ts","../../../../../packages/angular/localize/src/lib/language-selector.service.ts","../../../../../packages/angular/localize/src/lib/load-languages.ts","../../../../../packages/angular/localize/src/lib/load-i18n-bootstrap-hook.ts","../../../../../packages/angular/localize/src/index.ts","../../../../../packages/angular/localize/src/rxap-ngx-localize.ts"],"sourcesContent":["import {\n inject,\n Injectable,\n isDevMode,\n LOCALE_ID,\n signal,\n Signal,\n} from '@angular/core';\nimport { UserSettingsLanguageService } from '@rxap/ngx-user';\n\n/**\n * @deprecated removed\n */\n@Injectable({ providedIn: 'root' })\nexport class I18nService {\n\n private readonly localId: string = inject(LOCALE_ID);\n private readonly userSettingsLanguageService = inject(UserSettingsLanguageService);\n\n public readonly currentLanguage: Signal<string> = signal(this.localId.replace(/-[A-Z]+$/, ''));\n\n public async setLanguage(language: string) {\n await this.userSettingsLanguageService.setLanguage(language);\n if (!isDevMode()) {\n this.redirect(language);\n }\n if (typeof (this.currentLanguage as any)['set'] === 'function') {\n (this.currentLanguage as any).set(language);\n }\n }\n\n public redirect(next: string, current: string = this.currentLanguage()) {\n if (current === next) {\n console.warn('[I18nService] redirect not required - language unchanged');\n return;\n }\n const redirectUrl =\n location.origin +\n location.pathname.replace(new RegExp(`^/${ current }`), `/${ next }`) +\n location.search;\n console.log('[I18nService] redirect to: ' + redirectUrl);\n location.replace(redirectUrl);\n }\n\n}\n","import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport {\n inject,\n LOCALE_ID,\n} from '@angular/core';\nimport { Observable } from 'rxjs';\n\n/**\n * Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.\n *\n * @param {HttpRequest<unknown>} request - The HTTP request to be intercepted and optionally modified.\n * @param {HttpHandlerFn} next - The next handler in the HTTP request pipeline.\n * @return {Observable<HttpEvent<unknown>>} An observable of the HTTP response event.\n */\nexport function LanguageInterceptor(\n request: HttpRequest<unknown>,\n next: HttpHandlerFn,\n): Observable<HttpEvent<unknown>> {\n\n const localId = inject(LOCALE_ID, { optional: true });\n\n if (localId) {\n request = request.clone({\n headers: request.headers.set('Accept-Language', localId),\n });\n }\n\n return next(request);\n\n}\n","import {\n computed,\n inject,\n Injectable,\n Signal,\n signal,\n} from '@angular/core';\nimport {\n ConfigService,\n LanguagesConfig,\n} from '@rxap/config';\n\n/**\n * A service that manages language selection and configuration for the application.\n * Provides functionality to retrieve available languages, default language,\n * selected language, and dynamically change the application's language settings.\n */\n@Injectable({ providedIn: 'root' })\nexport class LanguageSelectorService {\n private readonly config = inject(ConfigService);\n\n public readonly languages: Signal<LanguagesConfig> = signal(this.config.get<LanguagesConfig>('i18n.languages', {}));\n public readonly defaultLanguage: Signal<string> = signal(this.config.get('i18n.defaultLanguage', Object.keys(this.languages())[0] ?? 'en'));\n public readonly selectedLanguage = signal(localStorage.getItem(\"locale\") ?? this.defaultLanguage());\n\n public readonly hasLanguages = computed(() => Object.keys(this.languages()).length > 1);\n\n /**\n * Sets the application language to the specified value if it exists in the list of supported languages.\n * Optionally reloads the page if the `reload` parameter is set to `true`.\n *\n * @param {string} language - The language code to set as the active language.\n * @param {boolean} [reload=false] - A flag indicating whether to reload the page after updating the language.\n * @return {Promise<void>} A promise that resolves once the language has been set and optional reload is completed.\n */\n public async setLanguage(language: string, reload = false) {\n if (language !== this.selectedLanguage()) {\n if (Object.keys(this.languages()).includes(language)) {\n localStorage.setItem(\"locale\", language);\n if (reload) {\n location.reload();\n }\n }\n }\n }\n\n}\n","import { registerLocaleData } from '@angular/common';\nimport { loadTranslations } from '@angular/localize';\n\n/**\n * Loads the locale data module for the specified locale and registers it.\n *\n * @param {string} locale - The locale identifier for which the module needs to be loaded.\n * @return {Promise<void>} A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.\n */\nexport async function defaultLoadModule(locale: string) {\n\n try {\n // Load required locale module (needs to be adjusted for different locales)\n let module: { default: any } | null = null;\n switch (locale) {\n\n case 'en':\n module = await import('@angular/common/locales/en');\n break;\n\n }\n if (module) {\n registerLocaleData(module.default);\n }\n } catch (e: any) {\n console.error(`Could not load locale module for locale ${ locale }: ${ e.message }`);\n }\n\n}\n\nexport type FetchTranslationsFunction = (locale: string, preferredLanguages: string[], fallback: string) => Promise<{ json: any, locale: string } | null>;\n\nexport type LoadModuleFunction = (locale: string) => Promise<void>;\n\n/**\n * Loads language translations and sets the locale for the application.\n * This function fetches the translations based on the specified locale, preferred languages,\n * and a fallback, then initializes the translations and optionally loads additional modules.\n *\n * @param {function} fetchTranslations - A function to fetch the translation json map\n * @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.\n * @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.\n * @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.\n * @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.\n * @return {Promise<string>} The resolved locale, as a string.\n */\nexport async function loadLanguages(\n fetchTranslations: FetchTranslationsFunction,\n loadModule: LoadModuleFunction = defaultLoadModule,\n locale: string = localStorage.getItem(\"locale\") || navigator.language.split('-')[0] || 'en',\n preferredLanguages = navigator.languages?.map((l) => l.split('-')[0]) ?? [],\n fallback = 'messages',\n) {\n // Fetch XLIFF translation file and transform to JSON format (JSON translations can be used directly)\n const response = await fetchTranslations(locale, preferredLanguages, fallback);\n\n if (response) {\n // Initialize translation\n loadTranslations(response.json);\n locale = response.locale;\n $localize.locale = locale;\n localStorage.setItem(\"locale\", locale);\n await loadModule(locale);\n }\n\n return locale;\n}\n","import {\n ApplicationConfig,\n LOCALE_ID,\n} from '@angular/core';\nimport {\n defaultLoadModule,\n FetchTranslationsFunction,\n loadLanguages,\n LoadModuleFunction,\n} from './load-languages';\n\nexport async function loadI18nBootstrapHook(\n fetchTranslations: FetchTranslationsFunction,\n loadModule: LoadModuleFunction = defaultLoadModule,\n locale?: string,\n preferredLanguages?: string[],\n fallback?: string,\n) {\n return async (options: Partial<ApplicationConfig>) => {\n try {\n const currentLocale = await loadLanguages(\n fetchTranslations,\n loadModule,\n locale,\n preferredLanguages,\n fallback\n );\n console.debug('locale', currentLocale);\n options.providers ??= [];\n options.providers.push({\n provide: LOCALE_ID,\n useValue: currentLocale\n });\n } catch (e: any) {\n console.error(`Failed to load language translations: ${ e.message }`);\n }\n };\n}\n","// region\nexport * from './lib/i18n.service';\nexport * from './lib/language-interceptor';\nexport * from './lib/language-selector.service';\nexport * from './lib/load-i18n-bootstrap-hook';\nexport * from './lib/load-languages';\n// endregion\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAUA;;AAEG;MAEU,WAAW,CAAA;AADxB,IAAA,WAAA,GAAA;AAGmB,QAAA,IAAA,CAAA,OAAO,GAAW,MAAM,CAAC,SAAS,CAAC;AACnC,QAAA,IAAA,CAAA,2BAA2B,GAAG,MAAM,CAAC,2BAA2B,CAAC;AAElE,QAAA,IAAA,CAAA,eAAe,GAAmB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAyB/F;IAvBQ,MAAM,WAAW,CAAC,QAAgB,EAAA;QACvC,MAAM,IAAI,CAAC,2BAA2B,CAAC,WAAW,CAAC,QAAQ,CAAC;AAC5D,QAAA,IAAI,CAAC,SAAS,EAAE,EAAE;AAChB,YAAA,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;;QAEzB,IAAI,OAAQ,IAAI,CAAC,eAAuB,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AAC7D,YAAA,IAAI,CAAC,eAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC;;;AAIxC,IAAA,QAAQ,CAAC,IAAY,EAAE,UAAkB,IAAI,CAAC,eAAe,EAAE,EAAA;AACpE,QAAA,IAAI,OAAO,KAAK,IAAI,EAAE;AACpB,YAAA,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC;YACxE;;AAEF,QAAA,MAAM,WAAW,GACf,QAAQ,CAAC,MAAM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M,CAAC;AACtC,QAAA,MAAM,UAAU,CAAC,MAAM,CAAC;;AAG1B,IAAA,OAAO,MAAM;AACf;;ACvDO,eAAe,qBAAqB,CACzC,iBAA4C,EAC5C,UAAiC,GAAA,iBAAiB,EAClD,MAAe,EACf,kBAA6B,EAC7B,QAAiB,EAAA;AAEjB,IAAA,OAAO,OAAO,OAAmC,KAAI;AACnD,QAAA,IAAI;AACF,YAAA,MAAM,aAAa,GAAG,MAAM,aAAa,CACvC,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,kBAAkB,EAClB,QAAQ,CACT;AACD,YAAA,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC;AACtC,YAAA,OAAO,CAAC,SAAS,KAAK,EAAE;AACxB,YAAA,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;AACrB,gBAAA,OAAO,EAAE,SAAS;AAClB,gBAAA,QAAQ,EAAE;AACX,aAAA,CAAC;;QACF,OAAO,CAAM,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,CAAA,sCAAA,EAA0C,CAAC,CAAC,OAAQ,CAAE,CAAA,CAAC;;AAEzE,KAAC;AACH;;ACrCA;AAMA;;ACNA;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { ApplicationConfig } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @param {Partial<ApplicationConfig>} options - The application configuration options.
|
|
6
|
-
* @return {Promise<void>} A promise that resolves when the i18n bootstrap process completes.
|
|
7
|
-
*/
|
|
8
|
-
export declare function loadI18nBootstrapHook(options: Partial<ApplicationConfig>): Promise<void>;
|
|
2
|
+
import { FetchTranslationsFunction, LoadModuleFunction } from './load-languages';
|
|
3
|
+
export declare function loadI18nBootstrapHook(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): Promise<(options: Partial<ApplicationConfig>) => Promise<void>>;
|
package/lib/load-languages.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads the locale data module for the specified locale and registers it.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} locale - The locale identifier for which the module needs to be loaded.
|
|
5
|
+
* @return {Promise<void>} A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.
|
|
6
|
+
*/
|
|
7
|
+
export declare function defaultLoadModule(locale: string): Promise<void>;
|
|
8
|
+
export type FetchTranslationsFunction = (locale: string, preferredLanguages: string[], fallback: string) => Promise<{
|
|
9
|
+
json: any;
|
|
10
|
+
locale: string;
|
|
11
|
+
} | null>;
|
|
12
|
+
export type LoadModuleFunction = (locale: string) => Promise<void>;
|
|
1
13
|
/**
|
|
2
14
|
* Loads language translations and sets the locale for the application.
|
|
3
15
|
* This function fetches the translations based on the specified locale, preferred languages,
|
|
4
16
|
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
5
17
|
*
|
|
18
|
+
* @param {function} fetchTranslations - A function to fetch the translation json map
|
|
6
19
|
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
7
20
|
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
8
21
|
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
9
22
|
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
10
23
|
* @return {Promise<string>} The resolved locale, as a string.
|
|
11
24
|
*/
|
|
12
|
-
export declare function loadLanguages(
|
|
25
|
+
export declare function loadLanguages(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "19.1.0",
|
|
2
|
+
"version": "19.1.1-dev.0",
|
|
3
3
|
"name": "@rxap/ngx-localize",
|
|
4
4
|
"description": "This package provides internationalization (i18n) support for Angular applications, including services for language management, an HTTP interceptor for setting the `Accept-Language` header, and a language selector component. It allows you to set and manage the current language of your application, redirect users based on their language preference, and configure available languages. The package also includes an init generator to handle peer dependencies.\n",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@nx/devkit": "20.5.0",
|
|
8
|
-
"tslib": "2.6.2"
|
|
9
|
-
"xliff": "^6.2.1"
|
|
8
|
+
"tslib": "2.6.2"
|
|
10
9
|
},
|
|
11
10
|
"peerDependencies": {
|
|
12
11
|
"@angular/common": "^19.2.1",
|
|
13
12
|
"@angular/core": "^19.2.1",
|
|
14
|
-
"@rxap/config": "^19.1.0
|
|
15
|
-
"@rxap/ngx-user": "^19.0.4
|
|
13
|
+
"@rxap/config": "^19.1.0",
|
|
14
|
+
"@rxap/ngx-user": "^19.0.4",
|
|
16
15
|
"rxjs": "^7.8.1"
|
|
17
16
|
},
|
|
18
17
|
"author": {
|
|
@@ -61,59 +60,59 @@
|
|
|
61
60
|
},
|
|
62
61
|
{
|
|
63
62
|
"package": "@rxap/config",
|
|
64
|
-
"version": "19.1.0
|
|
63
|
+
"version": "19.1.0"
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
66
|
"package": "@rxap/data-source",
|
|
68
|
-
"version": "19.1.0
|
|
67
|
+
"version": "19.1.0"
|
|
69
68
|
},
|
|
70
69
|
{
|
|
71
70
|
"package": "@rxap/data-structure-tree",
|
|
72
|
-
"version": "1.1.16
|
|
71
|
+
"version": "1.1.16"
|
|
73
72
|
},
|
|
74
73
|
{
|
|
75
74
|
"package": "@rxap/definition",
|
|
76
|
-
"version": "19.0.4
|
|
75
|
+
"version": "19.0.4"
|
|
77
76
|
},
|
|
78
77
|
{
|
|
79
78
|
"package": "@rxap/environment",
|
|
80
|
-
"version": "19.0.4
|
|
79
|
+
"version": "19.0.4"
|
|
81
80
|
},
|
|
82
81
|
{
|
|
83
82
|
"package": "@rxap/mixin",
|
|
84
|
-
"version": "16.0.14
|
|
83
|
+
"version": "16.0.14"
|
|
85
84
|
},
|
|
86
85
|
{
|
|
87
86
|
"package": "@rxap/ngx-pub-sub",
|
|
88
|
-
"version": "19.0.4
|
|
87
|
+
"version": "19.0.4"
|
|
89
88
|
},
|
|
90
89
|
{
|
|
91
90
|
"package": "@rxap/ngx-user",
|
|
92
|
-
"version": "19.0.4
|
|
91
|
+
"version": "19.0.4"
|
|
93
92
|
},
|
|
94
93
|
{
|
|
95
94
|
"package": "@rxap/open-api",
|
|
96
|
-
"version": "19.1.0
|
|
95
|
+
"version": "19.1.0"
|
|
97
96
|
},
|
|
98
97
|
{
|
|
99
98
|
"package": "@rxap/pattern",
|
|
100
|
-
"version": "1.1.14
|
|
99
|
+
"version": "1.1.14"
|
|
101
100
|
},
|
|
102
101
|
{
|
|
103
102
|
"package": "@rxap/reflect-metadata",
|
|
104
|
-
"version": "1.0.15
|
|
103
|
+
"version": "1.0.15"
|
|
105
104
|
},
|
|
106
105
|
{
|
|
107
106
|
"package": "@rxap/remote-method",
|
|
108
|
-
"version": "19.0.4
|
|
107
|
+
"version": "19.0.4"
|
|
109
108
|
},
|
|
110
109
|
{
|
|
111
110
|
"package": "@rxap/rxjs",
|
|
112
|
-
"version": "1.1.16
|
|
111
|
+
"version": "1.1.16"
|
|
113
112
|
},
|
|
114
113
|
{
|
|
115
114
|
"package": "@rxap/utilities",
|
|
116
|
-
"version": "16.4.4
|
|
115
|
+
"version": "16.4.4"
|
|
117
116
|
}
|
|
118
117
|
]
|
|
119
118
|
},
|
|
@@ -128,7 +127,7 @@
|
|
|
128
127
|
},
|
|
129
128
|
"schematics": "./generators.json",
|
|
130
129
|
"sideEffects": false,
|
|
131
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "edbe45ecb6840997e71b8878ac67c3490fbe1a98",
|
|
132
131
|
"module": "fesm2022/rxap-ngx-localize.mjs",
|
|
133
132
|
"typings": "index.d.ts",
|
|
134
133
|
"exports": {
|