Introduction
Hello, I have an Angular+Ionic project and I'm using Transloco to translate some of the text.
The problem
I have a consts file that has strings inside and I want to be able to translate them in the same file but I don't know how to do this since I can't import the TranslocoService on a consts file.
The code
test.consts.ts
export const LABELS = {
hello_world: 'Hello World!',
goodbye: "Goodbye"
}
es.json
{
"label_1": "Hola mundo!",
"label_2": "Adios"
}
Alternatives
I thought about an alternatives in case it's not possible to translate on the consts file:
- Using the translation key instead of the phrase: For example replacing
Hello World!
withlabel_1
. Then when using the consts file I would have to translate the value, for example:this.translocoSrv.t(LABELS.label_1)
While this alternative works it would take a lot of time to implement. I would have to replace every consts file and refactor every component, template, etc. that uses the consts files.
Thanks in advance.