简体   繁体   English

ngx-translate angular5自定义元素

[英]ngx-translate angular5 custom elements

i am trying to translate an application, where jointjs is used to create elements. 我正在尝试翻译一个应用程序,其中jointjs用于创建元素。 If the custom element template contains ex: {{ 'EXAMPLE' | translate }} 如果自定义元素模板包含ex: {{ 'EXAMPLE' | translate }} {{ 'EXAMPLE' | translate }} then it is displayed as {{ 'EXAMPLE' | translate }} {{ 'EXAMPLE' | translate }}然后显示为{{ 'EXAMPLE' | translate }} {{ 'EXAMPLE' | translate }} and is not translated. {{ 'EXAMPLE' | translate }}且未翻译。 Is there any solution to generate component before the ngx-translate is done? 在ngx-translate完成之前,有什么解决方案可以生成组件吗? Thank you 谢谢

EDIT having TS class ElementBuilder which builds with the jointjs the elemet having TS class with HTML template ExampleElement which inherits from ElementBuilder in the template of ExampleElement is used the: {{ 'EXAMPLE' | translate }} EDIT具有TS类ElementBuilder与具有与HTML模板TS类elemet的jointjs构建ExampleElement从继承ElementBuilder用于在ExampleElement的模板{{ 'EXAMPLE' | translate }} {{ 'EXAMPLE' | translate }} which is not translated. {{ 'EXAMPLE' | translate }} ,但未翻译。

Try 1: Added to constructors the TranslateService , and when calling the ExampleElement the translateService is passed. 尝试1:向构造函数添加TranslateService ,并在调用ExampleElement时传递translateService。 Nothing changes, it is not translated 没有任何变化,它不会翻译

You can for example somewhere in assets to create a folder and into the folder which language you need and then in the ts file call the ngx-translate 例如,您可以在资产中的某个地方创建一个文件夹,并在文件夹中使用所需的语言,然后在ts文件中调用ngx-translate

Here is one example for the translate what I have done. 这是我所做的翻译的一个示例。 Code in the assets 资产中的代码

English Language the file need to be json file 英文文件必须是json文件

{
  "button": {
    "#save": "Save",
    "#cancel": "Cancel"
}
}

Deutschland sprache Deutschland sprache

{
  "button": {
    "#save": "Speichern",
    "#cancel": "Abbrechen"
  }
}

You need to define in constructor of the TS file 您需要在TS文件的构造函数中定义

constructor(private translate: TranslateService) {}

Html Code HTML代码

<button matTooltip="{{'button.#add' | translate}}" matTooltipPosition="below">&nbsp;
</button>

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

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