Skip to content

Commit

Permalink
umputun#10 translate vote messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 18, 2020
1 parent b6f7f93 commit bde6a9b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 16 deletions.
32 changes: 19 additions & 13 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { boundActions } from './connected-comment';
import { getPreview, uploadImage } from '@app/common/api';
import postMessage from '@app/utils/postMessage';
import { FormattedMessage, useIntl, IntlShape, defineMessages } from 'react-intl';
import { getVoteMessage, VoteMessagesTypes } from './getVoteMessage';

defineMessages({
'comment.delete-message': {
Expand Down Expand Up @@ -413,26 +414,31 @@ export class Comment extends Component<Props, State> {
* returns reason for disabled downvoting
*/
getDownvoteDisabledReason = (): string | null => {
if (!(this.props.view === 'main' || this.props.view === 'pinned')) return "Voting allowed only on post's page";
if (this.props.post_info!.read_only) return "Can't vote on read-only topics";
if (this.props.data.delete) return "Can't vote for deleted comment";
if (this.isCurrentUser()) return "Can't vote for your own comment";
if (StaticStore.config.positive_score && this.props.data.score < 1) return 'Only positive score allowed';
if (this.isGuest()) return 'Sign in to vote';
if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote";
const intl = this.props.intl;
if (!(this.props.view === 'main' || this.props.view === 'pinned'))
return getVoteMessage(VoteMessagesTypes.ONLY_POST_PAGE, intl);
if (this.props.post_info!.read_only) return getVoteMessage(VoteMessagesTypes.READONLY, intl);
if (this.props.data.delete) return getVoteMessage(VoteMessagesTypes.DELETED, intl);
if (this.isCurrentUser()) return getVoteMessage(VoteMessagesTypes.OWN_COMMENT, intl);
if (StaticStore.config.positive_score && this.props.data.score < 1)
return getVoteMessage(VoteMessagesTypes.ONLY_POSITIVE, intl);
if (this.isGuest()) return getVoteMessage(VoteMessagesTypes.GUEST, intl);
if (this.isAnonymous() && !StaticStore.config.anon_vote) return getVoteMessage(VoteMessagesTypes.ANONYMOUS, intl);
return null;
};

/**
* returns reason for disabled upvoting
*/
getUpvoteDisabledReason = (): string | null => {
if (!(this.props.view === 'main' || this.props.view === 'pinned')) return "Voting allowed only on post's page";
if (this.props.post_info!.read_only) return "Can't vote on read-only topics";
if (this.props.data.delete) return "Can't vote for deleted comment";
if (this.isCurrentUser()) return "Can't vote for your own comment";
if (this.isGuest()) return 'Sign in to vote';
if (this.isAnonymous() && !StaticStore.config.anon_vote) return "Anonymous users can't vote";
const intl = this.props.intl;
if (!(this.props.view === 'main' || this.props.view === 'pinned'))
return getVoteMessage(VoteMessagesTypes.ONLY_POST_PAGE, intl);
if (this.props.post_info!.read_only) return getVoteMessage(VoteMessagesTypes.READONLY, intl);
if (this.props.data.delete) return getVoteMessage(VoteMessagesTypes.DELETED, intl);
if (this.isCurrentUser()) return getVoteMessage(VoteMessagesTypes.OWN_COMMENT, intl);
if (this.isGuest()) return getVoteMessage(VoteMessagesTypes.GUEST, intl);
if (this.isAnonymous() && !StaticStore.config.anon_vote) return getVoteMessage(VoteMessagesTypes.ANONYMOUS, intl);
return null;
};

Expand Down
76 changes: 76 additions & 0 deletions frontend/app/components/comment/getVoteMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { IntlShape, defineMessages } from 'react-intl';

defineMessages({
'vote.own-comment': {
id: 'vote.own-comment',
defaultMessage: `Can't vote for your own comment`,
},
'vote.guest': {
id: 'vote.guest',
defaultMessage: 'Sign in to vote',
},
'vote.only-post-page': {
id: 'vote.only-post-page',
defaultMessage: `Voting allowed only on post's page`,
},
'vote.readonly': {
id: 'vote.readonly',
defaultMessage: `Can't vote on read-only topics`,
},
'vote.deleted': {
id: 'vote.deleted',
defaultMessage: `Can't vote for deleted comment`,
},
'vote.anonymous': {
id: 'vote.anonymous',
defaultMessage: `Anonymous users can't vote`,
},
'vote.only_positive': {
id: 'vote.only_positive',
defaultMessage: `Only positive score allowed`,
},
});

export enum VoteMessagesTypes {
OWN_COMMENT,
GUEST,
ONLY_POST_PAGE,
READONLY,
DELETED,
ANONYMOUS,
ONLY_POSITIVE,
}

export function getVoteMessage(type: VoteMessagesTypes, intl: IntlShape) {
const messages = {
[VoteMessagesTypes.OWN_COMMENT]: intl.formatMessage({
id: 'vote.own-comment',
defaultMessage: 'vote.own-comment',
}),
[VoteMessagesTypes.GUEST]: intl.formatMessage({
id: 'vote.guest',
defaultMessage: 'vote.guest',
}),
[VoteMessagesTypes.ONLY_POST_PAGE]: intl.formatMessage({
id: 'vote.only-post-page',
defaultMessage: 'vote.only-post-page',
}),
[VoteMessagesTypes.READONLY]: intl.formatMessage({
id: 'vote.readonly',
defaultMessage: 'vote.readonly',
}),
[VoteMessagesTypes.DELETED]: intl.formatMessage({
id: 'vote.deleted',
defaultMessage: 'vote.deleted',
}),
[VoteMessagesTypes.ANONYMOUS]: intl.formatMessage({
id: 'vote.anonymous',
defaultMessage: 'vote.anonymous',
}),
[VoteMessagesTypes.ONLY_POSITIVE]: intl.formatMessage({
id: 'vote.only_positive',
defaultMessage: 'vote.only_positive',
}),
};
return messages[type];
}
9 changes: 8 additions & 1 deletion frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
"comment.unverify-user": "Do you want to unverify {userName}?",
"commentForm.input-placeholder": "Your comment here",
"commentForm.notice-about-styling": "Styling with <a>Markdown</a> is supported",
"commentForm.subscribe-by": "Subscribe by"
"commentForm.subscribe-by": "Subscribe by",
"vote.own-comment": "Can't vote for your own comment",
"vote.guest": "Sign in to vote",
"vote.only-post-page": "Voting allowed only on post's page",
"vote.readonly": "Can't vote on read-only topics",
"vote.deleted": "Can't vote for deleted comment",
"vote.anonymous": "Anonymous users can't vote",
"vote.only_positive": "Only positive score allowed"
}
11 changes: 9 additions & 2 deletions frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"authPanel.show-settings": "Показать настройки",
"authPanel.enable-comments": "Включить комментарии",
"authPanel.disable-comments": "Выключить комментарии",
"authPanel.read-only": "Только чтение",
"authPanel.read-only": "Только для чтение",
"commentsSort.best": "Лучшие",
"commentsSort.worst": "Худшие",
"commentsSort.newest": "Новые",
Expand All @@ -40,5 +40,12 @@
"comment.unverify-user": "Do you want to unverify {userName}?",
"commentForm.input-placeholder": "Написать комментарий",
"commentForm.notice-about-styling": "Поддерживается <a>Markdown</a> форматирование",
"commentForm.subscribe-by": "Подписаться"
"commentForm.subscribe-by": "Подписаться",
"vote.own-comment": "Вы не можете голосовать за свои комментарии",
"vote.guest": "Войдите в систему для голосование",
"vote.only-post-page": "Голосование возожно только для статей",
"vote.readonly": "Нельзя головать за комментарии, которые в режиме только для чтения",
"vote.deleted": "Нельзя головать за удаленный комментарий",
"vote.anonymous": "Нельзя головать анонимному пользователю",
"vote.only_positive": "Разрешены только положительные оценки"
}

0 comments on commit bde6a9b

Please sign in to comment.