Update Translation Path Factories
Update Imports
-
Remove
createTranslateLoader,createRemoteComponentAndMfeTranslateLoader,createRemoteComponentTranslateLoader,translationPathFactory,remoteComponentTranslationPathFactoryandTRANSLATION_PATHimports from@onecx/angular-accelerator. -
Add
provideTranslationPathFromMeta,createTranslateLoaderandTRANSLATION_PATHfrom@onecx/angular-utils.' -
Add
provideTranslateServiceForRootfrom@onecx/angular-utils
|
If you need to support multiple locales and fallback for missing translations, use |
Example - Replace translationPathFactory with provideTranslationPathFromMeta
import { TRANSLATION_PATH, translationPathFactory } from '@onecx/angular-accelerator';
@NgModule({
providers: [
// ... other providers,
{
provide: TRANSLATION_PATH,
useFactory: (appStateService: AppStateService) => translationPathFactory('assets/i18n/')(appStateService),
multi: true,
deps: [AppStateService]
}
]
})
imports { provideTranslationPathFromMeta } from '@onecx/angular-utils';
@NgModule({
providers: [
// ... other providers,
provideTranslationPathFromMeta(import.meta.url, 'assets/i18n/')
]
})
Example - Replace remoteComponentTranslationPathFactory with provideTranslationPathFromMeta
import { TRANSLATION_PATH, remoteComponentTranslationPathFactory } from '@onecx/angular-accelerator';
bootstrapRemoteComponent(RemoteComponent, 'ocx-my-remote-component', environment.production, [
// ... other providers
{
provide: TRANSLATION_PATH,
useFactory: (remoteComponentConfig: ReplaySubject<RemoteComponentConfig>) =>
remoteComponentTranslationPathFactory('assets/i18n/')(remoteComponentConfig),
multi: true,
deps: [REMOTE_COMPONENT_CONFIG]
},
]);
import { provideTranslationPathFromMeta } from '@onecx/angular-utils';
bootstrapRemoteComponent(RemoteComponent, 'ocx-my-remote-component', environment.production, [
// ... other providers
provideTranslationPathFromMeta(import.meta.url, 'assets/i18n/')
]);
Hint: To ensure the correct file path is used for import.meta.url, add the following to your application’s webpack.config.js:
|
Configure Translation Providers for Remote Components
In OneCX v6, For each Remote Component translation related providers are required to be defined in the bootstrap.ts instead of the component.ts file. For multiple locales and fallback translations, use AngularAcceleratorMissingTranslationHandler.
|
Use provideTranslationPathFromMeta with |
Example
import { TRANSLATION_PATH, translationPathFactory } from '@onecx/angular-accelerator';
@Component({
selector: 'ocx-my-remote',
templateUrl: './my-remote.component.html',
providers: [
{
provide: TRANSLATION_PATH,
useFactory: (appStateService: AppStateService) =>
translationPathFactory('assets/i18n/')(appStateService),
deps: [AppStateService],
multi: true,
},
]
})
export class MyRemoteComponent {}
import { provideTranslationPathFromMeta, provideTranslateServiceForRoot, createTranslateLoader } from '@onecx/angular-utils';
import { MissingTranslationHandler } from '@ngx-translate/core';
import { AngularAcceleratorMissingTranslationHandler } from '@onecx/angular-utils';
bootstrapRemoteComponent(
MyRemoteComponent,
'ocx-my-remote',
environment.production,
[
{ provide: REMOTE_COMPONENT_CONFIG, useValue: new ReplaySubject<RemoteComponentConfig>(1) },
provideTranslationPathFromMeta(import.meta.url, 'assets/i18n/'),
provideTranslateServiceForRoot({
isolate: true,
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [HttpClient]
},
// Optionally, add MissingTranslationHandler for logging and fallback
missingTranslationHandler: {
provide: MissingTranslationHandler,
useClass: AngularAcceleratorMissingTranslationHandler
}
})
]
)