Skip to content
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

Refactor some files to i18n format instead of hardcoded string literals #5980

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import React from 'react';

export default ({ course }) => {
const findingLink = course.type === 'FellowsCohort' ? '/training/professional-development/finding-your-article-professional' : '/training/students/finding-your-article';
const evaluatingLink = course.type === 'FellowsCohort' ? '/training/professional-development/evaluating-articles-professional' : '/training/students/evaluating-articles';
const findingLink = course.type === 'FellowsCohort'
? '/training/professional-development/finding-your-article-professional'
: '/training/students/finding-your-article';
const evaluatingLink = course.type === 'FellowsCohort'
? '/training/professional-development/evaluating-articles-professional'
: '/training/students/evaluating-articles';

return (
<div>
<p>You have not chosen an article to work on. When you have found an article to work on, use the button above to assign it.</p>
<p>{I18n.t('articles.not_choosen_article')}</p>
<aside>
<a href="/training/students/keeping-track-of-your-work" target="_blank" className="button ghost-button">
How to use the Dashboard
<a
href="/training/students/keeping-track-of-your-work"
target="_blank"
className="button ghost-button"
>
{I18n.t('articles.use_dashboard')}
</a>
<a href={findingLink} target="_blank" className="button ghost-button">
How to find an article
{I18n.t('articles.how_to_find')}
</a>
<a href={evaluatingLink} target="_blank" className="button ghost-button">
Evaluating articles and sources
<a
href={evaluatingLink}
target="_blank"
className="button ghost-button"
>
{I18n.t('articles.evaluate_and_source')}
</a>
</aside>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import { HashLink as Link } from 'react-router-hash-link';
export const Header = ({ completed = false, course, remaining = [], text }) => (
<header className="header">
<h3 className={completed ? 'completed' : ''}>
{ text }
{
remaining.length
? <small>{remaining.length} additional exercises remaining.</small>
: null
}
{text}
{remaining.length ? (
<small>
{remaining.length} {I18n.t('training.remaining_exercise')}
Copy link
Member

Choose a reason for hiding this comment

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

Rather than concatenating the number with the message, this should be implemented as an argument to the message, so that translators have full control of how to handle the number within the message.

</small>
) : null}
</h3>
<Link
exact="true"
scroll={el => el.scrollIntoView({ block: 'center' })}
to={`/courses/${course.slug}/resources#exercises`} className="resources-link"
to={`/courses/${course.slug}/resources#exercises`}
className="resources-link"
>
View all exercises
{I18n.t('training.view_all_exercise')}
</Link>
</header>
);

Header.propTypes = {
course: PropTypes.shape({
slug: PropTypes.string.isRequired
slug: PropTypes.string.isRequired,
}).isRequired,
remaining: PropTypes.array,
text: PropTypes.string.isRequired
text: PropTypes.string.isRequired,
};

export default Header;
62 changes: 42 additions & 20 deletions app/assets/javascripts/components/resources/resources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const moduleByExercises = (modules) => {
MOVE_YOUR_WORK,
OTHER,
DISCUSSIONS,
EXERCISES
EXERCISES,
] = orderedSteps;
const mapping = {
'wikipedia-essentials': COMPLETE_YOUR_BIBLIOGRAPHY,
Expand All @@ -48,7 +48,7 @@ const moduleByExercises = (modules) => {
'did-you-know-exercise': EXERCISES,
'continue-improving-exercise': EXERCISES,
'in-class-presentation-exercise': EXERCISES,
'reflective-essay-exercise': EXERCISES
'reflective-essay-exercise': EXERCISES,
};

const categorized = modules.reduce((acc, block) => {
Expand All @@ -71,16 +71,28 @@ const Resources = ({ weeks, current_user, course }) => {
const trainingLibrarySlug = course.training_library_slug;
let instructorModulesLink;
if (current_user.isInstructor && Features.wikiEd) {
instructorModulesLink = <a href={'/training/instructors'} className="button pull-right">Instructor orientation modules</a>;
instructorModulesLink = (
<a href={'/training/instructors'} className="button pull-right">
{I18n.t('training.orientation_modules')}
</a>
);
}

const { blocks, modules } = getModulesAndBlocksFromWeeks(weeks);
let additionalResources;
const additionalResourcesBlocks = blocks.filter(block => block.kind === BLOCK_KIND_RESOURCES);
const additionalResourcesBlocks = blocks.filter(
block => block.kind === BLOCK_KIND_RESOURCES
);
if (additionalResourcesBlocks) {
additionalResources = (
<div className="list-unstyled container mt2 mb2">
{additionalResourcesBlocks.map(block => <Block key={block.id} block={block} trainingLibrarySlug={trainingLibrarySlug} />)}
{additionalResourcesBlocks.map(block => (
<Block
key={block.id}
block={block}
trainingLibrarySlug={trainingLibrarySlug}
/>
))}
</div>
);
}
Expand All @@ -89,26 +101,34 @@ const Resources = ({ weeks, current_user, course }) => {
const categorized = moduleByExercises(modules);
assignedModules = categorized.map(([title, categorizedModules]) => {
if (categorizedModules) {
return (<TrainingModules
block_modules={categorizedModules}
header={title}
isStudent={current_user.isStudent}
key={title}
trainingLibrarySlug={trainingLibrarySlug}
/>);
return (
<TrainingModules
block_modules={categorizedModules}
header={title}
isStudent={current_user.isStudent}
key={title}
trainingLibrarySlug={trainingLibrarySlug}
/>
);
}
return null;
}
);
});
}
let additionalModules;
if (Features.wikiEd) {
additionalModules = (
<a href={`/training/${trainingLibrarySlug}`} className="button pull-right ml1">Additional training modules</a>
<a
href={`/training/${trainingLibrarySlug}`}
className="button pull-right ml1"
>
{I18n.t('training.additional_training')}
</a>
);
} else {
additionalModules = (
<a href={'/training'} className="button dark mb1">{I18n.t('training.training_library')}</a>
<a href={'/training'} className="button dark mb1">
{I18n.t('training.training_library')}
</a>
);
}

Expand All @@ -122,16 +142,18 @@ const Resources = ({ weeks, current_user, course }) => {
{instructorModulesLink}
</div>
{additionalResources}
{ Features.wikiEd && <Videos /> }
{ Features.wikiEd && <Templates /> }
{ Features.wikiEd && <Handouts trainingLibrarySlug={trainingLibrarySlug} blocks={blocks} /> }
{Features.wikiEd && <Videos />}
{Features.wikiEd && <Templates />}
{Features.wikiEd && (
<Handouts trainingLibrarySlug={trainingLibrarySlug} blocks={blocks} />
)}
</div>
</div>
);
};

const mapStateToProps = state => ({
weeks: getWeeksArray(state)
weeks: getWeeksArray(state),
});

export default connect(mapStateToProps)(Resources);
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ en:
tracked_articles: Tracked Articles
view_articles: View Articles
no_tracked_articles: This category has no tracked articles
not_choosen_article: You have not chosen an article to work on. When you have found an
article to work on, use the button above to assign it.
use_dashboard: How to use the Dashboard
how_to_find: How to find an article
evaluate_and_source: Evaluating articles and sources

items:
items: Items
Expand Down Expand Up @@ -1384,6 +1389,8 @@ en:
previous: < Previous
table_of_contents: Table of Contents
training_library: Training Library
additional_training: Additional training modules
orientation_modules: Instructor orientation modules
logged_out: "You are logged out. You will not receive credit for completing this module unless you log in."
done: Done!
invalid: Sorry that slide does not exist!
Expand All @@ -1402,6 +1409,8 @@ en:
search_training_resources: Search for training resources
no_training_resource_match_your_search: No training resource matches your search
exercise_sandbox: Exercise Sandbox
remaining_exercise: additional exercises remaining.
view_all: View all exercises

update_username:
header: Update a changed username
Expand Down
Loading