Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

331
Views
i18n Translate.instant with parameters

I need to use TranslateService.instant from ngx-core and pass parameters to do string interpolation.
So far I've done:

MY_STRING: "Welcome {{user}}"

In my component I do:

translateService.instant(MY_STRING, {user: 'Nick'})

and what I get from this is:

Welcome {{user}}

The parameter user is not interpolated. What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For using the instant method, you have to be sure that your translations have been loaded and it is safe to use it, if not it will fail. That may be the point.

The explanation is simple, you have three ways of loading the translation:

  • You are sure that your translation files are already loaded and don't need updates: translate.instant('key')

  • You are not sure about the loading and don't need updates (returns an Observable to subscribe): translate.get('key')

  • You want updates when user is changing the language:
    translate.stream('key')

I think that you might use the get option, as is the one with less known bugs:

let userName = 'Nick'     
translateService.get('MY_STRING', { user: this.userName }).subscribe((text:string) => {console.log(text});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!