mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
Make front-end localizable
This commit is contained in:
@@ -4,6 +4,7 @@ import LogInModal from 'flarum/components/LogInModal';
|
||||
import Button from 'flarum/components/Button';
|
||||
import Separator from 'flarum/components/Separator';
|
||||
import ItemList from 'flarum/utils/ItemList';
|
||||
import extractText from 'flarum/utils/extractText';
|
||||
|
||||
/**
|
||||
* The `DiscussionControls` utility constructs a list of buttons for a
|
||||
@@ -54,14 +55,14 @@ export default {
|
||||
!app.session.user || discussion.canReply()
|
||||
? Button.component({
|
||||
icon: 'reply',
|
||||
children: app.session.user ? 'Reply' : 'Log In to Reply',
|
||||
children: app.session.user ? app.trans('core.reply') : app.trans('core.log_in_to_reply'),
|
||||
onclick: this.replyAction.bind(discussion, true, false)
|
||||
})
|
||||
: Button.component({
|
||||
icon: 'reply',
|
||||
children: 'Can\'t Reply',
|
||||
children: app.trans('core.cannot_reply'),
|
||||
className: 'disabled',
|
||||
title: 'You don\'t have permission to reply to this discussion.'
|
||||
title: app.trans('core.cannot_reply_help')
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -84,7 +85,7 @@ export default {
|
||||
if (discussion.canRename()) {
|
||||
items.add('rename', Button.component({
|
||||
icon: 'pencil',
|
||||
children: 'Rename',
|
||||
children: app.trans('core.rename'),
|
||||
onclick: this.renameAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
@@ -107,7 +108,7 @@ export default {
|
||||
if (discussion.canDelete()) {
|
||||
items.add('delete', Button.component({
|
||||
icon: 'times',
|
||||
children: 'Delete',
|
||||
children: app.trans('core.delete'),
|
||||
onclick: this.deleteAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
@@ -176,7 +177,7 @@ export default {
|
||||
* Delete the discussion after confirming with the user.
|
||||
*/
|
||||
deleteAction() {
|
||||
if (confirm('Are you sure you want to delete this discussion?')) {
|
||||
if (confirm(extractText(app.trans('core.confirm_delete_discussion')))) {
|
||||
this.delete();
|
||||
|
||||
// If there is a discussion list in the cache, remove this discussion.
|
||||
@@ -197,7 +198,7 @@ export default {
|
||||
*/
|
||||
renameAction() {
|
||||
const currentTitle = this.title();
|
||||
const title = prompt('Enter a new title for this discussion:', currentTitle);
|
||||
const title = prompt(extractText(app.trans('core.prompt_rename_discussion')), currentTitle);
|
||||
|
||||
// If the title is different to what it was before, then save it. After the
|
||||
// save has completed, update the post stream as there will be a new post
|
||||
|
@@ -60,13 +60,13 @@ export default {
|
||||
if (post.isHidden()) {
|
||||
items.add('restore', Button.component({
|
||||
icon: 'reply',
|
||||
children: 'Restore',
|
||||
children: app.trans('core.restore'),
|
||||
onclick: this.restoreAction.bind(post)
|
||||
}));
|
||||
} else {
|
||||
items.add('edit', Button.component({
|
||||
icon: 'pencil',
|
||||
children: 'Edit',
|
||||
children: app.trans('core.edit'),
|
||||
onclick: this.editAction.bind(post)
|
||||
}));
|
||||
}
|
||||
@@ -91,13 +91,13 @@ export default {
|
||||
if (post.contentType() === 'comment' && !post.isHidden() && post.canEdit()) {
|
||||
items.add('hide', Button.component({
|
||||
icon: 'times',
|
||||
children: 'Delete',
|
||||
children: app.trans('core.delete'),
|
||||
onclick: this.hideAction.bind(post)
|
||||
}));
|
||||
} else if ((post.contentType() !== 'comment' || post.isHidden()) && post.canDelete()) {
|
||||
items.add('delete', Button.component({
|
||||
icon: 'times',
|
||||
children: 'Delete Forever',
|
||||
children: app.trans('core.delete_forever'),
|
||||
onclick: this.deleteAction.bind(post)
|
||||
}));
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ export default {
|
||||
if (user.canEdit()) {
|
||||
items.add('edit', Button.component({
|
||||
icon: 'pencil',
|
||||
children: 'Edit',
|
||||
children: app.trans('core.edit'),
|
||||
onclick: this.editAction.bind(user)
|
||||
}));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
if (user.canDelete()) {
|
||||
items.add('delete', Button.component({
|
||||
icon: 'times',
|
||||
children: 'Delete',
|
||||
children: app.trans('core.delete'),
|
||||
onclick: this.deleteAction.bind(user)
|
||||
}));
|
||||
}
|
||||
|
19
js/forum/src/utils/extractText.js
Normal file
19
js/forum/src/utils/extractText.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Extract the text nodes from a virtual element.
|
||||
*
|
||||
* @param {VirtualElement} vdom
|
||||
* @return {String}
|
||||
*/
|
||||
export default function extractText(vdom) {
|
||||
let text = '';
|
||||
|
||||
if (vdom instanceof Array) {
|
||||
text += vdom.map(element => extractText(element)).join('');
|
||||
} else if (typeof vdom === 'object') {
|
||||
text += extractText(vdom.children);
|
||||
} else {
|
||||
text += vdom;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
Reference in New Issue
Block a user