Skip to content

Commit 8874c9e

Browse files
committed
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
1 parent e93b7a3 commit 8874c9e

77 files changed

Lines changed: 2279 additions & 29 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/assets/javascripts/discourse/templates/topic.js.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</table>
102102
</div>
103103
<br/>
104-
<h3>{{{unbound view.browseMoreMessage}}}</h3>
104+
<h3>{{{view.browseMoreMessage}}}</h3>
105105
</div>
106106
{{/if}}
107107
{{/if}}

app/assets/javascripts/discourse/views/topic_view.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
402402
});
403403

404404
this.nonUrgentPositionUpdate({
405-
userActive: userActive,
406-
currentPost: currentPost || this.getPost($(rows[info.bottom])).get('post_number')
405+
userActive: userActive,
406+
currentPost: currentPost || this.getPost($(rows[info.bottom])).get('post_number')
407407
});
408408

409409
offset = window.pageYOffset || $('html').scrollTop();
@@ -440,20 +440,41 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
440440
}
441441
},
442442

443+
topicTrackingState: function(){
444+
return Discourse.TopicTrackingState.current();
445+
}.property(),
446+
443447
browseMoreMessage: (function() {
444448
var category, opts;
445449

446450
opts = {
447451
latestLink: "<a href=\"/\">" + (Em.String.i18n("topic.view_latest_topics")) + "</a>"
448452
};
453+
449454
if (category = this.get('controller.content.category')) {
450455
opts.catLink = Discourse.Utilities.categoryLink(category);
451-
return Ember.String.i18n("topic.read_more_in_category", opts);
452456
} else {
453457
opts.catLink = "<a href=\"" + Discourse.getURL("/categories") + "\">" + (Em.String.i18n("topic.browse_all_categories")) + "</a>";
458+
}
459+
460+
var tracking = this.get('topicTrackingState');
461+
462+
var unreadTopics = tracking.countUnread();
463+
var newTopics = tracking.countNew();
464+
465+
if (newTopics + unreadTopics > 0) {
466+
if(category) {
467+
return I18n.messageFormat("topic.read_more_in_category_MF", {"UNREAD": unreadTopics, "NEW": newTopics, catLink: opts.catLink})
468+
} else {
469+
return I18n.messageFormat("topic.read_more_MF", {"UNREAD": unreadTopics, "NEW": newTopics, latestLink: opts.latestLink})
470+
}
471+
}
472+
else if (category) {
473+
return Ember.String.i18n("topic.read_more_in_category", opts);
474+
} else {
454475
return Ember.String.i18n("topic.read_more", opts);
455476
}
456-
}).property()
477+
}).property('topicTrackingState.messageCount')
457478

458479
});
459480

@@ -474,7 +495,7 @@ Discourse.TopicView.reopenClass({
474495
expectedOffset = title.height() - header.find('.contents').height();
475496

476497
if (expectedOffset < 0) {
477-
expectedOffset = 0;
498+
expectedOffset = 0;
478499
}
479500

480501
$('html, body').scrollTop(existing.offset().top - (header.outerHeight(true) + expectedOffset));

app/helpers/js_locale_helper.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Application < Rails::Application
1919
# -- all .rb files in that directory are automatically loaded.
2020

2121
require 'discourse'
22+
require 'js_locale_helper'
2223

2324
# mocha hates us, active_support/testing/mochaing.rb line 2 is requiring the wrong
2425
# require, patched in source, on upgrade remove this

config/locales/client.en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ en:
505505
toggle_information: "toggle topic details"
506506
read_more_in_category: "Want to read more? Browse other topics in {{catLink}} or {{latestLink}}."
507507
read_more: "Want to read more? {{catLink}} or {{latestLink}}."
508+
509+
# keys ending with _MF use message format, see /spec/components/js_local_helper_spec.rb for samples
510+
read_more_in_category_MF: "There {UNREAD, plural, one {is <a href='/unread'>1 unread</a>} other {are <a href='/unread'># unread</a>}} and {NEW, plural, one {<a href='/new'>1 new</a> topic} other {<a href='/new'># new</a> topics}} remaining, or browse other topics in {catLink}"
511+
read_more_MF: "There {UNREAD, plural, one {is <a href='/unread'>1 unread</a>} other {are <a href='/unread'># unread</a>}} and {NEW, plural, one {<a href='/new'>1 new</a> topic} other {<a href='/new'># new</a> topics}} remaining, or {latestLink}"
512+
508513
browse_all_categories: Browse all categories
509514

510515
view_latest_topics: view latest topics

lib/javascripts/locale/af.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MessageFormat.locale.af = function ( n ) {
2+
if ( n === 1 ) {
3+
return "one";
4+
}
5+
return "other";
6+
};

lib/javascripts/locale/am.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MessageFormat.locale.am = function(n) {
2+
if (n === 0 || n == 1) {
3+
return 'one';
4+
}
5+
return 'other';
6+
};

lib/javascripts/locale/ar.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MessageFormat.locale.ar = function(n) {
2+
if (n === 0) {
3+
return 'zero';
4+
}
5+
if (n == 1) {
6+
return 'one';
7+
}
8+
if (n == 2) {
9+
return 'two';
10+
}
11+
if ((n % 100) >= 3 && (n % 100) <= 10 && n == Math.floor(n)) {
12+
return 'few';
13+
}
14+
if ((n % 100) >= 11 && (n % 100) <= 99 && n == Math.floor(n)) {
15+
return 'many';
16+
}
17+
return 'other';
18+
};

lib/javascripts/locale/bg.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MessageFormat.locale.bg = function ( n ) {
2+
if ( n === 1 ) {
3+
return "one";
4+
}
5+
return "other";
6+
};

lib/javascripts/locale/bn.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MessageFormat.locale.bn = function ( n ) {
2+
if ( n === 1 ) {
3+
return "one";
4+
}
5+
return "other";
6+
};

0 commit comments

Comments
 (0)