Skip to content

Commit

Permalink
umputun#10 translate toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 22, 2020
1 parent f11c48c commit 32f0322
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions frontend/app/components/comment-form/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export class CommentForm extends Component<Props, State> {
{!props.simpleView && (
<div className="comment-form__control-panel">
<MarkdownToolbar
intl={intl}
allowUpload={Boolean(this.props.uploadImage)}
uploadImages={this.uploadImages}
textareaId={this.textareaId}
Expand Down
60 changes: 51 additions & 9 deletions frontend/app/components/comment-form/markdown-toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsx createElement */
import { createElement, Component } from 'preact';
import '@github/markdown-toolbar-element';
import { defineMessages, IntlShape } from 'react-intl';
import BoldIcon from './markdown-toolbar-icons/bold-icon';
import HeaderIcon from './markdown-toolbar-icons/header-icon';
import ItalicIcon from './markdown-toolbar-icons/italic-icon';
Expand All @@ -12,6 +13,7 @@ import UnorderedListIcon from './markdown-toolbar-icons/unordered-list-icon';
import OrderedListIcon from './markdown-toolbar-icons/ordered-list-icon';

interface Props {
intl: IntlShape;
textareaId: string;
uploadImages: (files: File[]) => Promise<void>;
allowUpload: boolean;
Expand All @@ -26,15 +28,44 @@ interface FileInputEvent extends Event {
readonly currentTarget: FileEventTarget | null;
}

const boldLabel = 'Add bold text <cmd-b>';
const headerLabel = 'Add header text';
const italicLabel = 'Add italic text <cmd-i>';
const quoteLabel = 'Insert a quote';
const codeLabel = 'Insert a code';
const linkLabel = 'Add a link <cmd-k>';
const unorderedListLabel = 'Add a bulleted list';
const orderedListLabel = 'Add a numbered list';
const attachImageLabel = 'Attach the image, drag & drop or paste from clipboard';
const messages = defineMessages({
bold: {
id: 'toolbar.bold',
defaultMessage: 'Add bold text <cmd-b>',
},
header: {
id: 'toolbar.header',
defaultMessage: 'Add header text',
},
italic: {
id: 'toolbar.italic',
defaultMessage: 'Add italic text <cmd-i>',
},
quote: {
id: 'toolbar.quote',
defaultMessage: 'Insert a quote',
},
code: {
id: 'toolbar.code',
defaultMessage: 'Insert a code',
},
link: {
id: 'toolbar.link',
defaultMessage: 'Add a link <cmd-k>',
},
unorderedList: {
id: 'toolbar.unordered-list',
defaultMessage: 'Add a bulleted list',
},
orderedList: {
id: 'toolbar.ordered-list',
defaultMessage: 'Add a numbered list',
},
attachImage: {
id: 'toolbar.attach-image',
defaultMessage: 'Attach the image, drag & drop or paste from clipboard',
},
});

export default class MarkdownToolbar extends Component<Props> {
constructor(props: Props) {
Expand All @@ -49,6 +80,17 @@ export default class MarkdownToolbar extends Component<Props> {
currentTarget.value = null;
}
render(props: Props) {
const intl = props.intl;

const boldLabel = intl.formatMessage(messages.bold);
const headerLabel = intl.formatMessage(messages.header);
const italicLabel = intl.formatMessage(messages.italic);
const quoteLabel = intl.formatMessage(messages.quote);
const codeLabel = intl.formatMessage(messages.code);
const linkLabel = intl.formatMessage(messages.link);
const unorderedListLabel = intl.formatMessage(messages.unorderedList);
const orderedListLabel = intl.formatMessage(messages.orderedList);
const attachImageLabel = intl.formatMessage(messages.attachImage);
return (
<markdown-toolbar className="comment-form__toolbar" for={props.textareaId}>
<div className="comment-form__toolbar-group">
Expand Down
11 changes: 10 additions & 1 deletion frontend/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,14 @@
"settings.blocked-users-title": "Blocked users",
"settings.no-hidden-users": "There are no hidden users.",
"settings.no-blocked-users": "There are no blocked users.",
"settings.blocked-users-header": "Blocked users:"
"settings.blocked-users-header": "Blocked users:",
"toolbar.bold": "Add bold text <cmd-b>",
"toolbar.header": "Add header text",
"toolbar.italic": "Add italic text <cmd-i>",
"toolbar.quote": "Insert a quote",
"toolbar.code": "Insert a code",
"toolbar.link": "Add a link <cmd-k>",
"toolbar.unordered-list": "Add a bulleted list",
"toolbar.ordered-list": "Add a numbered list",
"toolbar.attach-image": "Attach the image, drag & drop or paste from clipboard"
}
11 changes: 10 additions & 1 deletion frontend/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,14 @@
"settings.hide": "Спрятать",
"settings.blocked-users-title": "Заблокированные пользователи",
"settings.blocked-users-header": "Заблокированные пользователи:",
"settings.no-blocked-users": "Нет заблокированных пользователей."
"settings.no-blocked-users": "Нет заблокированных пользователей.",
"toolbar.bold": "Жирный <cmd-b>",
"toolbar.header": "Заголовок",
"toolbar.italic": "Курсив <cmd-i>",
"toolbar.quote": "Цитата",
"toolbar.code": "Код",
"toolbar.link": "Ссылка <cmd-k>",
"toolbar.unordered-list": "Неупорядоченный список",
"toolbar.ordered-list": "Упорядоченный список",
"toolbar.attach-image": "Attach the image, drag & drop or paste from clipboard"
}

0 comments on commit 32f0322

Please sign in to comment.