Skip to content

Resources and Prep titles made translatable - #47972

Merged
mgc1194 merged 2 commits into
stagingfrom
fnd-2079-resources-prep-titles-translatable
Sep 9, 2022
Merged

Resources and Prep titles made translatable#47972
mgc1194 merged 2 commits into
stagingfrom
fnd-2079-resources-prep-titles-translatable

Conversation

@mgc1194

@mgc1194 mgc1194 commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

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:
Screen Shot 2022-09-07 at 16 39 39

)}
{this.props.objectToRollUp === 'Prep' && (
<div style={styles.object}>
<h4>{i18n.preparation()}</h4>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wilkie wilkie Sep 7, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 smusoke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you tested the new change looks good to me! 👍

@mgc1194

mgc1194 commented Sep 7, 2022

Copy link
Copy Markdown
Contributor Author

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.

@wilkie wilkie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mgc1194
mgc1194 merged commit ac49f4d into staging Sep 9, 2022
@mgc1194
mgc1194 deleted the fnd-2079-resources-prep-titles-translatable branch September 9, 2022 10:39
@mgc1194 mgc1194 added the translate-csd Has to do with the CSD localization epic! label Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

translate-csd Has to do with the CSD localization epic!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants