Core: Send interpolateParams correctly inside instant function

Created on 5 Feb 2018  路  2Comments  路  Source: ngx-translate/core

I'm submitting a ...
[x] support request

Current behavior

Do you know if I can do something like this ?

let max = 35.99;
let message = this.translate.instant('Maximum amount allowed is {{max}}', { max: max });

When I run console.log(message); I get "Maximum amount allowed is {{max}}"
instead "Maximum amount allowed is 35.99"

I just trying to use "instant" inside a component., but I don't know if I am sending the interpolateParams correctly.

Expected/desired behavior

let max = 35.99;
let message = this.translate.instant('Maximum amount allowed is {{max}}', { max: max });

Output after console.log(message) => "Maximum amount allowed is 35.99"

  • ngx-translate version: 8.0.0
  • Angular version: 5.1.3

Most helpful comment

what you ask make no sense with this library, interpolation will only work with keys, i mean for example
en.json:

{
    //other keys
    "max": "Maximum amount allowed is {{max}}"
}

then in typescript:

let message = this.translate.instant('max', {max: 35.99});
console.log(message); // this should display "Maximum amount allowed is 35.99"

All 2 comments

what you ask make no sense with this library, interpolation will only work with keys, i mean for example
en.json:

{
    //other keys
    "max": "Maximum amount allowed is {{max}}"
}

then in typescript:

let message = this.translate.instant('max', {max: 35.99});
console.log(message); // this should display "Maximum amount allowed is 35.99"

i think that what you need is something like:

let max = 35.99; // or whatever value you want to set here (even a server response if were the case)
let message = `Maximum amount allowed is ${max}`;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Snap252 picture Snap252  路  3Comments

gmquiroga picture gmquiroga  路  3Comments

madoublet picture madoublet  路  3Comments

IterationCorp picture IterationCorp  路  3Comments

guysan picture guysan  路  4Comments