Home > Back-end >  Angular Translation Service
Angular Translation Service

Time:10-14

I would like to translate wordings from eng to chinese using a key-value mapping approach with angular translation service but i failed. Any ideas??

mapping json:

"At most {{ number }} wrods":"最多輸入{{ number }}字": 

In typescript:

import { TranslateService } from '@ngx-translate/core';
...
this.translate = injector.get(TranslateService);
....
this.translate.instant(`At most ${50} wrods`);

CodePudding user response:

Thx for the help but i figured out the solution.

sol:

this.translate.instant('At most {{ number }} words.', {
                    number: 300,
                }),

//in mapping json

"At most {{ number }} words.":"最多輸入{{ number }}字。",

CodePudding user response:

mapping-en.json:

{
  "AT_MOST_X_WORDS": "At most {{ number }} words"
}

mapping-zh.json:

{
  "AT_MOST_X_WORDS": "最多輸入{{ number }}字"
}
console.log(this.translate.instant('AT_MOST_X_WORDS', {number: 50}));
// 最多輸入50字

  • Related