Skip to content

Commit 97bf0a7

Browse files
committed
Auto merge of #3043 - Turbo87:plural, r=locks
Fix broken pluralizations Passing the formatted number into the `pluralize` helper doesn't work quite as expected, and in these cases we already know the pluralization, so using the `pluralize` helper is somewhat pointless anyway. Resolves #3042 r? `@jtgeibel`
2 parents 9214e86 + 2e5c7b3 commit 97bf0a7

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

app/templates/categories.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{category.category}}
2828
</LinkTo>
2929
<span local-class="crate-count" data-test-crate-count>
30-
{{ pluralize (format-num category.crates_cnt) "crate" }}
30+
{{format-num category.crates_cnt}} {{if (eq category.crates_cnt 1) "crate" "crates"}}
3131
</span>
3232
</div>
3333
<div local-class="description">

app/templates/category/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div>
2222
<LinkTo @route="category" @model={{subcategory.slug}}>{{subcategory.category}}</LinkTo>
2323
<span local-class="crate-count">
24-
{{ pluralize (format-num subcategory.crates_cnt) "crate" }}
24+
{{format-num subcategory.crates_cnt}} {{if (eq subcategory.crates_cnt 1) "crate" "crates"}}
2525
</span>
2626
</div>
2727
<div local-class="category-description">

app/templates/keywords.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<div local-class="row">
2525
<LinkTo @route="keyword" @model={{keyword}}>{{keyword.id}}</LinkTo>
2626
<span local-class="crate-count">
27-
{{ pluralize (format-num keyword.crates_cnt) "crate" }}
27+
{{format-num keyword.crates_cnt}} {{if (eq keyword.crates_cnt 1) "crate" "crates"}}
2828
</span>
2929
</div>
3030
{{/each}}

mirage/serializers/category.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export default BaseSerializer.extend({
1919
let allCrates = this.schema.crates.all();
2020
let associatedCrates = allCrates.filter(it => it.categoryIds.includes(hash.id));
2121

22-
hash.crates_cnt = associatedCrates.length;
22+
hash.crates_cnt ??= associatedCrates.length;
2323
},
2424
});

mirage/serializers/keyword.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export default BaseSerializer.extend({
1919
let allCrates = this.schema.crates.all();
2020
let associatedCrates = allCrates.filter(it => it.keywordIds.includes(hash.id));
2121

22-
hash.crates_cnt = associatedCrates.length;
22+
hash.crates_cnt ??= associatedCrates.length;
2323
},
2424
});

tests/acceptance/categories-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,47 @@ import { module, test } from 'qunit';
44

55
import percySnapshot from '@percy/ember';
66
import a11yAudit from 'ember-a11y-testing/test-support/audit';
7+
import window from 'ember-window-mock';
8+
import { setupWindowMock } from 'ember-window-mock/test-support';
79

810
import axeConfig from '../axe-config';
911
import setupMirage from '../helpers/setup-mirage';
1012

1113
module('Acceptance | categories', function (hooks) {
1214
setupApplicationTest(hooks);
15+
setupWindowMock(hooks);
1316
setupMirage(hooks);
1417

1518
test('listing categories', async function (assert) {
19+
window.navigator = { languages: ['en'] };
20+
1621
this.server.create('category', { category: 'API bindings' });
1722
this.server.create('category', { category: 'Algorithms' });
1823
this.server.createList('crate', 1, { categoryIds: ['algorithms'] });
1924
this.server.create('category', { category: 'Asynchronous' });
2025
this.server.createList('crate', 15, { categoryIds: ['asynchronous'] });
26+
this.server.create('category', { category: 'Everything', crates_cnt: 1234 });
2127

2228
await visit('/categories');
2329

2430
assert.dom('[data-test-category="api-bindings"] [data-test-crate-count]').hasText('0 crates');
2531
assert.dom('[data-test-category="algorithms"] [data-test-crate-count]').hasText('1 crate');
2632
assert.dom('[data-test-category="asynchronous"] [data-test-crate-count]').hasText('15 crates');
33+
assert.dom('[data-test-category="everything"] [data-test-crate-count]').hasText('1,234 crates');
2734

2835
await percySnapshot(assert);
2936
await a11yAudit(axeConfig);
3037
});
3138

39+
test('listing categories (locale: de)', async function (assert) {
40+
window.navigator = { languages: ['de'] };
41+
42+
this.server.create('category', { category: 'Everything', crates_cnt: 1234 });
43+
44+
await visit('/categories');
45+
assert.dom('[data-test-category="everything"] [data-test-crate-count]').hasText('1.234 crates');
46+
});
47+
3248
test('category/:category_id index default sort is recent-downloads', async function (assert) {
3349
this.server.create('category', { category: 'Algorithms' });
3450

0 commit comments

Comments
 (0)