Skip to content

Commit

Permalink
umputun#10 translate comment form
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 22, 2020
1 parent 302fbaa commit 05ae8cf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
37 changes: 30 additions & 7 deletions frontend/app/components/comment-form/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ const messages = defineMessages({
id: 'commentForm.uploading-file',
defaultMessage: 'uploading {fileName}...',
},
exceededSize: {
id: 'commentForm.exceeded-size',
defaultMessage: '{fileName} exceeds size limit of {maxImageSize}',
},
newComment: {
id: 'commentForm.new-comment',
defaultMessage: 'New comment',
},
unexpectedError: {
id: 'commentForm.unexpected-error',
defaultMessage: 'Something went wrong. Please try again a bit later.',
},
});

export class CommentForm extends Component<Props, State> {
Expand Down Expand Up @@ -282,7 +294,12 @@ export class CommentForm extends Component<Props, State> {
const placeholderStart = this.state.text.length === 0 ? '' : '\n';

if (file.size > StaticStore.config.max_image_size) {
this.appendError(`${file.name} exceeds size limit of ${maxImageSizeString}`);
this.appendError(
intl.formatMessage(messages.exceededSize, {
fileName: file.name,
maxImageSize: maxImageSizeString,
})
);
continue;
}

Expand Down Expand Up @@ -327,7 +344,12 @@ export class CommentForm extends Component<Props, State> {
};

if (file.size > StaticStore.config.max_image_size) {
this.appendError(`${file.name} exceeds size limit of ${maxImageSizeString}`);
this.appendError(
intl.formatMessage(messages.exceededSize, {
fileName: file.name,
maxImageSize: maxImageSizeString,
})
);
continue;
}

Expand Down Expand Up @@ -367,7 +389,8 @@ export class CommentForm extends Component<Props, State> {
reply: <FormattedMessage id="commentForm.replay" defaultMessage="Replay" />,
};
const label = buttonText || Labels[props.mode || 'main'];
const placeholderMessage = this.props.intl.formatMessage(messages.placeholder);
const intl = this.props.intl;
const placeholderMessage = intl.formatMessage(messages.placeholder);
return (
<form
className={b('comment-form', {
Expand All @@ -379,7 +402,7 @@ export class CommentForm extends Component<Props, State> {
mix: props.mix,
})}
onSubmit={this.send}
aria-label="New comment"
aria-label={intl.formatMessage(messages.newComment)}
onDragOver={this.onDragOver}
onDrop={this.onDrop}
>
Expand Down Expand Up @@ -413,7 +436,7 @@ export class CommentForm extends Component<Props, State> {
</div>

{(isErrorShown || !!errorMessage) &&
(errorMessage || 'Something went wrong. Please try again a bit later.').split('\n').map(e => (
(errorMessage || intl.formatMessage(messages.unexpectedError)).split('\n').map(e => (
<p className="comment-form__error" role="alert" key={e}>
{e}
</p>
Expand Down Expand Up @@ -455,8 +478,8 @@ export class CommentForm extends Component<Props, State> {
<SubscribeByRSS userId={props.user !== null ? props.user.id : null} />
{StaticStore.config.email_notifications && (
<Fragment>
{' or '}
<SubscribeByEmail />
{' '}
<FormattedMessage id="commentForm.subscribe-or" defaultMessage="or" /> <SubscribeByEmail />
</Fragment>
)}
</div>
Expand Down
6 changes: 5 additions & 1 deletion frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@
"comment.vote-error": "Voting error: {voteErrorMessage}",
"commentForm.upload-file-fail": "{fileName} upload failed with \"{errorMessage}\"",
"commentForm.uploading": "Uploading...",
"commentForm.uploading-file": "uploading {fileName}..."
"commentForm.uploading-file": "uploading {fileName}...",
"commentForm.exceeded-size": "{fileName} exceeds size limit of {maxImageSize}",
"commentForm.new-comment": "New comment",
"commentForm.unexpected-error": "Something went wrong. Please try again a bit later.",
"commentForm.subscribe-or": "or"
}
6 changes: 5 additions & 1 deletion frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,9 @@
"comment.vote-error": "Ошибка голосования: {voteErrorMessage}",
"commentForm.upload-file-fail": "{fileName} невозможно загрузить из-за ошибки: \"{errorMessage}\"",
"commentForm.uploading": "Загрузка...",
"commentForm.uploading-file": "Загрузка {fileName}..."
"commentForm.uploading-file": "Загрузка {fileName}...",
"commentForm.exceeded-size": "Размер файла {fileName} должен быть меньше чем {maxImageSize}",
"commentForm.new-comment": "New comment",
"commentForm.unexpected-error": "Something went wrong. Please try again a bit later.",
"commentForm.subscribe-or": "или"
}

0 comments on commit 05ae8cf

Please sign in to comment.