Reputation:
I am trying to work with angular localize on one project but I am confused about its usage. Lets say I have code like this.
$localize`:@@text-to-translate:IAmText}`
Now if I understand it correctly it first try to use translate from json file with key "text-to-translate" but if that file is unavailable it will use string "IAmText".
Now my question is. Its bad practice to use string instead of some fallback language file no? So instead of this should not I use something like this?
$localize`:@@text-to-translate:${someFallbackLanguage[text-to-translate]}}`
Because when I have string on many places and I need to change it I can forgot one place for example. Or is there any better approach in angular localize? Thanks for any suggestions.
Upvotes: 0
Views: 272
Reputation: 1
$localize`:@@title-component.app-title:I am a title`
In that expression, there are two parts, first is unique translation key which is title-component.app-title
(what ever you write between :@@
and :
. Second part is the actual string which you are rendering on ui.
After you run ng extract-i18n
, it will create the translation file. You can find your text by searching with unique id and modify the text but running the app will not pick this file automatically. You need to pass extra configurations with cli command. That means you can either display your default string text you have in your code or you can pick the translation file to render translated text.
You can find the explanation here: https://angular.io/guide/i18n-common-merge
Upvotes: 0