Home:ALL Converter>ngx-translate translating in all children components of the module

ngx-translate translating in all children components of the module

Ask Time:2019-05-15T10:55:53         Author:user824624

Json Formatter

I am currently using ngx-translate on the angular 7. My project is translating two languages, english and chinese, the project is composed of the structure as showed below, A.component is the parent component and B.component is the children component.

module A

    {
      componentB:{
         B.component.ts
         ....
      },
      A.component.ts
      A.module.ts
      .... 
    }

export class BComponent implements OnInit{

  constructor(private translate: TranslateService
              ) {
        translate.addLangs(['zh-CN', 'en']);
        translate.use('zh-CN');
  }
}

the code above is working to translate.

But if the above code is only added to A.component but not B.component. the translation will not happen on the B.component.

I wonder if there is the way to have the code added to parent component of the module, and all the following children components can automatically translate without putting the code in each children component.

Author:user824624,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56141165/ngx-translate-translating-in-all-children-components-of-the-module
yy