Skip to content

Commit

Permalink
umputun#10 localize subscribe by rss
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 22, 2020
1 parent bfe8e53 commit b4cdb1e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
/** @jsx createElement */
import { createElement } from 'preact';
import { shallow } from 'enzyme';
import enMessages from '../../../locales/en.json';

import { SubscribeByRSS, createSubscribeUrl } from './';

jest.mock('react-redux', () => ({
useSelector: jest.fn(fn => fn({ theme: 'light' })),
}));

jest.mock('react-intl', () => {
// Require the original module to not be mocked...
const originalModule = jest.requireActual('react-intl');

return {
...originalModule,
useIntl: () => originalModule.createIntl({ locale: `en`, messages: enMessages }),
};
});

describe('<SubscribeByRSS/>', () => {
let wrapper: ReturnType<typeof shallow>;

Expand All @@ -16,6 +27,7 @@ describe('<SubscribeByRSS/>', () => {
});

it('should be render links in dropdown', () => {
wrapper.update();
expect(wrapper.find('.comment-form__rss-dropdown__link')).toHaveLength(3);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsx createElement */
import { createElement, FunctionComponent } from 'preact';
import { useMemo } from 'preact/hooks';
import { useIntl, defineMessages } from 'react-intl';

import useTheme from '@app/hooks/useTheme';
import { siteId, url } from '@app/common/settings';
Expand All @@ -10,22 +11,46 @@ import { Dropdown, DropdownItem } from '@app/components/dropdown';
export const createSubscribeUrl = (type: 'post' | 'site' | 'reply', urlParams: string = '') =>
`${BASE_URL}${API_BASE}/rss/${type}?site=${siteId}${urlParams}`;

const messages = defineMessages({
thread: {
id: 'subscribeByRSS.thread',
defaultMessage: 'Thread',
},
site: {
id: 'subscribeByRSS.site',
defaultMessage: 'Site',
},
replies: {
id: 'subscribeByRSS.replies',
defaultMessage: 'Replies',
},
buttonTitle: {
id: 'subscribeByRSS.button-title',
defaultMessage: 'Subscribe by RSS',
},
title: {
id: 'subscribeByRSS.title',
defaultMessage: 'RSS',
},
});

export const SubscribeByRSS: FunctionComponent<{ userId: string | null }> = ({ userId }) => {
const theme = useTheme();
const intl = useIntl();
const items: Array<[string, string]> = useMemo(
() => [
[createSubscribeUrl('post'), 'Thread'],
[createSubscribeUrl('site', `&user=${userId}`), 'Site'],
[createSubscribeUrl('reply', `&url=${url}`), 'Replies'],
[createSubscribeUrl('post'), intl.formatMessage(messages.thread)],
[createSubscribeUrl('site', `&user=${userId}`), intl.formatMessage(messages.site)],
[createSubscribeUrl('reply', `&url=${url}`), intl.formatMessage(messages.replies)],
],
[userId]
);

return (
<Dropdown
title="RSS"
title={intl.formatMessage(messages.title)}
titleClass="comment-form__rss-dropdown__title"
buttonTitle="Subscribe by RSS"
buttonTitle={intl.formatMessage(messages.buttonTitle)}
mix="comment-form__rss-dropdown"
theme={theme}
>
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
"settings.unblock": "unblock",
"settings.unblock-user": "Do you want to unblock {userName}?",
"settings.unknown": "unknown",
"subscribeByRSS.button-title": "Subscribe by RSS",
"subscribeByRSS.replies": "Replies",
"subscribeByRSS.site": "Site",
"subscribeByRSS.thread": "Thread",
"subscribeByRSS.title": "RSS",
"toolbar.attach-image": "Attach the image, drag & drop or paste from clipboard",
"toolbar.bold": "Add bold text <cmd-b>",
"toolbar.code": "Insert a code",
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
"settings.unblock": "разблокировать",
"settings.unblock-user": "Разблокировать пользователя {userName}?",
"settings.unknown": "безымянный",
"subscribeByRSS.button-title": "Subscribe by RSS",
"subscribeByRSS.replies": "Replies",
"subscribeByRSS.site": "Site",
"subscribeByRSS.thread": "Thread",
"subscribeByRSS.title": "RSS",
"toolbar.attach-image": "Attach the image, drag & drop or paste from clipboard",
"toolbar.bold": "Жирный <cmd-b>",
"toolbar.code": "Код",
Expand Down

0 comments on commit b4cdb1e

Please sign in to comment.