0

I have a dynamic validation message from form controls and the message is from backend configuration. Is it possible to translate with angular ngx-translate?

<span> {{products.errors?.error | tanslate }} </span>- not works. This error is dynamic erros not able to define in json.

likewise for

there is a list of dropdown based on category dynamically from the server. is it possible to translate?

else

is it possible to update the translation en.json,es.json,fr.json files based on server values eg) consider usernames,roles ,permissions of logged user needs to be translate

Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71

1 Answers1

1

How I see the problem, try to find an api as google translate and send your message and language in which you need to be translated. (fantastic resolution)

https://www.npmjs.com/package/google-translate-api. I never used it, but from examples looks pretty friendly.

translate('I spea Dutch!', {from: 'en', to: 'nl'}).then(res => {
    console.log(res.text);
    //=> Ik spreek Nederlands!
    console.log(res.from.text.autoCorrected);
    //=> true
    console.log(res.from.text.value);
    //=> I [speak] Dutch!
    console.log(res.from.text.didYouMean);
    //=> false
}).catch(err => {
    console.error(err);
});

Realistic, you can map your server errors with numerotations: ERROR_1, ERROR_2, ERROR_3

and in your translate file (which I think is a json):

{ 
   ERROR_1: "mesage translated",
   ERROR_2: "another translated message",
   ERROR_3: "etc"
}

In client, save your errors in an errors list (string[]) and your html will become:

<span *ngFor="let error of errors">
 {{error | translate}}
</span>
AlleXyS
  • 2,476
  • 2
  • 17
  • 37
  • is there any angular google translate API if have need to use ngx-translate – Mohamed Sahir Jun 02 '20 at 08:20
  • google translate 1 year free after that subscription ($300 credit for free Sign up and get $300 to spend on Google Cloud Platform over the next 12 months.) , its not allowed in organization levels any other option – Mohamed Sahir Jun 11 '20 at 17:13