Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda