Skip to content

Commit

Permalink
umputun#10 localize some comment form message
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 18, 2020
1 parent 8af1e0d commit b6f7f93
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
14 changes: 10 additions & 4 deletions frontend/app/components/comment-form/comment-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import { StaticStore } from '@app/common/static_store';
import { CommentForm, Props } from './comment-form';
import { SubscribeByEmail } from './__subscribe-by-email';

const DEFAULT_PROPS: Readonly<Props> = {
const DEFAULT_PROPS: Readonly<Omit<Props, 'intl'>> = {
mode: 'main',
theme: 'light',
onSubmit: () => Promise.resolve(),
getPreview: () => Promise.resolve(''),
user: null,
};

const intl = {
formatMessage() {
return '';
},
} as any;

describe('<CommentForm />', () => {
it('should render without control panel, preview button, and rss links in "simple view" mode', () => {
const props = { ...DEFAULT_PROPS, simpleView: true };
const props = { ...DEFAULT_PROPS, simpleView: true, intl };
const wrapper = shallow(<CommentForm {...props} />);

expect(wrapper.exists('.comment-form__control-panel')).toEqual(false);
Expand All @@ -29,7 +35,7 @@ describe('<CommentForm />', () => {
it('should be rendered with email subscription button', () => {
StaticStore.config.email_notifications = true;

const props = { ...DEFAULT_PROPS, user };
const props = { ...DEFAULT_PROPS, user, intl };
const wrapper = shallow(<CommentForm {...props} />);

expect(wrapper.exists(SubscribeByEmail)).toEqual(true);
Expand All @@ -38,7 +44,7 @@ describe('<CommentForm />', () => {
it('should be rendered without email subscription button when email_notifications disabled', () => {
StaticStore.config.email_notifications = false;

const props = { ...DEFAULT_PROPS, user };
const props = { ...DEFAULT_PROPS, user, intl };
const wrapper = shallow(<CommentForm {...props} />);

expect(wrapper.exists(SubscribeByEmail)).toEqual(false);
Expand Down
35 changes: 26 additions & 9 deletions frontend/app/components/comment-form/comment-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsx createElement */
import { createElement, Component, createRef, Fragment } from 'preact';
import { FormattedMessage } from 'react-intl';
import { FormattedMessage, IntlShape, defineMessages } from 'react-intl';
import b, { Mix } from 'bem-react-helper';

import { User, Theme, Image, ApiError } from '@app/common/types';
Expand Down Expand Up @@ -35,6 +35,7 @@ export interface Props {
/** action on cancel. optional as root input has no cancel option */
onCancel?: () => void;
uploadImage?: (image: File) => Promise<Image>;
intl: IntlShape;
}

interface State {
Expand All @@ -54,6 +55,13 @@ interface State {

const ImageMimeRegex = /image\//i;

defineMessages({
'commentForm.input-placeholder': {
id: 'commentForm.input-placeholder',
defaultMessage: 'Your comment here',
},
});

export class CommentForm extends Component<Props, State> {
/** reference to textarea element */
textAreaRef = createRef<TextareaAutosize>();
Expand Down Expand Up @@ -344,7 +352,10 @@ 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({
id: 'commentForm.input-placeholder',
defaultMessage: 'commentForm.input-placeholder',
});
return (
<form
className={b('comment-form', {
Expand Down Expand Up @@ -376,7 +387,7 @@ export class CommentForm extends Component<Props, State> {
onPaste={this.onPaste}
ref={this.textAreaRef}
className="comment-form__field"
placeholder="Your comment here"
placeholder={placeholderMessage}
value={text}
maxLength={maxLength}
onInput={this.onInput}
Expand Down Expand Up @@ -416,13 +427,19 @@ export class CommentForm extends Component<Props, State> {
{!props.simpleView && props.mode === 'main' && (
<div className="comment-form__rss">
<div className="comment-form__markdown">
Styling with{' '}
<a className="comment-form__markdown-link" target="_blank" href="markdown-help.html">
Markdown
</a>
{' is supported'}
<FormattedMessage
id="commentForm.notice-about-styling"
defaultMessage="Styling with <a>Markdown</a> is supported"
values={{
a: (title: string) => (
<a class="comment-form__markdown-link" target="_blank" href="markdown-help.html">
{title}
</a>
),
}}
/>
</div>
{'Subscribe by '}
<FormattedMessage id="commentForm.subscribe-by" defaultMessage="Subscribe by" />{' '}
<SubscribeByRSS userId={props.user !== null ? props.user.id : null} />
{StaticStore.config.email_notifications && (
<Fragment>
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ export class Comment extends Component<Props, State> {

{isReplying && props.view === 'main' && (
<CommentForm
intl={this.props.intl}
user={props.user}
theme={props.theme}
value=""
Expand All @@ -807,6 +808,7 @@ export class Comment extends Component<Props, State> {

{isEditing && props.view === 'main' && (
<CommentForm
intl={this.props.intl}
user={props.user}
theme={props.theme}
value={o.orig}
Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/root/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export class Root extends Component<Props, State> {
<div className="root__main">
{!isGuest && !isCommentsDisabled && (
<CommentForm
intl={this.props.intl}
theme={props.theme}
mix="root__input"
mode="main"
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"comment.pin-comment": "Do you want to pin this comment?",
"comment.unpin-comment": "Do you want to unpin this comment?",
"comment.verify-user": "Do you want to verify {userName}?",
"comment.unverify-user": "Do you want to unverify {userName}?"
"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"
}
5 changes: 4 additions & 1 deletion frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
"comment.pin-comment": "Закрепить комментарий?",
"comment.unpin-comment": "Открепить комментарий?",
"comment.verify-user": "Do you want to verify {userName}?",
"comment.unverify-user": "Do you want to unverify {userName}?"
"comment.unverify-user": "Do you want to unverify {userName}?",
"commentForm.input-placeholder": "Написать комментарий",
"commentForm.notice-about-styling": "Поддерживается <a>Markdown</a> форматирование",
"commentForm.subscribe-by": "Подписаться"
}

0 comments on commit b6f7f93

Please sign in to comment.