Skip to content

Commit

Permalink
[New] add Ukrainian
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfedak authored and ljharb committed Jul 11, 2024
1 parent 78022fe commit 2e29439
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
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

0 comments on commit 2e29439

Please sign in to comment.