程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了MissingTranslationHandler 未调用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决MissingTranslationHandler 未调用?

开发过程中遇到MissingTranslationHandler 未调用的问题如何解决?下面主要结合日常开发的经验,给出你关于MissingTranslationHandler 未调用的解决方法建议,希望对你解决MissingTranslationHandler 未调用有所启发或帮助;

我的 app.module.ts 的一部分

import { MissingTranslationHandler,MissingTranslationHandlerParams,TranslateLoader,TranslateModule } from '@ngx-translate/core';

export class MymissingTranslationHandler implements MissingTranslationHandler {

  handle(param: MissingTranslationHandlerParams) {
    console.log('handle',param);
  }
}

registerLocaleData(localeDe,'de');

export function httpLoaderFactory(http: httpClIEnt) {
  return new TranslatehttpLoader(http);
}

@NgModule({
  declarations: [
    AppComponent
  ],imports: [
    TranslateModule.forRoot({
      loader: {
        provIDe: TranslateLoader,useFactory: httpLoaderFactory,deps: [httpClIEnt]
      },missingTranslationHandler: {
        provIDe: MissingTranslationHandler,useClass: MymissingTranslationHandler,}
    }),],provIDers: [PreloadStrategy,{provIDe: LOCALE_ID,useValue: getUserLocale()},{provIDe: APP_INITIAliZER,useFactory: initializeApp,deps: [Subscriptionservice,Authservice],multi: truE}
  ],bootstrap: [AppComponent]
})
export class AppModule {
}

handle(param: MissingTranslationHandlerParams) 不会被调用。

在组件级设置 @H_151_5@missingTranslationHandler 有效,例如:

@Component({
  SELEctor: 'app-projects',templateUrl: './projects.component.HTML',styleUrls: ['./projects.component.sCSS'],})
export class ProjectsComponent implements OnInit,OnDestroy {

  constructor(private translate: TranslateservicE) {
    this.translateservice.missingTranslationHandler = new class extends MissingTranslationHandler {
      handle(params: MissingTranslationHandlerParams): any {
        console.log('handle',params);
      }
    };
  }

如何让 @H_151_5@missingTranslationHandler 应用广泛运行?

解决方法

@H_801_26@

制作文件translate-handler.ts

import {MissingTranslationHandler,MissingTranslationHandlerParams} from '@ngx-translate/core';
import {environment} from '../../environments/environment';

export class TranslateHandler implements MissingTranslationHandler {
  private response = '';
  handle(params: MissingTranslationHandlerParams) {
    if (!environment.production) {
      console.error(`No Translation! Key: ${params.key},Lang: ${params.translateservice.currentLang}`);
    }
    return this.response;
  }
}

app.module.ts中:

@NgModule({
    imports: [
        ...,TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,useFactory: (httpLoaderFactory),deps: [httpClient]
            },isolate: false,missingTranslationHandler: [{provide: MissingTranslationHandler,useClass: TranslateHandler}]
        }),]
})
export class AppModule {}

用于即时方法go here

大佬总结

以上是大佬教程为你收集整理的MissingTranslationHandler 未调用全部内容,希望文章能够帮你解决MissingTranslationHandler 未调用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。