RED-5485: allow runtime i18n init
This commit is contained in:
parent
d11abf9de5
commit
df2f052a83
@ -1,11 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { PruningTranslationLoader } from '../utils';
|
||||
import { IqserConfigService } from '../services';
|
||||
import { getConfig, IqserConfigService } from '../services';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
export function pruningTranslationLoaderFactory(pathPrefix: string): PruningTranslationLoader {
|
||||
const httpClient = inject(HttpClient);
|
||||
const version = inject(IqserConfigService).values.FRONTEND_APP_VERSION;
|
||||
const config = getConfig();
|
||||
const version = config.FRONTEND_APP_VERSION;
|
||||
|
||||
return new PruningTranslationLoader(httpClient, pathPrefix, `.json?version=${version}`);
|
||||
}
|
||||
|
||||
@ -29,12 +29,13 @@ export class IqserTranslateModule {
|
||||
}
|
||||
|
||||
static forRoot(options?: IqserTranslateModuleOptions): ModuleWithProviders<IqserTranslateModule> {
|
||||
const pathPrefix = options?.pathPrefix?.length ? options.pathPrefix : '/assets/i18n/';
|
||||
return {
|
||||
ngModule: IqserTranslateModule,
|
||||
providers: [
|
||||
{
|
||||
provide: translateLoaderToken,
|
||||
useFactory: () => pruningTranslationLoaderFactory(options?.pathPrefix ?? '/assets/i18n/'),
|
||||
useFactory: () => pruningTranslationLoaderFactory(pathPrefix),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@ interface T {
|
||||
}
|
||||
|
||||
export class PruningTranslationLoader implements TranslateLoader {
|
||||
constructor(private _http: HttpClient, private _prefix: string, private _suffix: string) {}
|
||||
constructor(private readonly _http: HttpClient, private readonly _prefix: string, private readonly _suffix: string) {}
|
||||
|
||||
getTranslation(lang: string): Observable<T> {
|
||||
return this._http.get(`${this._prefix}${lang}${this._suffix}`).pipe(map(result => this._process(result as T)));
|
||||
@ -11,7 +11,7 @@ export * from './decorators/debounce.decorator';
|
||||
export * from './decorators/on-change.decorator';
|
||||
export * from './http-encoder';
|
||||
export * from './types/iqser-types';
|
||||
export * from './pruning-translation-loader';
|
||||
export * from '../translations/pruning-translation-loader';
|
||||
export * from './custom-route-reuse.strategy';
|
||||
export * from './headers-configuration';
|
||||
export * from './context.component';
|
||||
|
||||
@ -3,7 +3,8 @@ export interface IqserAppConfig {
|
||||
readonly APP_NAME: string;
|
||||
readonly FRONTEND_APP_VERSION: string;
|
||||
readonly OAUTH_CLIENT_ID: string;
|
||||
readonly OAUTH_IDP_HINT: string;
|
||||
readonly OAUTH_IDP_HINT?: string;
|
||||
readonly OAUTH_URL: string;
|
||||
readonly MANUAL_BASE_URL: string;
|
||||
readonly BASE_TRANSLATIONS_DIRECTORY?: string;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user