i18n-polyfill
i18n-polyfill copied to clipboard
i18n is too sensitive to formatting and whitespaces
Hello,
I'm dealing with issues how to translate enums in TypeScript code.
I found a way how to it, but it is too sensitive to formatting and whitespaces.
translations[1] = this.i18n({
id: id,
value: `{ value, select, selection {value} }`
}, { value: value});
translations[2] = this.i18n({
id: id,
value: `{value, select, selection {value} }`
}, { value: value});
Expression 2 works, but expression 1 doesn't. I guess it is because in xlf
file, it is like this: {VAR_SELECT, select, selection {value} }
. Just whitespaces can break it down :(
Would it be possible to ignore whitespaces in such an expression?
Also I have different enums in different contexts, sometimes in TypeScript, sometimes in template. I wanted to have some hint about context and use something like:
const messageStateValues = [ "READ", "UNREAD" ];
const translatedValues = messageStateValues.map(state => {
return this.i18n({
id: 'ENUM_MESSAGE_STATES',
value: `{state, select, messageState {state}`
}, { state: state});
});
But this cannot be used for any other enum (like UserRoles
).
So now instead of having some meaningful expression, I'm using this: {variable, select, selection {value}}
for all enums in whole application. It is the only way how to have it universal enough for real usage.
Could parser maybe ignore inside part of that expression (to always match it)? The best case scenario would be to have something like {VAR_SELECT, select}
- no real need for other parts, they will be inside translation file.