简体   繁体   English

用ngx-translate翻译Kendo-UI网格

[英]Translating Kendo-UI grid with ngx-translate

I've got a problem with translating Kendo-UI grid component by ngx-translate. 我在通过ngx-translate转换Kendo-UI网格组件时遇到问题。

There's part of my code. 我的代码有一部分。 I created a grid component which just contains basic showcase of our grid component. 我创建了一个网格组件,其中仅包含我们的网格组件的基本展示。

Then I added into assets/i18n/en.json our translations. 然后,我将翻译添加到asset / i18n / en.json中。 And I wrote a service which extends MessageService from Kendo-UI: code 我写了一个从Kendo-UI扩展MessageService的服务:代码

export class CustomMessageService extends MessageService {

  constructor(@Injectable() private translateService: TranslateService) {
    super();
  }

  get(key: string): string {
    return (this.translateService.instant(key) as any).value;
  }
}

and inside app.module I used this service instead of their service (same as in docs) 在app.module内部,我使用了此服务而不是其服务(与docs中的相同)

  providers: [
    {
      provide: MessageService,
      useClass: CustomMessageService
    }],

And there's a problem. 还有一个问题。 Just get method inside CustomMessageService doesn't see my translates. 只是CustomMessageService中的get方法看不到我的翻译。

Stackblitz: https://stackblitz.com/edit/angular-u7aeks Stackblitz: https ://stackblitz.com/edit/angular-u7aeks

I don't know why I cannot translate it properly. 我不知道为什么我不能正确翻译它。 Any solutions? 有什么办法吗?

TLTR: load locales before use instant TLTR:在使用即时之前加载语言环境

translateService.instant is sync but you need to be sure that your translations already loaded. translateService.instant已同步,但是您需要确保已加载翻译。

I've fix your example here. 我在这里修正了您的示例。 https://stackblitz.com/edit/angular-pcipfd https://stackblitz.com/edit/angular-pcipfd

It's based on this comment https://github.com/ngx-translate/core/issues/517#issuecomment-299637956 它基于此评论https://github.com/ngx-translate/core/issues/517#issuecomment-299637956

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM