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

[New] add Ukrainian #184

Merged
merged 1 commit into from
Jul 11, 2024
Merged
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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ var defaultPluralRules = {
var lastTwo = n % 100;
if (n === 0 || (lastTwo >= 2 && lastTwo <= 19)) { return 1; }
return 2;
}
},
ukrainian: russianPluralGroups
},

// Mapping from pluralization group to individual language codes/locales.
Expand All @@ -111,7 +112,8 @@ var defaultPluralRules = {
polish: ['pl'],
icelandic: ['is', 'mk'],
slovenian: ['sl-SL'],
romanian: ['ro']
romanian: ['ro'],
ukrainian: ['uk', 'ua']
}
};

Expand Down
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,38 @@ describe('locale-specific pluralization rules', function () {
expect(polyglot.t('n_days', 101)).to.equal('101 ден');
expect(polyglot.t('n_days', 111)).to.equal('111 дена');
});

it('pluralizes in Ukrainian', function () {
// English would be: "1 vote" / "%{smart_count} votes"
var whatSomeoneTranslated = [
'%{smart_count} голос',
'%{smart_count} голоси',
'%{smart_count} голосів'
];
var phrases = {
n_votes: whatSomeoneTranslated.join(' |||| ')
};

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

// Singular form
expect(polyglot.t('n_votes', 1)).to.equal('1 голос');
expect(polyglot.t('n_votes', 21)).to.equal('21 голос');

// Few form
expect(polyglot.t('n_votes', 2)).to.equal('2 голоси');
expect(polyglot.t('n_votes', 3)).to.equal('3 голоси');
expect(polyglot.t('n_votes', 4)).to.equal('4 голоси');

// Many form
expect(polyglot.t('n_votes', 0)).to.equal('0 голосів');
expect(polyglot.t('n_votes', 5)).to.equal('5 голосів');
expect(polyglot.t('n_votes', 6)).to.equal('6 голосів');
expect(polyglot.t('n_votes', 7)).to.equal('7 голосів');
expect(polyglot.t('n_votes', 8)).to.equal('8 голосів');
expect(polyglot.t('n_votes', 9)).to.equal('9 голосів');
expect(polyglot.t('n_votes', 11)).to.equal('11 голосів');
});
});

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