Resources and Prep titles made translatable - #47972
Conversation
| )} | ||
| {this.props.objectToRollUp === 'Prep' && ( | ||
| <div style={styles.object}> | ||
| <h4>{i18n.preparation()}</h4> |
There was a problem hiding this comment.
This is a nitpick for sure so feel free to leave it as is.
The only value that seems to be changing is the text so I think you could have the logic wrap only the text instead of the entire div and child element like this:
<div style={styles.object}>
<h4>
{this.props.objectToRollUp === 'Resources' && i18n.resources()}
{this.props.objectToRollUp === 'Prep' && i18n.preparation()}
</h4>
</div>
Also just double check that renders properly with that syntax (I didn't test it)
There was a problem hiding this comment.
You would still need to not render the <div> if the objectToRollUp was not one of the two, so you would need the original guard.
There was a problem hiding this comment.
Hm. Maybe for now just (does the linter allow it?):
(this.props.objectToRollUp === 'Resources' ||
this.props.objectToRollUp === 'Prep') && (
<div style={styles.object}>
<h4>
{this.props.objectToRollUp === 'Resources' ? i18n.resources() : i18n.preparation()}
</h4>
</div>
)
If the i18n keys were the same (or could make "Prep" into "Preparation"), it could be simply {i18n[this.props.objectToRollUp.toLowerCase()]()}, lol.
React sure makes this messy! The actual "proper" thing might be to try to have a render function for each type and have the content and negotiation be separate. And maybe have functions like isResources() to capture the === so those aren't everywhere. I dunno!
smusoke
left a comment
There was a problem hiding this comment.
Assuming you tested the new change looks good to me! 👍
yeah! I double checked and flipped the titles to make sure it was still working. |
What: Making Resources and Prep titles translatable. The strings already existed in the common.json file, In order to render the titles, instead of rendering the this.props.objectToRollUp value, depending on the value (this.props.objectToRollUp === 'Prep' or this.props.objectToRollUp === 'Resources'), the corresponding i18n string is rendered.
Why: As part of the CSD translatability project, all the content and elements of the course resources needed to be translatable.
Links
Testing story
Titles render translations:
