i18n-polyfill icon indicating copy to clipboard operation
i18n-polyfill copied to clipboard

i18n is too sensitive to formatting and whitespaces

Open klinki opened this issue 6 years ago • 0 comments

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.

klinki avatar May 29 '18 13:05 klinki