Skip to content

Commit

Permalink
Translate group description, sidebar & edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Nov 11, 2017
1 parent bf72560 commit 7e4f03d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 22 deletions.
14 changes: 12 additions & 2 deletions src/components/Groups/GroupDetail/GroupDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import Box from '../../widgets/Box';
import SupervisorsList from '../../Users/SupervisorsList';
import { MaybeSucceededIcon } from '../../icons';
import GroupTree from '../GroupTree';
import { getLocalizedName } from '../../../helpers/getLocalizedData';
import {
getLocalizedName,
getLocalizedDescription
} from '../../../helpers/getLocalizedData';

const GroupDetail = ({
group: {
Expand Down Expand Up @@ -43,7 +46,14 @@ const GroupDetail = ({
defaultMessage="Group description"
/>
}
description={<ReactMarkdown source={description} />}
description={
<ReactMarkdown
source={getLocalizedDescription(
{ description, localizedTexts },
locale
)}
/>
}
type="primary"
collapsable
noPadding
Expand Down
1 change: 1 addition & 0 deletions src/components/forms/EditGroupForm/EditGroupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const EditGroupForm = ({
name="localizedTexts"
localizedTexts={localizedTexts}
component={LocalizedTextsFormField}
isGroup={true}
/>

<Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TextField
} from '../Fields';

const LocalizedTextFormField = ({ prefix }) =>
const LocalizedExerciseFormField = ({ prefix }) =>
<div>
<Field
name={`${prefix}.name`}
Expand Down Expand Up @@ -55,8 +55,8 @@ const LocalizedTextFormField = ({ prefix }) =>
/>
</div>;

LocalizedTextFormField.propTypes = {
LocalizedExerciseFormField.propTypes = {
prefix: PropTypes.string.isRequired
};

export default LocalizedTextFormField;
export default LocalizedExerciseFormField;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Field } from 'redux-form';
import {
MarkdownTextAreaField,
LanguageSelectField,
TextField
} from '../Fields';

const LocalizedGroupFormField = ({ prefix }) =>
<div>
<Field
name={`${prefix}.name`}
component={TextField}
label={
<FormattedMessage
id="app.editGroupForm.localized.name"
defaultMessage="Name:"
/>
}
/>

<Field
name={`${prefix}.locale`}
component={LanguageSelectField}
label={
<FormattedMessage
id="app.editGroupForm.localized.locale"
defaultMessage="The language:"
/>
}
/>

<Field
name={`${prefix}.description`}
component={MarkdownTextAreaField}
label={
<FormattedMessage
id="app.editGroupForm.description"
defaultMessage="Group description:"
/>
}
/>
</div>;

LocalizedGroupFormField.propTypes = {
prefix: PropTypes.string.isRequired
};

export default LocalizedGroupFormField;
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,52 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { TabbedArrayField } from '../Fields';
import LocalizedTextFormField from './LocalizedTextFormField';
import LocalizedExerciseFormField from './LocalizedExerciseFormField';
import LocalizedGroupFormField from './LocalizedGroupFormField';

const LocalizedTextsFormField = ({ localizedTexts = [], ...props }) => (
const LocalizedTextsFormField = ({
localizedTexts = [],
isGroup = false,
...props
}) =>
<TabbedArrayField
{...props}
getTitle={i =>
localizedTexts && localizedTexts[i] && localizedTexts[i].locale
? localizedTexts[i].locale
: <FormattedMessage
id="app.editAssignmentForm.newLocale"
id="app.editLocalizedTextForm.newLocale"
defaultMessage="New language"
/>}
ContentComponent={LocalizedTextFormField}
ContentComponent={
isGroup ? LocalizedGroupFormField : LocalizedExerciseFormField
}
emptyMessage={
<FormattedMessage
id="app.editAssignmentForm.localized.noLanguage"
defaultMessage="There is currently no text in any language for this assignment."
id="app.editLocalizedTextForm.localized.noLanguage"
defaultMessage="There is currently no text in any language."
/>
}
addMessage={
<FormattedMessage
id="app.editAssignmentForm.addLanguage"
id="app.editLocalizedTextForm.addLanguage"
defaultMessage="Add language variant"
/>
}
removeQuestion={
<FormattedMessage
id="app.editAssignmentForm.localized.reallyRemoveQuestion"
defaultMessage="Do you really want to delete the assignmenet in this language?"
id="app.editLocalizedTextForm.localized.reallyRemoveQuestion"
defaultMessage="Do you really want to delete this localization?"
/>
}
id="localized-assignments"
id="localized-texts"
add
remove
/>
);
/>;

LocalizedTextsFormField.propTypes = {
localizedTexts: PropTypes.array
localizedTexts: PropTypes.array,
isGroup: PropTypes.bool
};

export default LocalizedTextsFormField;
18 changes: 14 additions & 4 deletions src/components/widgets/Sidebar/MenuGroup/MenuGroup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl } from 'react-intl';
import classNames from 'classnames';
import Icon from 'react-fontawesome';
import MenuItem from '../MenuItem';
import LoadingMenuItem from '../LoadingMenuItem';
import { isLoading } from '../../../../redux/helpers/resourceManager';
import { getLocalizedName } from '../../../../helpers/getLocalizedData';

class MenuGroup extends Component {
componentWillMount = () =>
Expand Down Expand Up @@ -43,7 +45,8 @@ class MenuGroup extends Component {
createLink,
currentPath,
notifications,
forceOpen = false
forceOpen = false,
intl: { locale }
} = this.props;

const dropdownStyles = {
Expand Down Expand Up @@ -91,7 +94,13 @@ class MenuGroup extends Component {
? <LoadingMenuItem key={key} />
: <MenuItem
key={key}
title={item.getIn(['data', 'name'])}
title={getLocalizedName(
{
name: item.getIn(['data', 'name']),
localizedTexts: item.getIn(['data', 'localizedTexts'])
},
locale
)}
icon="circle-o"
currentPath={currentPath}
notificationsCount={itemsNotificationsCount(item)}
Expand All @@ -112,11 +121,12 @@ MenuGroup.propTypes = {
currentPath: PropTypes.string,
forceOpen: PropTypes.bool,
createLink: PropTypes.func.isRequired,
notifications: PropTypes.object
notifications: PropTypes.object,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

MenuGroup.contextTypes = {
isActive: PropTypes.func
};

export default MenuGroup;
export default injectIntl(MenuGroup);

0 comments on commit 7e4f03d

Please sign in to comment.