Built-in Angular translation engine supports (so-far) only translation within templates, so you might think it's not possible to translate parts of...
For further actions, you may consider blocking this person and/or reporting abuse
I have gotten the ICU approach working, but I've come across another problem, I would like to have a hover title on my enum. Do you have any idea how to accomplish that? I've tried everything I could think of.
Right, it might cause duplication in ICU approach. I'd go with first solution then.
Notes:
<ng-container>anymore withtitleattribute. I went with<span>i18n-titleto translate attributeIvy update
If you use Ivy (and the best Angular 11.2+), there is new package
@angular/localize, that can translate strings in TypeScript.So you could have re-usable function for providing messages:
Wow, thanks for the really quick reply!
I thought that the first approach is not suitable for const enum, and since our company prefers using const enums I would rather not change that. Do you know any other way? If not, I will use the first approach anyway.
We don't use Ivy unfortunately.
Yep, it has to be regular enum.
I also maintain practice to keep const enum, but they do not fit in every use case. Overhead is slightly bigger but not crazy
Ok I will change it to a regular enum. Thank you for your help!
This is one nice approach ! One minor detail, though - can this default value in ngSwitch might lead to hide new untranslated enum values?
For third final note, I imagine test enumerating through all enum values that reminds us about new values to translate.
for enums that tends to change or grow, we write unit tests that iterate over enum and make sure all values are included.
Example could be as simple as: