Files
cbsnexora/src/app/app.module.ts
T
Abhinav R CillankiandGitHub 2da6093955 fix(translations): Ensure missing keys display original text instead of prefixed labels (#2319)
- Added a custom `MissingTranslationHandler` in `app.module.ts` to remove `labels.catalogs.` prefix
  when a translation key is not found.
- Updated `TranslateModule` configuration to use the custom handler globally.
- Ensured that missing translations fall back to the original value.
- Removed an unnecessary change from `address-tab.component.ts` introduced in a previous PR, as the
  current implementation resolves the issue more effectively.
2025-03-15 22:27:48 -06:00

121 lines
3.9 KiB
TypeScript

/** Angular Imports */
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpBackend, HttpClient, HttpClientModule } from '@angular/common/http';
/** Environment Configuration */
/** Main Component */
import { WebAppComponent } from './web-app.component';
/** Not Found Component */
import { NotFoundComponent } from './not-found/not-found.component';
/** Custom Modules */
import { CoreModule } from './core/core.module';
import { HomeModule } from './home/home.module';
import { LoginModule } from './login/login.module';
import { SettingsModule } from './settings/settings.module';
import { NavigationModule } from './navigation/navigation.module';
import { ClientsModule } from './clients/clients.module';
import { GroupsModule } from './groups/groups.module';
import { CentersModule } from './centers/centers.module';
import { AccountingModule } from './accounting/accounting.module';
import { SelfServiceModule } from './self-service/self-service.module';
import { SystemModule } from './system/system.module';
import { ProductsModule } from './products/products.module';
import { OrganizationModule } from './organization/organization.module';
import { TemplatesModule } from './templates/templates.module';
import { UsersModule } from './users/users.module';
import { ReportsModule } from './reports/reports.module';
import { SearchModule } from './search/search.module';
import { NotificationsModule } from './notifications/notifications.module';
import { CollectionsModule } from './collections/collections.module';
import { ProfileModule } from './profile/profile.module';
import { TasksModule } from './tasks/tasks.module';
import { ConfigurationWizardModule } from './configuration-wizard/configuration-wizard.module';
import { PortalModule } from '@angular/cdk/portal';
/** Main Routing Module */
import { AppRoutingModule } from './app-routing.module';
import { DatePipe, LocationStrategy } from '@angular/common';
import {
TranslateLoader,
TranslateModule,
MissingTranslationHandler,
MissingTranslationHandlerParams
} from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
export class CustomMissingTranslationHandler implements MissingTranslationHandler {
handle(params: MissingTranslationHandlerParams): string {
// Remove the 'labels.catalogs.' prefix and return the fallback value
return params.key.replace('labels.catalogs.', '');
}
}
/**
* App Module
*
* Core module and all feature modules should be imported here in proper order.
*/
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
@NgModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (httpBackend: HttpBackend, locationStrategy: LocationStrategy) => {
const http = new HttpClient(httpBackend);
return new TranslateHttpLoader(http, `/assets/translations/`, '.json');
},
deps: [
HttpBackend,
LocationStrategy
]
},
missingTranslationHandler: { provide: MissingTranslationHandler, useClass: CustomMissingTranslationHandler }
}),
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
PortalModule,
CoreModule,
HomeModule,
LoginModule,
ProfileModule,
SettingsModule,
NavigationModule,
ClientsModule,
ReportsModule,
GroupsModule,
CentersModule,
AccountingModule,
SelfServiceModule,
SystemModule,
ProductsModule,
OrganizationModule,
TemplatesModule,
UsersModule,
NotificationsModule,
SearchModule,
CollectionsModule,
TasksModule,
ConfigurationWizardModule,
AppRoutingModule
],
declarations: [
WebAppComponent,
NotFoundComponent
],
providers: [DatePipe],
bootstrap: [WebAppComponent]
})
export class AppModule {}