Add message format support that can be used on complex localization strings

Add message about new and unread topics at the bottom of topics
move localization helper into lib
This commit is contained in:
Sam
2013-05-30 15:53:40 +10:00
parent e93b7a3b20
commit 8874c9ea75
77 changed files with 2279 additions and 29 deletions

View File

@ -101,7 +101,7 @@
</table>
</div>
<br/>
<h3>{{{unbound view.browseMoreMessage}}}</h3>
<h3>{{{view.browseMoreMessage}}}</h3>
</div>
{{/if}}
{{/if}}

View File

@ -402,8 +402,8 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
});
this.nonUrgentPositionUpdate({
userActive: userActive,
currentPost: currentPost || this.getPost($(rows[info.bottom])).get('post_number')
userActive: userActive,
currentPost: currentPost || this.getPost($(rows[info.bottom])).get('post_number')
});
offset = window.pageYOffset || $('html').scrollTop();
@ -440,20 +440,41 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
}
},
topicTrackingState: function(){
return Discourse.TopicTrackingState.current();
}.property(),
browseMoreMessage: (function() {
var category, opts;
opts = {
latestLink: "<a href=\"/\">" + (Em.String.i18n("topic.view_latest_topics")) + "</a>"
};
if (category = this.get('controller.content.category')) {
opts.catLink = Discourse.Utilities.categoryLink(category);
return Ember.String.i18n("topic.read_more_in_category", opts);
} else {
opts.catLink = "<a href=\"" + Discourse.getURL("/categories") + "\">" + (Em.String.i18n("topic.browse_all_categories")) + "</a>";
}
var tracking = this.get('topicTrackingState');
var unreadTopics = tracking.countUnread();
var newTopics = tracking.countNew();
if (newTopics + unreadTopics > 0) {
if(category) {
return I18n.messageFormat("topic.read_more_in_category_MF", {"UNREAD": unreadTopics, "NEW": newTopics, catLink: opts.catLink})
} else {
return I18n.messageFormat("topic.read_more_MF", {"UNREAD": unreadTopics, "NEW": newTopics, latestLink: opts.latestLink})
}
}
else if (category) {
return Ember.String.i18n("topic.read_more_in_category", opts);
} else {
return Ember.String.i18n("topic.read_more", opts);
}
}).property()
}).property('topicTrackingState.messageCount')
});
@ -474,7 +495,7 @@ Discourse.TopicView.reopenClass({
expectedOffset = title.height() - header.find('.contents').height();
if (expectedOffset < 0) {
expectedOffset = 0;
expectedOffset = 0;
}
$('html, body').scrollTop(existing.offset().top - (header.outerHeight(true) + expectedOffset));

View File

@ -1,23 +0,0 @@
module JsLocaleHelper
def self.output_locale(locale)
locale_str = locale.to_s
translations = YAML::load(File.open("#{Rails.root}/config/locales/client.#{locale_str}.yml"))
# We used to split the admin versus the client side, but it's much simpler to just
# include both for now due to the small size of the admin section.
#
# For now, let's leave it split out in the translation file in case we want to split
# it again later, so we'll merge the JSON ourselves.
admin_contents = translations[locale_str].delete('admin_js')
translations[locale_str]['js'].merge!(admin_contents) if admin_contents.present?
result = "I18n.translations = #{translations.to_json};\n"
result << "I18n.locale = '#{locale_str}'\n"
result
end
end