Skip to content

[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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rammba
Copy link
Contributor

@rammba rammba commented Nov 18, 2024

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:

const PRODUCTS = [
  {category: "Fruits", price: "$1", stocked: true, name: "Apple"},
  {category: "Fruits", price: "$1", stocked: true, name: "Dragonfruit"},
  {category: "Fruits", price: "$2", stocked: false, name: "Passionfruit"},
  {category: "Vegetables", price: "$2", stocked: true, name: "Spinach"},
  {category: "Vegetables", price: "$4", stocked: false, name: "Pumpkin"},
  {category: "Vegetables", price: "$1", stocked: true, name: "Peas"}
];

I saw that some other languages also have similar workaround:
French:
French

Spanish:
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

Copy link

vercel bot commented Nov 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
19-react-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 18, 2024 5:57pm
react-dev ✅ Ready (Inspect) Visit Preview Nov 18, 2024 5:57pm

Copy link

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@rammba
Copy link
Contributor Author

rammba commented Apr 19, 2025

Hey @gaearon @rickhanlonii @eps1lon, can you please take a look?

Copy link

@Parvezkhan0 Parvezkhan0 left a 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.

@rammba
Copy link
Contributor Author

rammba commented May 4, 2025

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.

@rickhanlonii
Copy link
Member

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 find lookup.

@rammba
Copy link
Contributor Author

rammba commented May 16, 2025

Hey @rickhanlonii, thanks for clarifying this topic. I didn't think about speed difference between find() and direct access by the key. If you agree I can incorporate French's solution here?

@rickhanlonii
Copy link
Member

Yeah please do, and that means we can close this?

@rammba
Copy link
Contributor Author

rammba commented May 17, 2025

Hey @rickhanlonii, I've incorporated French's solution here.

@rickhanlonii
Copy link
Member

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 tea is in english? Is there a blocker to this do to characters or something?

@rammba
Copy link
Contributor Author

rammba commented May 19, 2025

Hello @rickhanlonii,
As I said in the description: I didn't want to use non-english names of variables as in the spanish solution. For me it looks ugly to name variables with non-ASCII characters, while it's totally fine to have object data with those characters. But, if you prefer that way, I will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants