@rxap/ngx-localize 19.2.0 → 21.0.1-dev.1
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 +22 -0
- package/compodoc/changelog.html +20 -0
- package/compodoc/dependencies.html +6 -6
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +41 -41
- 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 +2 -2
- package/docs/html/functions/loadI18nBootstrapHook.html +1 -1
- package/docs/html/functions/loadLanguages.html +2 -2
- package/docs/html/index.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/html/types/FetchTranslationsFunction.html +1 -1
- package/docs/html/types/LoadModuleFunction.html +1 -1
- package/docs/html/variables/LOCALE_STORAGE_KEY.html +1 -1
- 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 +2 -2
- package/docs/markdown/functions/loadI18nBootstrapHook.md +2 -2
- package/docs/markdown/functions/loadLanguages.md +2 -2
- package/docs/markdown/globals.md +2 -2
- package/docs/markdown/type-aliases/FetchTranslationsFunction.md +2 -2
- package/docs/markdown/type-aliases/LoadModuleFunction.md +2 -2
- package/docs/markdown/variables/LOCALE_STORAGE_KEY.md +2 -2
- 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 +1 -1
- package/docs/wiki/Function.loadI18nBootstrapHook.md +1 -1
- package/docs/wiki/Function.loadLanguages.md +1 -1
- package/docs/wiki/TypeAlias.FetchTranslationsFunction.md +1 -1
- package/docs/wiki/TypeAlias.LoadModuleFunction.md +1 -1
- package/docs/wiki/Variable.LOCALE_STORAGE_KEY.md +1 -1
- package/docs/wiki/globals.md +1 -1
- package/fesm2022/rxap-ngx-localize.mjs +11 -11
- package/fesm2022/rxap-ngx-localize.mjs.map +1 -1
- package/package.json +31 -30
- package/types/rxap-ngx-localize.d.ts +84 -0
- package/index.d.ts +0 -6
- package/lib/const.d.ts +0 -1
- package/lib/i18n.service.d.ts +0 -14
- package/lib/language-interceptor.d.ts +0 -10
- package/lib/language-selector.service.d.ts +0 -26
- package/lib/load-i18n-bootstrap-hook.d.ts +0 -3
- package/lib/load-languages.d.ts +0 -25
|
@@ -14,7 +14,7 @@ class I18nService {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.localId = inject(LOCALE_ID);
|
|
16
16
|
this.userSettingsLanguageService = inject(UserSettingsLanguageService);
|
|
17
|
-
this.currentLanguage = signal(this.localId.replace(/-[A-Z]+$/, ''));
|
|
17
|
+
this.currentLanguage = signal(this.localId.replace(/-[A-Z]+$/, ''), ...(ngDevMode ? [{ debugName: "currentLanguage" }] : /* istanbul ignore next */ []));
|
|
18
18
|
}
|
|
19
19
|
async setLanguage(language) {
|
|
20
20
|
await this.userSettingsLanguageService.setLanguage(language);
|
|
@@ -36,10 +36,10 @@ class I18nService {
|
|
|
36
36
|
console.log('[I18nService] redirect to: ' + redirectUrl);
|
|
37
37
|
location.replace(redirectUrl);
|
|
38
38
|
}
|
|
39
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
40
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
39
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: I18nService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
40
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: I18nService, providedIn: 'root' }); }
|
|
41
41
|
}
|
|
42
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
42
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: I18nService, decorators: [{
|
|
43
43
|
type: Injectable,
|
|
44
44
|
args: [{ providedIn: 'root' }]
|
|
45
45
|
}] });
|
|
@@ -69,10 +69,10 @@ function LanguageInterceptor(request, next) {
|
|
|
69
69
|
class LanguageSelectorService {
|
|
70
70
|
constructor() {
|
|
71
71
|
this.config = inject(ConfigService);
|
|
72
|
-
this.languages = signal(this.config.get('i18n.languages', {}));
|
|
73
|
-
this.defaultLanguage = signal(this.config.get('i18n.defaultLanguage', Object.keys(this.languages())[0] ?? 'en'));
|
|
74
|
-
this.selectedLanguage = signal(localStorage.getItem(LOCALE_STORAGE_KEY) ?? this.defaultLanguage());
|
|
75
|
-
this.hasLanguages = computed(() => Object.keys(this.languages()).length > 1);
|
|
72
|
+
this.languages = signal(this.config.get('i18n.languages', {}), ...(ngDevMode ? [{ debugName: "languages" }] : /* istanbul ignore next */ []));
|
|
73
|
+
this.defaultLanguage = signal(this.config.get('i18n.defaultLanguage', Object.keys(this.languages())[0] ?? 'en'), ...(ngDevMode ? [{ debugName: "defaultLanguage" }] : /* istanbul ignore next */ []));
|
|
74
|
+
this.selectedLanguage = signal(localStorage.getItem(LOCALE_STORAGE_KEY) ?? this.defaultLanguage(), ...(ngDevMode ? [{ debugName: "selectedLanguage" }] : /* istanbul ignore next */ []));
|
|
75
|
+
this.hasLanguages = computed(() => Object.keys(this.languages()).length > 1, ...(ngDevMode ? [{ debugName: "hasLanguages" }] : /* istanbul ignore next */ []));
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Sets the application language to the specified value if it exists in the list of supported languages.
|
|
@@ -98,10 +98,10 @@ class LanguageSelectorService {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
102
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
101
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: LanguageSelectorService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
102
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: LanguageSelectorService, providedIn: 'root' }); }
|
|
103
103
|
}
|
|
104
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
104
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: LanguageSelectorService, decorators: [{
|
|
105
105
|
type: Injectable,
|
|
106
106
|
args: [{ providedIn: 'root' }]
|
|
107
107
|
}] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-ngx-localize.mjs","sources":["../../../../../packages/angular/localize/src/lib/const.ts","../../../../../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/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":["export const LOCALE_STORAGE_KEY = 'locale';","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';\nimport { LOCALE_STORAGE_KEY } from './const';\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_STORAGE_KEY) ?? 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_STORAGE_KEY, language);\n } else if (this.defaultLanguage()) {\n localStorage.setItem(LOCALE_STORAGE_KEY, this.defaultLanguage());\n } else {\n localStorage.removeItem(LOCALE_STORAGE_KEY);\n }\n if (reload) {\n location.reload();\n }\n }\n }\n\n}\n","import { registerLocaleData } from '@angular/common';\nimport { loadTranslations } from '@angular/localize';\nimport { LOCALE_STORAGE_KEY } from './const';\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.split('-')[0].toLowerCase()) {\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_STORAGE_KEY) || navigator.language || 'en',\n preferredLanguages = (navigator.languages ?? []).slice(),\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 console.debug('Loaded translations for locale:', response.locale);\n $localize.locale = locale;\n await loadModule(locale);\n }\n localStorage.setItem(LOCALE_STORAGE_KEY, locale);\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 function loadI18nBootstrapHook(\n fetchTranslations: FetchTranslationsFunction,\n loadModule: LoadModuleFunction = defaultLoadModule,\n locale?: string,\n preferredLanguages?: string[],\n fallback?: string,\n) {\n return async (_: any, options: Partial<ApplicationConfig>) => {\n try {\n const currentLocale = await loadLanguages(\n fetchTranslations,\n loadModule,\n locale,\n preferredLanguages,\n fallback\n );\n console.debug('current 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/const';\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":";;;;;;;AAAO,MAAM,kBAAkB,GAAG;;ACUlC;;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,EAAE,CAAC;YAC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AAE1B,IAAA,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC;AAEhD,IAAA,OAAO,MAAM;AACf;;ACxDgB,SAAA,qBAAqB,CACnC,iBAA4C,EAC5C,UAAA,GAAiC,iBAAiB,EAClD,MAAe,EACf,kBAA6B,EAC7B,QAAiB,EAAA;AAEjB,IAAA,OAAO,OAAO,CAAM,EAAE,OAAmC,KAAI;AAC3D,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,gBAAgB,EAAE,aAAa,CAAC;AAC9C,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;AAOA;;ACPA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"rxap-ngx-localize.mjs","sources":["../../../../../packages/angular/localize/src/lib/const.ts","../../../../../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/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":["export const LOCALE_STORAGE_KEY = 'locale';","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';\nimport { LOCALE_STORAGE_KEY } from './const';\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_STORAGE_KEY) ?? 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_STORAGE_KEY, language);\n } else if (this.defaultLanguage()) {\n localStorage.setItem(LOCALE_STORAGE_KEY, this.defaultLanguage());\n } else {\n localStorage.removeItem(LOCALE_STORAGE_KEY);\n }\n if (reload) {\n location.reload();\n }\n }\n }\n\n}\n","import { registerLocaleData } from '@angular/common';\nimport { loadTranslations } from '@angular/localize';\nimport { LOCALE_STORAGE_KEY } from './const';\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.split('-')[0].toLowerCase()) {\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_STORAGE_KEY) || navigator.language || 'en',\n preferredLanguages = (navigator.languages ?? []).slice(),\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 console.debug('Loaded translations for locale:', response.locale);\n $localize.locale = locale;\n await loadModule(locale);\n }\n localStorage.setItem(LOCALE_STORAGE_KEY, locale);\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 function loadI18nBootstrapHook(\n fetchTranslations: FetchTranslationsFunction,\n loadModule: LoadModuleFunction = defaultLoadModule,\n locale?: string,\n preferredLanguages?: string[],\n fallback?: string,\n) {\n return async (_: any, options: Partial<ApplicationConfig>) => {\n try {\n const currentLocale = await loadLanguages(\n fetchTranslations,\n loadModule,\n locale,\n preferredLanguages,\n fallback\n );\n console.debug('current 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/const';\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":";;;;;;;AAAO,MAAM,kBAAkB,GAAG;;ACUlC;;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,sFAAC;AAyB/F,IAAA;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;QACzB;QACA,IAAI,OAAQ,IAAI,CAAC,eAAuB,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE;AAC7D,YAAA,IAAI,CAAC,eAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC7C;IACF;AAEO,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;QACF;AACA,QAAA,MAAM,WAAW,GACf,QAAQ,CAAC,MAAM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
"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
|
-
"@nx/devkit": "
|
|
7
|
+
"@nx/devkit": "22.7.5",
|
|
8
8
|
"tslib": "2.6.2"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
|
-
"@angular/common": "^
|
|
12
|
-
"@angular/core": "^
|
|
13
|
-
"@rxap/config": "^
|
|
14
|
-
"@rxap/ngx-user": "^
|
|
15
|
-
"rxjs": "^7.8.
|
|
11
|
+
"@angular/common": "^21.2.9",
|
|
12
|
+
"@angular/core": "^21.2.9",
|
|
13
|
+
"@rxap/config": "^21.0.1-dev.1",
|
|
14
|
+
"@rxap/ngx-user": "^21.0.1-dev.1",
|
|
15
|
+
"rxjs": "^7.8.2"
|
|
16
16
|
},
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Merzough Münker",
|
|
@@ -36,83 +36,83 @@
|
|
|
36
36
|
"packageGroup": [
|
|
37
37
|
{
|
|
38
38
|
"package": "@angular/cdk",
|
|
39
|
-
"version": "
|
|
39
|
+
"version": "21.2.9"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"package": "@angular/common",
|
|
43
|
-
"version": "
|
|
43
|
+
"version": "21.2.9"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"package": "@angular/core",
|
|
47
|
-
"version": "
|
|
47
|
+
"version": "21.2.9"
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
"package": "@angular/forms",
|
|
51
|
-
"version": "
|
|
51
|
+
"version": "21.2.9"
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
"package": "@angular/material",
|
|
55
|
-
"version": "
|
|
55
|
+
"version": "21.2.9"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"package": "@angular/platform-browser",
|
|
59
|
-
"version": "
|
|
59
|
+
"version": "21.2.9"
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
"package": "@rxap/config",
|
|
63
|
-
"version": "
|
|
63
|
+
"version": "21.0.1-dev.1"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
"package": "@rxap/data-source",
|
|
67
|
-
"version": "
|
|
67
|
+
"version": "21.0.1-dev.1"
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
"package": "@rxap/data-structure-tree",
|
|
71
|
-
"version": "1.1.
|
|
71
|
+
"version": "1.1.19-dev.1"
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
"package": "@rxap/definition",
|
|
75
|
-
"version": "
|
|
75
|
+
"version": "21.0.1-dev.1"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"package": "@rxap/environment",
|
|
79
|
-
"version": "
|
|
79
|
+
"version": "21.0.1-dev.1"
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"package": "@rxap/mixin",
|
|
83
|
-
"version": "16.0.
|
|
83
|
+
"version": "16.0.17-dev.1"
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
"package": "@rxap/ngx-pub-sub",
|
|
87
|
-
"version": "
|
|
87
|
+
"version": "21.0.1-dev.1"
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
90
|
"package": "@rxap/ngx-user",
|
|
91
|
-
"version": "
|
|
91
|
+
"version": "21.0.1-dev.1"
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
"package": "@rxap/open-api",
|
|
95
|
-
"version": "
|
|
95
|
+
"version": "21.0.1-dev.1"
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
"package": "@rxap/pattern",
|
|
99
|
-
"version": "1.1.
|
|
99
|
+
"version": "1.1.16-dev.1"
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
"package": "@rxap/reflect-metadata",
|
|
103
|
-
"version": "1.0.
|
|
103
|
+
"version": "1.0.18-dev.1"
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"package": "@rxap/remote-method",
|
|
107
|
-
"version": "
|
|
107
|
+
"version": "21.0.1-dev.1"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
"package": "@rxap/rxjs",
|
|
111
|
-
"version": "1.1.
|
|
111
|
+
"version": "1.1.18-dev.1"
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
"package": "@rxap/utilities",
|
|
115
|
-
"version": "16.5.1"
|
|
115
|
+
"version": "16.5.2-dev.1"
|
|
116
116
|
}
|
|
117
117
|
]
|
|
118
118
|
},
|
|
@@ -128,15 +128,16 @@
|
|
|
128
128
|
"schematics": "./generators.json",
|
|
129
129
|
"sideEffects": false,
|
|
130
130
|
"module": "fesm2022/rxap-ngx-localize.mjs",
|
|
131
|
-
"typings": "
|
|
131
|
+
"typings": "types/rxap-ngx-localize.d.ts",
|
|
132
132
|
"exports": {
|
|
133
133
|
"./package.json": {
|
|
134
134
|
"default": "./package.json"
|
|
135
135
|
},
|
|
136
136
|
".": {
|
|
137
|
-
"types": "./
|
|
137
|
+
"types": "./types/rxap-ngx-localize.d.ts",
|
|
138
138
|
"default": "./fesm2022/rxap-ngx-localize.mjs"
|
|
139
139
|
},
|
|
140
140
|
"./theme": "./theme.css"
|
|
141
|
-
}
|
|
141
|
+
},
|
|
142
|
+
"type": "module"
|
|
142
143
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Signal, ApplicationConfig } from '@angular/core';
|
|
3
|
+
import { HttpRequest, HttpHandlerFn, HttpEvent } from '@angular/common/http';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
import { LanguagesConfig } from '@rxap/config';
|
|
6
|
+
|
|
7
|
+
declare const LOCALE_STORAGE_KEY = "locale";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated removed
|
|
11
|
+
*/
|
|
12
|
+
declare class I18nService {
|
|
13
|
+
private readonly localId;
|
|
14
|
+
private readonly userSettingsLanguageService;
|
|
15
|
+
readonly currentLanguage: Signal<string>;
|
|
16
|
+
setLanguage(language: string): Promise<void>;
|
|
17
|
+
redirect(next: string, current?: string): void;
|
|
18
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<I18nService, never>;
|
|
19
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<I18nService>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Intercepts an HTTP request to include a localized 'Accept-Language' header, if available.
|
|
24
|
+
*
|
|
25
|
+
* @param {HttpRequest<unknown>} request - The HTTP request to be intercepted and optionally modified.
|
|
26
|
+
* @param {HttpHandlerFn} next - The next handler in the HTTP request pipeline.
|
|
27
|
+
* @return {Observable<HttpEvent<unknown>>} An observable of the HTTP response event.
|
|
28
|
+
*/
|
|
29
|
+
declare function LanguageInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A service that manages language selection and configuration for the application.
|
|
33
|
+
* Provides functionality to retrieve available languages, default language,
|
|
34
|
+
* selected language, and dynamically change the application's language settings.
|
|
35
|
+
*/
|
|
36
|
+
declare class LanguageSelectorService {
|
|
37
|
+
private readonly config;
|
|
38
|
+
readonly languages: Signal<LanguagesConfig>;
|
|
39
|
+
readonly defaultLanguage: Signal<string>;
|
|
40
|
+
readonly selectedLanguage: i0.WritableSignal<string>;
|
|
41
|
+
readonly hasLanguages: Signal<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the application language to the specified value if it exists in the list of supported languages.
|
|
44
|
+
* Optionally reloads the page if the `reload` parameter is set to `true`.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} language - The language code to set as the active language.
|
|
47
|
+
* @param {boolean} [reload=false] - A flag indicating whether to reload the page after updating the language.
|
|
48
|
+
* @return {Promise<void>} A promise that resolves once the language has been set and optional reload is completed.
|
|
49
|
+
*/
|
|
50
|
+
setLanguage(language: string, reload?: boolean): Promise<void>;
|
|
51
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LanguageSelectorService, never>;
|
|
52
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LanguageSelectorService>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Loads the locale data module for the specified locale and registers it.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} locale - The locale identifier for which the module needs to be loaded.
|
|
59
|
+
* @return {Promise<void>} A promise that resolves when the module is successfully loaded and registered, or logs an error if loading fails.
|
|
60
|
+
*/
|
|
61
|
+
declare function defaultLoadModule(locale: string): Promise<void>;
|
|
62
|
+
type FetchTranslationsFunction = (locale: string, preferredLanguages: string[], fallback: string) => Promise<{
|
|
63
|
+
json: any;
|
|
64
|
+
locale: string;
|
|
65
|
+
} | null>;
|
|
66
|
+
type LoadModuleFunction = (locale: string) => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Loads language translations and sets the locale for the application.
|
|
69
|
+
* This function fetches the translations based on the specified locale, preferred languages,
|
|
70
|
+
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
71
|
+
*
|
|
72
|
+
* @param {function} fetchTranslations - A function to fetch the translation json map
|
|
73
|
+
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
74
|
+
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
75
|
+
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
76
|
+
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
77
|
+
* @return {Promise<string>} The resolved locale, as a string.
|
|
78
|
+
*/
|
|
79
|
+
declare function loadLanguages(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): Promise<string>;
|
|
80
|
+
|
|
81
|
+
declare function loadI18nBootstrapHook(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): (_: any, options: Partial<ApplicationConfig>) => Promise<void>;
|
|
82
|
+
|
|
83
|
+
export { I18nService, LOCALE_STORAGE_KEY, LanguageInterceptor, LanguageSelectorService, defaultLoadModule, loadI18nBootstrapHook, loadLanguages };
|
|
84
|
+
export type { FetchTranslationsFunction, LoadModuleFunction };
|
package/index.d.ts
DELETED
package/lib/const.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const LOCALE_STORAGE_KEY = "locale";
|
package/lib/i18n.service.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Signal } from '@angular/core';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated removed
|
|
5
|
-
*/
|
|
6
|
-
export declare class I18nService {
|
|
7
|
-
private readonly localId;
|
|
8
|
-
private readonly userSettingsLanguageService;
|
|
9
|
-
readonly currentLanguage: Signal<string>;
|
|
10
|
-
setLanguage(language: string): Promise<void>;
|
|
11
|
-
redirect(next: string, current?: string): void;
|
|
12
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<I18nService, never>;
|
|
13
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<I18nService>;
|
|
14
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { HttpEvent, HttpHandlerFn, HttpRequest } from '@angular/common/http';
|
|
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
|
-
*/
|
|
10
|
-
export declare function LanguageInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Signal } from '@angular/core';
|
|
2
|
-
import { LanguagesConfig } from '@rxap/config';
|
|
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
|
-
*/
|
|
9
|
-
export declare class LanguageSelectorService {
|
|
10
|
-
private readonly config;
|
|
11
|
-
readonly languages: Signal<LanguagesConfig>;
|
|
12
|
-
readonly defaultLanguage: Signal<string>;
|
|
13
|
-
readonly selectedLanguage: import("@angular/core").WritableSignal<string>;
|
|
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
|
-
*/
|
|
23
|
-
setLanguage(language: string, reload?: boolean): Promise<void>;
|
|
24
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LanguageSelectorService, never>;
|
|
25
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LanguageSelectorService>;
|
|
26
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ApplicationConfig } from '@angular/core';
|
|
2
|
-
import { FetchTranslationsFunction, LoadModuleFunction } from './load-languages';
|
|
3
|
-
export declare function loadI18nBootstrapHook(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): (_: any, options: Partial<ApplicationConfig>) => Promise<void>;
|
package/lib/load-languages.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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>;
|
|
13
|
-
/**
|
|
14
|
-
* Loads language translations and sets the locale for the application.
|
|
15
|
-
* This function fetches the translations based on the specified locale, preferred languages,
|
|
16
|
-
* and a fallback, then initializes the translations and optionally loads additional modules.
|
|
17
|
-
*
|
|
18
|
-
* @param {function} fetchTranslations - A function to fetch the translation json map
|
|
19
|
-
* @param {function} loadModule - A function to load additional modules for the specified locale. Defaults to `defaultLoadModule`.
|
|
20
|
-
* @param {string} [locale] - The primary locale to be used. Defaults to the stored locale, browser language, or 'en'.
|
|
21
|
-
* @param {string[]} [preferredLanguages] - A list of preferred languages to use, derived from the browser or input. Defaults to the browser's preferred languages.
|
|
22
|
-
* @param {string} [fallback] - The fallback key for translation files. Defaults to 'messages'.
|
|
23
|
-
* @return {Promise<string>} The resolved locale, as a string.
|
|
24
|
-
*/
|
|
25
|
-
export declare function loadLanguages(fetchTranslations: FetchTranslationsFunction, loadModule?: LoadModuleFunction, locale?: string, preferredLanguages?: string[], fallback?: string): Promise<string>;
|