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.
This commit is contained in:
+15
-2
@@ -40,9 +40,21 @@ import { PortalModule } from '@angular/cdk/portal';
|
|||||||
/** Main Routing Module */
|
/** Main Routing Module */
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { DatePipe, LocationStrategy } from '@angular/common';
|
import { DatePipe, LocationStrategy } from '@angular/common';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import {
|
||||||
|
TranslateLoader,
|
||||||
|
TranslateModule,
|
||||||
|
MissingTranslationHandler,
|
||||||
|
MissingTranslationHandlerParams
|
||||||
|
} from '@ngx-translate/core';
|
||||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
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
|
* App Module
|
||||||
*
|
*
|
||||||
@@ -66,7 +78,8 @@ export function HttpLoaderFactory(http: HttpClient) {
|
|||||||
HttpBackend,
|
HttpBackend,
|
||||||
LocationStrategy
|
LocationStrategy
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
missingTranslationHandler: { provide: MissingTranslationHandler, useClass: CustomMissingTranslationHandler }
|
||||||
}),
|
}),
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export class AddressTabComponent {
|
|||||||
|
|
||||||
for (let index = 0; index < this.clientAddressTemplate.addressTypeIdOptions.length; index++) {
|
for (let index = 0; index < this.clientAddressTemplate.addressTypeIdOptions.length; index++) {
|
||||||
this.clientAddressTemplate.addressTypeIdOptions[index].name = this.translateService.instant(
|
this.clientAddressTemplate.addressTypeIdOptions[index].name = this.translateService.instant(
|
||||||
`${this.clientAddressTemplate.addressTypeIdOptions[index].name}`
|
`labels.catalogs.${this.clientAddressTemplate.addressTypeIdOptions[index].name}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user