-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[conditional-rendering] Make object data easier for translation #7296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[conditional-rendering] Make object data easier for translation #7296
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
Hey @gaearon @rickhanlonii @eps1lon, can you please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional rendering page in React documentation contains object data (like lists of products or drinks), where object names (e.g., "Apple", "Tea") are being used directly within the code. These object names are part of the data, but they are not treated as translatable content.
This becomes a problem when trying to translate the content for different languages.
On many places object data are used within the code, but on other places it's possible to translate object content, which is not the case here. |
What's wrong with the French language solution, isn't this how you would write it if you were writing it yourself? Using a normalized data structure is better here if possible since you don't need the slower |
Hey @rickhanlonii, thanks for clarifying this topic. I didn't think about speed difference between |
Yeah please do, and that means we can close this? |
Hey @rickhanlonii, I've incorporated French's solution here. |
Ok sorry, I said the French version but I meant the Spanish version. For native speakers, wouldn't you want to write: <Drink name="name-in-your-language" /> Not <Drink name="tea" /> Since |
Hello @rickhanlonii, |
While translating conditional-rendering page I encountered one small issue. Namely, last (3rd) challenge solution has list of objects in the code which are referenced by its names. Name of the object is not the property of the object, so I needed to make workaround. Since I'm trying to translate all the text, including object property values, I needed to introduce
name
field to the object, similar to the example at the end of thinking-in-react page:I saw that some other languages also have similar workaround:

French:
Spanish:

I didn't want to use either english names as in the french solution nor non-english names of variables as in the spanish solution. My idea was to have all functions/variables/etc. in english and all object values on my mother tongue, Serbian. I've made this PR based on the changes in Serbian repository: reactjs/sr.react.dev#99