Angular 2 - Translate string with other string to translate as it's param

Viewed 98

I want to display a translated title, like: "Status of my dog"

I want to translate "Status of my {{param}}" and "dog" independently, because maybe in some language it should be displayed as "My dog status" (order changed).

I achived it by doing two separate translations - one in html and one in ts:

html:

{{'TITLE' | translate: {param: getParam()} }}

ts:

getParam(): string {
  return this.translateService.instant(this.param.name); // where param = {name: 'DOG'}
}

and the translation strings are (example for english):

"TITLE": "Status of my {{param}}"
"DOG": "dog"

It works fine, but I was wondering - is it maybe doable by doing only translation in html file, with maybe some additional things in translate?

Like...

{{'TITLE' | translate: {param: param.name | translate} }}

?

1 Answers

Well, looks like I should try the intuitive solution before postion a question.

The answer is just like I guessed above:

{{'TITLE' | translate: {param: param.name | translate} }}
Related