react-localization icon indicating copy to clipboard operation
react-localization copied to clipboard

JSX.Element causes app crash at start: Uncaught TypeError: Cannot assign to read only property key of object '#Object''

Open timobaehr opened this issue 6 years ago • 4 comments

If I (1) place a JSX.Element instead of a string for a language item and (2) the browser language is set to the second language of the dictionary (here en), the React app is unable to start. If the language is set to the first language specified in the dictionary, the JSX.Element is succesfully shown.

key 'gutterBottom' not found in localizedStrings for language en
key 'noWrap' not found in localizedStrings for language en
key 'paragraph' not found in localizedStrings for language en
Uncaught TypeError: Cannot assign to read only property key of object '#Object''

The problematic code:

de: {
  helloWorld: <Typography style={styles.fontStyleText}>
      Hallo <i>Welt</i>
  </Typography>,
},
en: {
  helloWorld: <Typography style={styles.fontStyleText}>
      Hello <i>World</i>
  </Typography>,
}

If I change this line to simple string App is able to start:

en: {
  helloWorld: 'Hello <i>World</i>'
},

timobaehr avatar Jun 28 '18 15:06 timobaehr

I'm also having this issue. Has this ever been addressed?

jurcaua avatar Apr 08 '19 02:04 jurcaua

I just encountered this issue as well. Was able to temporarily workaround using dangerouslySetInnerHTML.

AubreyF avatar May 31 '19 21:05 AubreyF

In case anybody is still having this issue, I just solved it by making the value a function instead of putting the JSX chunk directly for the string property.

Hope this helps!

en: {
  helloWorld: () => <Typography style={styles.fontStyleText}>
      Hello <i>World</i>
  </Typography>,
}

damitsu avatar Nov 28 '20 07:11 damitsu

In case anybody is still having this issue, I just solved it by making the value a function instead of putting the JSX chunk directly for the string property.

Hope this helps!

en: {
  helloWorld: () => <Typography style={styles.fontStyleText}>
      Hello <i>World</i>
  </Typography>,
}

Not working for me:

export const strings = new LocalizedStrings({
 English: {
   price: () => <div>price</div>,
 },
 Hebrew: {
   price: () => <div>מחיר</div>,
 }
});

mgoldenbe avatar Nov 23 '21 16:11 mgoldenbe