diff --git a/framework/core/js/forum/src/components/DiscussionRenamedPost.js b/framework/core/js/forum/src/components/DiscussionRenamedPost.js index 0827e43fe..5acc343a8 100644 --- a/framework/core/js/forum/src/components/DiscussionRenamedPost.js +++ b/framework/core/js/forum/src/components/DiscussionRenamedPost.js @@ -13,15 +13,18 @@ export default class DiscussionRenamedPost extends EventPost { return 'pencil'; } - description() { + descriptionKey() { + return 'core.discussion_renamed_post'; + } + + descriptionData() { const post = this.props.post; const oldTitle = post.content()[0]; const newTitle = post.content()[1]; - return app.trans('core.discussion_renamed', { - user: this.props.post.user(), + return { old: {oldTitle}, new: {newTitle} - }); + }; } } diff --git a/framework/core/js/forum/src/components/EventPost.js b/framework/core/js/forum/src/components/EventPost.js index 8aefd32ee..ca4023375 100644 --- a/framework/core/js/forum/src/components/EventPost.js +++ b/framework/core/js/forum/src/components/EventPost.js @@ -1,4 +1,5 @@ import Post from 'flarum/components/Post'; +import { ucfirst } from 'flarum/utils/string'; import usernameHelper from 'flarum/helpers/username'; import icon from 'flarum/helpers/icon'; @@ -16,19 +17,24 @@ import icon from 'flarum/helpers/icon'; export default class EventPost extends Post { attrs() { return { - className: 'EventPost EventPost--' + this.props.post.contentType() + className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post' }; } content() { const user = this.props.post.user(); const username = usernameHelper(user); + const data = Object.assign(this.descriptionData(), { + user, + username: user + ? {username} + : username + }); return [ icon(this.icon(), {className: 'EventPost-icon'}),
- {user ? {username} : username}{' '} - {this.description()} + {app.trans(this.descriptionKey(), data)}
]; } @@ -39,13 +45,24 @@ export default class EventPost extends Post { * @return {String} */ icon() { + return ''; } /** - * Get the description of the event. + * Get the translation key for the description of the event. * - * @return {VirtualElement} + * @return {String} */ - description() { + descriptionKey() { + return ''; + } + + /** + * Get the translation data for the description of the event. + * + * @return {Object} + */ + descriptionData() { + return {}; } } diff --git a/framework/core/js/lib/utils/string.js b/framework/core/js/lib/utils/string.js index 69d89bd69..6d5a14aa8 100644 --- a/framework/core/js/lib/utils/string.js +++ b/framework/core/js/lib/utils/string.js @@ -36,3 +36,13 @@ export function slug(string) { export function getPlainContent(string) { return $('
').html(string.replace(/(<\/p>|
)/g, '$1 ')).text(); } + +/** + * Make a string's first character uppercase. + * + * @param {String} string + * @return {String} + */ +export function ucfirst(string) { + return string.substr(0, 1).toUpperCase() + string.substr(1); +} diff --git a/framework/core/locale/en/translations.yml b/framework/core/locale/en/translations.yml index 9c9516394..43939a938 100644 --- a/framework/core/locale/en/translations.yml +++ b/framework/core/locale/en/translations.yml @@ -25,7 +25,7 @@ core: delete_forever: Delete Forever deleted: "[deleted]" disclose_online: Allow others to see when I am online - discussion_renamed: "changed the title from {old} to {new}" + discussion_renamed_post: "{username} changed the title from {old} to {new}." discussion_renamed_notification: "{username} changed the title" discussion_replied: "{username} replied {ago}" discussion_started: "{username} started {ago}"