make post actions (likes, flags) translatable as whole sentences

This commit is contained in:
Kuba Brecka
2013-04-02 21:15:55 +02:00
parent 7ef5037bbe
commit f957b0aee5
5 changed files with 93 additions and 40 deletions

View File

@@ -10,16 +10,15 @@ Discourse.ActionSummary = Discourse.Model.extend({
// Description for the action
description: (function() {
var action = this.get('actionType.name_key');
if (this.get('acted')) {
return Em.String.i18n('post.actions.by_you_and_others', {
count: this.get('count') - 1,
long_form: this.get('actionType.long_form')
});
if (this.get('count') <= 1) {
return Em.String.i18n('post.actions.by_you.' + action);
} else {
return Em.String.i18n('post.actions.by_you_and_others.' + action, { count: this.get('count') - 1 });
}
} else {
return Em.String.i18n('post.actions.by_others', {
count: this.get('count'),
long_form: this.get('actionType.long_form')
});
return Em.String.i18n('post.actions.by_others.' + action, { count: this.get('count') });
}
}).property('count', 'acted', 'actionType'),
@@ -113,5 +112,3 @@ Discourse.ActionSummary = Discourse.Model.extend({
}
});

View File

@@ -8,16 +8,4 @@
**/
Discourse.PostActionType = Discourse.Model.extend({
alsoName: (function() {
if (this.get('is_flag')) return Em.String.i18n('post.actions.flag');
return this.get('name');
}).property('is_flag', 'name'),
alsoNameLower: (function() {
var _ref;
return (_ref = this.get('alsoName')) ? _ref.toLowerCase() : void 0;
}).property('alsoName')
});

View File

@@ -49,7 +49,7 @@ Discourse.Site.reopenClass({
result.postActionByIdLookup = Em.Object.create();
result.post_action_types = result.post_action_types.map(function(p) {
var actionType;
actionType = Discourse.PostActionType.create(p);
actionType = Discourse.Model.create(p);
result.postActionByIdLookup.set("action" + p.id, actionType);
return actionType;
});

View File

@@ -24,32 +24,33 @@ Discourse.ActionsHistoryView = Discourse.View.extend({
if (!this.present('content')) return;
return this.get('content').forEach(function(c) {
var alsoName;
var actionString, iconsHtml;
buffer.push("<div class='post-action'>");
if (c.get('users')) {
iconsHtml = "";
c.get('users').forEach(function(u) {
buffer.push("<a href=\"" + Discourse.getURL("/users/") + (u.get('username_lower')) + "\">");
buffer.push(Discourse.Utilities.avatarImg({
iconsHtml += "<a href=\"" + Discourse.getURL("/users/") + (u.get('username_lower')) + "\">";
iconsHtml += Discourse.Utilities.avatarImg({
size: 'small',
username: u.get('username'),
avatarTemplate: u.get('avatar_template')
}));
return buffer.push("</a>");
});
iconsHtml += "</a>";
});
buffer.push(" " + (c.get('actionType.long_form')) + ".");
buffer.push(" " + Em.String.i18n('post.actions.people.' + c.get('actionType.name_key'), { icons: iconsHtml }) + ".");
} else {
buffer.push("<a href='#' data-who-acted='" + (c.get('id')) + "'>" + (c.get('description')) + "</a>.");
}
if (c.get('can_act')) {
alsoName = Em.String.i18n("post.actions.it_too", { alsoName: c.get('actionType.alsoName') });
buffer.push(" <a href='#' data-act='" + (c.get('id')) + "'>" + alsoName + "</a>.");
actionString = Em.String.i18n("post.actions.it_too." + c.get('actionType.name_key'));
buffer.push(" <a href='#' data-act='" + (c.get('id')) + "'>" + actionString + "</a>.");
}
if (c.get('can_undo')) {
alsoName = Em.String.i18n("post.actions.undo", { alsoName: c.get('actionType.alsoNameLower') });
buffer.push(" <a href='#' data-undo='" + (c.get('id')) + "'>" + alsoName + "</a>.");
actionString = Em.String.i18n("post.actions.undo." + c.get('actionType.name_key') );
buffer.push(" <a href='#' data-undo='" + (c.get('id')) + "'>" + actionString + "</a>.");
}
if (c.get('can_clear_flags')) {