@rxap/ngx-localize 19.1.0-dev.4 → 19.1.0-dev.7
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 +16 -0
- package/compodoc/changelog.html +12 -0
- package/compodoc/injectables/LanguageSelectorService.html +46 -7
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/miscellaneous/functions.html +111 -4
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +260 -45
- package/docs/html/classes/I18nService.html +3 -3
- package/docs/html/classes/LanguageSelectorService.html +10 -2
- package/docs/html/functions/LanguageInterceptor.html +5 -1
- package/docs/html/functions/loadI18nBootstrapHook.html +4 -1
- package/docs/html/functions/loadLanguages.html +9 -1
- package/docs/html/functions/xliffToJson.html +4 -1
- package/docs/html/index.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/markdown/README.md +1 -1
- package/docs/markdown/classes/I18nService.md +5 -5
- package/docs/markdown/classes/LanguageSelectorService.md +22 -9
- package/docs/markdown/functions/LanguageInterceptor.md +10 -2
- package/docs/markdown/functions/loadI18nBootstrapHook.md +8 -2
- package/docs/markdown/functions/loadLanguages.md +20 -6
- package/docs/markdown/functions/xliffToJson.md +8 -2
- package/docs/markdown/globals.md +2 -2
- package/docs/wiki/Class.I18nService.md +4 -4
- package/docs/wiki/Class.LanguageSelectorService.md +21 -8
- package/docs/wiki/Function.LanguageInterceptor.md +9 -1
- package/docs/wiki/Function.loadI18nBootstrapHook.md +7 -1
- package/docs/wiki/Function.loadLanguages.md +19 -5
- package/docs/wiki/Function.xliffToJson.md +7 -1
- package/docs/wiki/globals.md +1 -1
- package/fesm2022/rxap-ngx-localize.mjs +84 -14
- package/fesm2022/rxap-ngx-localize.mjs.map +1 -1
- package/lib/language-interceptor.d.ts +7 -0
- package/lib/language-selector.service.d.ts +13 -0
- package/lib/load-i18n-bootstrap-hook.d.ts +6 -0
- package/lib/load-languages.d.ts +11 -0
- package/lib/xliff-to-json.d.ts +6 -0
- package/package.json +2 -2
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
# Function: loadLanguages()
|
|
4
4
|
|
|
5
|
-
> **loadLanguages**(`loadModule`, `locale
|
|
5
|
+
> **loadLanguages**(`loadModule`, `locale`?, `preferredLanguages`?, `fallback`?): `Promise`\<`string`\>
|
|
6
6
|
|
|
7
|
-
Defined in: [load-languages.ts:
|
|
7
|
+
Defined in: [load-languages.ts:129](https://gitlab.com/rxap/packages/-/blob/75776b311d9691b0c51b086377bbeb5883bf70d3/packages/angular/localize/src/lib/load-languages.ts#L129)
|
|
8
|
+
|
|
9
|
+
Loads language translations and sets the locale for the application.
|
|
10
|
+
This function fetches the translations based on the specified locale, preferred languages,
|
|
11
|
+
and a fallback, then initializes the translations and optionally loads additional modules.
|
|
8
12
|
|
|
9
13
|
## Parameters
|
|
10
14
|
|
|
@@ -12,18 +16,28 @@ Defined in: [load-languages.ts:97](https://gitlab.com/rxap/packages/-/blob/be694
|
|
|
12
16
|
|
|
13
17
|
(`locale`) => `Promise`\<`void`\>
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
20
|
+
|
|
21
|
+
### locale?
|
|
16
22
|
|
|
17
23
|
`string` = `...`
|
|
18
24
|
|
|
19
|
-
|
|
25
|
+
The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
26
|
+
|
|
27
|
+
### preferredLanguages?
|
|
20
28
|
|
|
21
29
|
`string`[] = `...`
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
32
|
+
|
|
33
|
+
### fallback?
|
|
24
34
|
|
|
25
35
|
`string` = `'messages'`
|
|
26
36
|
|
|
37
|
+
The fallback key for translation files. Defaults to 'messages'.
|
|
38
|
+
|
|
27
39
|
## Returns
|
|
28
40
|
|
|
29
41
|
`Promise`\<`string`\>
|
|
42
|
+
|
|
43
|
+
The resolved locale, as a string.
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
> **xliffToJson**(`translations`): `Promise`\<`any`\>
|
|
6
6
|
|
|
7
|
-
Defined in: [xliff-to-json.ts:
|
|
7
|
+
Defined in: [xliff-to-json.ts:10](https://gitlab.com/rxap/packages/-/blob/75776b311d9691b0c51b086377bbeb5883bf70d3/packages/angular/localize/src/lib/xliff-to-json.ts#L10)
|
|
8
|
+
|
|
9
|
+
Converts an XLIFF translation string into a JSON object with translation keys and their corresponding values.
|
|
8
10
|
|
|
9
11
|
## Parameters
|
|
10
12
|
|
|
@@ -12,6 +14,10 @@ Defined in: [xliff-to-json.ts:4](https://gitlab.com/rxap/packages/-/blob/be694d7
|
|
|
12
14
|
|
|
13
15
|
`string`
|
|
14
16
|
|
|
17
|
+
A string in XLIFF format containing translations to be parsed and transformed.
|
|
18
|
+
|
|
15
19
|
## Returns
|
|
16
20
|
|
|
17
21
|
`Promise`\<`any`\>
|
|
22
|
+
|
|
23
|
+
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.
|
package/docs/wiki/globals.md
CHANGED
|
@@ -43,6 +43,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
|
|
|
43
43
|
args: [{ providedIn: 'root' }]
|
|
44
44
|
}] });
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.
|
|
48
|
+
*
|
|
49
|
+
* @param {HttpRequest<unknown>} request - The HTTP request to be intercepted and optionally modified.
|
|
50
|
+
* @param {HttpHandlerFn} next - The next handler in the HTTP request pipeline.
|
|
51
|
+
* @return {Observable<HttpEvent<unknown>>} An observable of the HTTP response event.
|
|
52
|
+
*/
|
|
46
53
|
function LanguageInterceptor(request, next) {
|
|
47
54
|
const localId = inject(LOCALE_ID, { optional: true });
|
|
48
55
|
if (localId) {
|
|
@@ -53,6 +60,11 @@ function LanguageInterceptor(request, next) {
|
|
|
53
60
|
return next(request);
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
/**
|
|
64
|
+
* A service that manages language selection and configuration for the application.
|
|
65
|
+
* Provides functionality to retrieve available languages, default language,
|
|
66
|
+
* selected language, and dynamically change the application's language settings.
|
|
67
|
+
*/
|
|
56
68
|
class LanguageSelectorService {
|
|
57
69
|
constructor() {
|
|
58
70
|
this.config = inject(ConfigService);
|
|
@@ -61,6 +73,14 @@ class LanguageSelectorService {
|
|
|
61
73
|
this.selectedLanguage = signal(localStorage.getItem("locale") ?? this.defaultLanguage());
|
|
62
74
|
this.hasLanguages = computed(() => Object.keys(this.languages()).length > 1);
|
|
63
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Sets the application language to the specified value if it exists in the list of supported languages.
|
|
78
|
+
* Optionally reloads the page if the `reload` parameter is set to `true`.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} language - The language code to set as the active language.
|
|
81
|
+
* @param {boolean} [reload=false] - A flag indicating whether to reload the page after updating the language.
|
|
82
|
+
* @return {Promise<void>} A promise that resolves once the language has been set and optional reload is completed.
|
|
83
|
+
*/
|
|
64
84
|
async setLanguage(language, reload = false) {
|
|
65
85
|
if (language !== this.selectedLanguage()) {
|
|
66
86
|
if (Object.keys(this.languages()).includes(language)) {
|
|
@@ -80,6 +100,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
|
|
|
80
100
|
}] });
|
|
81
101
|
|
|
82
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
|
+
*/
|
|
83
109
|
async function xliffToJson(translations) {
|
|
84
110
|
const parserResult = await xliff2js(translations);
|
|
85
111
|
const xliffContent = parserResult.resources["ngi18n"];
|
|
@@ -91,12 +117,16 @@ async function xliffToJson(translations) {
|
|
|
91
117
|
else if (Array.isArray(translation)) {
|
|
92
118
|
result[current] = translation
|
|
93
119
|
.map((entry) => typeof entry === "string" ? entry : `{{${entry.Standalone.id}}}`)
|
|
94
|
-
.map((entry) => entry.replace("{{", "{$").replace("}}", "}"))
|
|
95
120
|
.join("");
|
|
96
121
|
}
|
|
122
|
+
else if (typeof translation === "object" && 'Standalone' in translation && translation.Standalone.id !== '') {
|
|
123
|
+
result[current] = `{{${translation.Standalone.id}}}`;
|
|
124
|
+
}
|
|
97
125
|
else {
|
|
98
|
-
|
|
126
|
+
console.warn(`Could not parse XLIFF: (${current}) ${JSON.stringify(xliffContent[current])}`);
|
|
127
|
+
return result;
|
|
99
128
|
}
|
|
129
|
+
result[current] = result[current].replace("{{", "{$").replace("}}", "}");
|
|
100
130
|
return result;
|
|
101
131
|
}, {});
|
|
102
132
|
}
|
|
@@ -104,6 +134,13 @@ async function xliffToJson(translations) {
|
|
|
104
134
|
function isTranslationXml(xml) {
|
|
105
135
|
return !!xml && typeof xml === 'string' && xml.startsWith('<?xml') && xml.includes('<xliff');
|
|
106
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
|
+
*/
|
|
107
144
|
async function fetchTranslation(locale) {
|
|
108
145
|
let xml;
|
|
109
146
|
try {
|
|
@@ -119,8 +156,17 @@ async function fetchTranslation(locale) {
|
|
|
119
156
|
}
|
|
120
157
|
return null;
|
|
121
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
|
+
*/
|
|
122
168
|
async function fetchTranslations(locale, preferredLanguages, fallback) {
|
|
123
|
-
let xml;
|
|
169
|
+
let xml = null;
|
|
124
170
|
let currentLocale = locale;
|
|
125
171
|
do {
|
|
126
172
|
xml = await fetchTranslation(currentLocale);
|
|
@@ -129,17 +175,17 @@ async function fetchTranslations(locale, preferredLanguages, fallback) {
|
|
|
129
175
|
}
|
|
130
176
|
} while (!xml && currentLocale);
|
|
131
177
|
if (!xml) {
|
|
132
|
-
console.error(`Could not download XLIFF file for locale ${locale}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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}`);
|
|
139
188
|
}
|
|
140
|
-
}
|
|
141
|
-
catch (e) {
|
|
142
|
-
console.warn(`Could not download XLIFF file for fallback locale ${fallback}: ${e.message}`);
|
|
143
189
|
}
|
|
144
190
|
if (!xml) {
|
|
145
191
|
console.error(`Could not download XLIFF file for locale ${locale} or preferred ${preferredLanguages.join(', ')} or fallback ${fallback}`);
|
|
@@ -150,7 +196,7 @@ async function fetchTranslations(locale, preferredLanguages, fallback) {
|
|
|
150
196
|
}
|
|
151
197
|
let json;
|
|
152
198
|
try {
|
|
153
|
-
json = xliffToJson(xml);
|
|
199
|
+
json = await xliffToJson(xml);
|
|
154
200
|
}
|
|
155
201
|
catch (e) {
|
|
156
202
|
console.error(`Could not parse XLIFF file for locale ${locale}: ${e.message}`);
|
|
@@ -158,6 +204,12 @@ async function fetchTranslations(locale, preferredLanguages, fallback) {
|
|
|
158
204
|
}
|
|
159
205
|
return { json, locale: currentLocale ?? locale };
|
|
160
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Loads the locale data module for the specified locale and registers it.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} locale - The locale identifier for which the module needs to be loaded.
|
|
211
|
+
* @return {Promise<void>} A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.
|
|
212
|
+
*/
|
|
161
213
|
async function defaultLoadModule(locale) {
|
|
162
214
|
try {
|
|
163
215
|
// Load required locale module (needs to be adjusted for different locales)
|
|
@@ -178,10 +230,22 @@ async function defaultLoadModule(locale) {
|
|
|
178
230
|
console.error(`Could not load locale module for locale ${locale}: ${e.message}`);
|
|
179
231
|
}
|
|
180
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Loads language translations and sets the locale for the application.
|
|
235
|
+
* This function fetches the translations based on the specified locale, preferred languages,
|
|
236
|
+
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
237
|
+
*
|
|
238
|
+
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
239
|
+
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
240
|
+
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
241
|
+
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
242
|
+
* @return {Promise<string>} The resolved locale, as a string.
|
|
243
|
+
*/
|
|
181
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') {
|
|
182
245
|
// Fetch XLIFF translation file and transform to JSON format (JSON translations can be used directly)
|
|
183
246
|
const response = await fetchTranslations(locale, preferredLanguages, fallback);
|
|
184
247
|
if (response) {
|
|
248
|
+
console.log('json', response.json);
|
|
185
249
|
// Initialize translation
|
|
186
250
|
loadTranslations(response.json);
|
|
187
251
|
locale = response.locale;
|
|
@@ -192,6 +256,12 @@ async function loadLanguages(loadModule = defaultLoadModule, locale = localStora
|
|
|
192
256
|
return locale;
|
|
193
257
|
}
|
|
194
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Loads internationalization (i18n) bootstrap settings for the application.
|
|
261
|
+
*
|
|
262
|
+
* @param {Partial<ApplicationConfig>} options - The application configuration options.
|
|
263
|
+
* @return {Promise<void>} A promise that resolves when the i18n bootstrap process completes.
|
|
264
|
+
*/
|
|
195
265
|
async function loadI18nBootstrapHook(options) {
|
|
196
266
|
try {
|
|
197
267
|
const locale = await loadLanguages();
|
|
@@ -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\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@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 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\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 .map((entry) => entry.replace(\"{{\", \"{$\").replace(\"}}\", \"}\"))\n .join(\"\");\n } else {\n throw new Error(\"Could not parse XLIFF: \" + JSON.stringify(translation));\n }\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\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\nasync function fetchTranslations(locale: string, preferredLanguages: string[], fallback: string): Promise<{ json: any, locale: string } | null> {\n let xml: string | 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 } or fallback ${ fallback }`);\n }\n\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 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 = 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\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\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\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,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;AACf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;IACF,OAAO,CAAM,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,CAAA,sCAAA,EAAyC,CAAC,CAAC,OAAO,CAAE,CAAA,CAAC;;AAGvE;;ACpBA;AAOA;;ACPA;;AAEG;;;;"}
|
|
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 console.log('json', response.json);\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,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;AACf,YAAA,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAM,EAAA,EAAA,OAAQ,EAAE,CAAC,EAAE,CAAK,CAAA,EAAA,IAAK,EA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AAC,MAAM,CAAC;;AAG1B,IAAA,OAAO,MAAM;AACf;;AC9IA;;;;;AAKG;AACI,eAAe,qBAAqB,CAAC,OAAmC,EAAA;AAE7E,IAAA,IAAI;AACF,QAAA,MAAM,MAAM,GAAG,MAAM,aAAa,EAAE;AACpC,QAAA,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;AAC/B,QAAA,OAAO,CAAC,SAAS,KAAK,EAAE;AACxB,QAAA,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC;AACrB,YAAA,OAAO,EAAE,SAAS;AAClB,YAAA,QAAQ,EAAE;AACX,SAAA,CAAC;;IACF,OAAO,CAAM,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,CAAA,sCAAA,EAAyC,CAAC,CAAC,OAAO,CAAE,CAAA,CAAC;;AAGvE;;AC1BA;AAOA;;ACPA;;AAEG;;;;"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.
|
|
5
|
+
*
|
|
6
|
+
* @param {HttpRequest<unknown>} request - The HTTP request to be intercepted and optionally modified.
|
|
7
|
+
* @param {HttpHandlerFn} next - The next handler in the HTTP request pipeline.
|
|
8
|
+
* @return {Observable<HttpEvent<unknown>>} An observable of the HTTP response event.
|
|
9
|
+
*/
|
|
3
10
|
export declare function LanguageInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>>;
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { Signal } from '@angular/core';
|
|
2
2
|
import { LanguagesConfig } from '@rxap/config';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* A service that manages language selection and configuration for the application.
|
|
6
|
+
* Provides functionality to retrieve available languages, default language,
|
|
7
|
+
* selected language, and dynamically change the application's language settings.
|
|
8
|
+
*/
|
|
4
9
|
export declare class LanguageSelectorService {
|
|
5
10
|
private readonly config;
|
|
6
11
|
readonly languages: Signal<LanguagesConfig>;
|
|
7
12
|
readonly defaultLanguage: Signal<string>;
|
|
8
13
|
readonly selectedLanguage: import("@angular/core").WritableSignal<string>;
|
|
9
14
|
readonly hasLanguages: Signal<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the application language to the specified value if it exists in the list of supported languages.
|
|
17
|
+
* Optionally reloads the page if the `reload` parameter is set to `true`.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} language - The language code to set as the active language.
|
|
20
|
+
* @param {boolean} [reload=false] - A flag indicating whether to reload the page after updating the language.
|
|
21
|
+
* @return {Promise<void>} A promise that resolves once the language has been set and optional reload is completed.
|
|
22
|
+
*/
|
|
10
23
|
setLanguage(language: string, reload?: boolean): Promise<void>;
|
|
11
24
|
static ɵfac: i0.ɵɵFactoryDeclaration<LanguageSelectorService, never>;
|
|
12
25
|
static ɵprov: i0.ɵɵInjectableDeclaration<LanguageSelectorService>;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { ApplicationConfig } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Loads internationalization (i18n) bootstrap settings for the application.
|
|
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
|
+
*/
|
|
2
8
|
export declare function loadI18nBootstrapHook(options: Partial<ApplicationConfig>): Promise<void>;
|
package/lib/load-languages.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads language translations and sets the locale for the application.
|
|
3
|
+
* This function fetches the translations based on the specified locale, preferred languages,
|
|
4
|
+
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
5
|
+
*
|
|
6
|
+
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
7
|
+
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
8
|
+
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
9
|
+
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
10
|
+
* @return {Promise<string>} The resolved locale, as a string.
|
|
11
|
+
*/
|
|
1
12
|
export declare function loadLanguages(loadModule?: (locale: string) => Promise<void>, locale?: string, preferredLanguages?: string[], fallback?: string): Promise<string>;
|
package/lib/xliff-to-json.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an XLIFF translation string into a JSON object with translation keys and their corresponding values.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} translations - A string in XLIFF format containing translations to be parsed and transformed.
|
|
5
|
+
* @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.
|
|
6
|
+
*/
|
|
1
7
|
export declare function xliffToJson(translations: string): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "19.1.0-dev.
|
|
2
|
+
"version": "19.1.0-dev.7",
|
|
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",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
},
|
|
129
129
|
"schematics": "./generators.json",
|
|
130
130
|
"sideEffects": false,
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "75776b311d9691b0c51b086377bbeb5883bf70d3",
|
|
132
132
|
"module": "fesm2022/rxap-ngx-localize.mjs",
|
|
133
133
|
"typings": "index.d.ts",
|
|
134
134
|
"exports": {
|