Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Chinese pluralization bug in index.js #187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
// (c) 2012-2018 Airbnb, Inc.
//
// polyglot.js may be freely distributed under the terms of the BSD
// license. For all licensing information, details, and documentation:
// http://airbnb.github.com/polyglot.js
//
//
// Polyglot.js is an I18n helper library written in JavaScript, made to
// work both in the browser and in Node. It provides a simple solution for
// interpolation and pluralization, based off of Airbnb's
// experience adding I18n functionality to its Backbone.js and Node apps.
//
// Polylglot is agnostic to your translation backend. It doesn't perform any
// translation; it simply gives you a way to manage translated phrases from
// your client- or server-side JavaScript application.
//

'use strict';

var entries = require('object.entries');
Expand Down Expand Up @@ -55,7 +38,7 @@ var defaultPluralRules = {
return lastTwo >= 11 ? 4 : 5;
},
bosnian_serbian: russianPluralGroups,
chinese: function () { return 0; },
chinese: function (n) { return n === 1 ? 0 : 1; },
croatian: russianPluralGroups,
french: function (n) { return n >= 2 ? 1 : 0; },
german: function (n) { return n !== 1 ? 1 : 0; },
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,17 @@ describe('locale-specific pluralization rules', function () {
expect(polyglot.t('n_votes', 9)).to.equal('9 голосів');
expect(polyglot.t('n_votes', 11)).to.equal('11 голосів');
});

it('pluralizes in Chinese', function () {
var phrases = {
n_items: '选择 1 个项目 |||| 选择 %{smart_count} 项目'
};

var polyglot = new Polyglot({ phrases: phrases, locale: 'zh' });

expect(polyglot.t('n_items', 1)).to.equal('选择 1 项目');
expect(polyglot.t('n_items', 2)).to.equal('选择 2 项目');
});
});

describe('custom pluralRules', function () {
Expand Down
Loading