Skip to content

Commit

Permalink
umputun#10 translate user info
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 22, 2020
1 parent b4402de commit c848581
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
23 changes: 19 additions & 4 deletions frontend/app/components/user-info/user-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ import { AvatarIcon } from '../avatar-icon';
import postMessage from '@app/utils/postMessage';
import { bindActions } from '@app/utils/actionBinder';
import { useActions } from '@app/hooks/useAction';
import { useIntl, defineMessages, FormattedMessage, IntlShape } from 'react-intl';

const boundActions = bindActions({ fetchInfo });

const messages = defineMessages({
unexpectedError: {
id: 'user-info.unexpected-error',
defaultMessage: 'Something went wrong',
},
});

type Props = {
comments: Comment[] | null;
} & typeof boundActions;
} & typeof boundActions & { intl: IntlShape };

interface State {
isLoading: boolean;
Expand All @@ -36,7 +44,7 @@ class UserInfo extends Component<Props, State> {
this.setState({ isLoading: false });
})
.catch(() => {
this.setState({ isLoading: false, error: 'Something went wrong' });
this.setState({ isLoading: false, error: this.props.intl.formatMessage(messages.unexpectedError) });
});
}

Expand All @@ -60,7 +68,13 @@ class UserInfo extends Component<Props, State> {
return (
<div className={b('user-info', {})}>
<AvatarIcon mix="user-info__avatar" picture={user.picture} />
<p className="user-info__title">Last comments by {user.name}</p>
<p className="user-info__title">
<FormattedMessage
id="user-info.last-comments"
defaultMessage="Last comments by {userName}"
values={{ userName: user.name }}
/>
</p>
<p className="user-info__id">{user.id}</p>

{!!comments && <LastCommentsList isLoading={isLoading} comments={comments} />}
Expand All @@ -85,5 +99,6 @@ const commentsSelector = (state: StoreState) => state.userComments![userInfo.id!
export const ConnectedUserInfo: FunctionComponent = () => {
const comments = useSelector(commentsSelector);
const actions = useActions(boundActions);
return <UserInfo comments={comments} {...actions} />;
const intl = useIntl();
return <UserInfo comments={comments} {...actions} intl={intl} />;
};
4 changes: 3 additions & 1 deletion frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@
"commentForm.subscribe-or": "or",
"root.show-more": "Show more",
"root.pinned-comments": "Pinned comments",
"root.powered-by": "Powered by <a>Remark42</a>"
"root.powered-by": "Powered by <a>Remark42</a>",
"user-info.unexpected-error": "Something went wrong",
"user-info.last-comments": "Last comments by {userName}"
}
4 changes: 3 additions & 1 deletion frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@
"commentForm.subscribe-or": "или",
"root.show-more": "Показать ещё",
"root.pinned-comments": "Закреплённые комментарии",
"root.powered-by": "Powered by <a>Remark42</a>"
"root.powered-by": "Powered by <a>Remark42</a>",
"user-info.unexpected-error": "Something went wrong",
"user-info.last-comments": "Последние комментарии {userName}"
}

0 comments on commit c848581

Please sign in to comment.