Skip to content

Commit

Permalink
bringt pt plurals in line with CLDR
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed Oct 9, 2017
1 parent d3b9154 commit c5113fb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 10.0.0
- **[BREAKING]** brings pt, pt-PT, pt-BR plurals in line with, new pt reflects pt-BR and pt-PT gets a special case for plural handling http://www.unicode.org/cldr/charts/26/supplemental/language_plural_rules.html

### 9.1.0
- support for using suffix `_0` on languages only having "singular" form enables easier convert in tool chains

Expand Down
4 changes: 2 additions & 2 deletions i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ var LanguageUtil = function () {

// definition http://translate.sourceforge.net/wiki/l10n/pluralforms
/* eslint-disable */
var sets = [{ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'tg', 'ti', 'tr', 'uz', 'wa'], nr: [1, 2], fc: 1 }, { lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'he', 'hi', 'hu', 'hy', 'ia', 'it', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'], nr: [1, 2], fc: 2 }, { lngs: ['ay', 'bo', 'cgg', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'], nr: [1], fc: 3 }, { lngs: ['be', 'bs', 'dz', 'hr', 'ru', 'sr', 'uk'], nr: [1, 2, 5], fc: 4 }, { lngs: ['ar'], nr: [0, 1, 2, 3, 11, 100], fc: 5 }, { lngs: ['cs', 'sk'], nr: [1, 2, 5], fc: 6 }, { lngs: ['csb', 'pl'], nr: [1, 2, 5], fc: 7 }, { lngs: ['cy'], nr: [1, 2, 3, 8], fc: 8 }, { lngs: ['fr'], nr: [1, 2], fc: 9 }, { lngs: ['ga'], nr: [1, 2, 3, 7, 11], fc: 10 }, { lngs: ['gd'], nr: [1, 2, 3, 20], fc: 11 }, { lngs: ['is'], nr: [1, 2], fc: 12 }, { lngs: ['jv'], nr: [0, 1], fc: 13 }, { lngs: ['kw'], nr: [1, 2, 3, 4], fc: 14 }, { lngs: ['lt'], nr: [1, 2, 10], fc: 15 }, { lngs: ['lv'], nr: [1, 2, 0], fc: 16 }, { lngs: ['mk'], nr: [1, 2], fc: 17 }, { lngs: ['mnk'], nr: [0, 1, 2], fc: 18 }, { lngs: ['mt'], nr: [1, 2, 11, 20], fc: 19 }, { lngs: ['or'], nr: [2, 1], fc: 2 }, { lngs: ['ro'], nr: [1, 2, 20], fc: 20 }, { lngs: ['sl'], nr: [5, 1, 2, 3], fc: 21 }];
var sets = [{ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'ti', 'tr', 'uz', 'wa'], nr: [1, 2], fc: 1 }, { lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'he', 'hi', 'hu', 'hy', 'ia', 'it', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'], nr: [1, 2], fc: 2 }, { lngs: ['ay', 'bo', 'cgg', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'], nr: [1], fc: 3 }, { lngs: ['be', 'bs', 'dz', 'hr', 'ru', 'sr', 'uk'], nr: [1, 2, 5], fc: 4 }, { lngs: ['ar'], nr: [0, 1, 2, 3, 11, 100], fc: 5 }, { lngs: ['cs', 'sk'], nr: [1, 2, 5], fc: 6 }, { lngs: ['csb', 'pl'], nr: [1, 2, 5], fc: 7 }, { lngs: ['cy'], nr: [1, 2, 3, 8], fc: 8 }, { lngs: ['fr'], nr: [1, 2], fc: 9 }, { lngs: ['ga'], nr: [1, 2, 3, 7, 11], fc: 10 }, { lngs: ['gd'], nr: [1, 2, 3, 20], fc: 11 }, { lngs: ['is'], nr: [1, 2], fc: 12 }, { lngs: ['jv'], nr: [0, 1], fc: 13 }, { lngs: ['kw'], nr: [1, 2, 3, 4], fc: 14 }, { lngs: ['lt'], nr: [1, 2, 10], fc: 15 }, { lngs: ['lv'], nr: [1, 2, 0], fc: 16 }, { lngs: ['mk'], nr: [1, 2], fc: 17 }, { lngs: ['mnk'], nr: [0, 1, 2], fc: 18 }, { lngs: ['mt'], nr: [1, 2, 11, 20], fc: 19 }, { lngs: ['or'], nr: [2, 1], fc: 2 }, { lngs: ['ro'], nr: [1, 2, 20], fc: 20 }, { lngs: ['sl'], nr: [5, 1, 2, 3], fc: 21 }];

var _rulesPluralsTypes = {
1: function _(n) {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ var PluralResolver = function () {
};

PluralResolver.prototype.getRule = function getRule(code) {
return this.rules[this.languageUtils.getLanguagePartFromCode(code)];
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
};

PluralResolver.prototype.needsPlural = function needsPlural(code) {
Expand Down
4 changes: 2 additions & 2 deletions i18next.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i18next",
"version": "9.1.0",
"version": "10.0.0",
"description": "i18next internationalization framework",
"main": "./index.js",
"jsnext:main": "dist/es/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/PluralResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import baseLogger from './logger';
// definition http://translate.sourceforge.net/wiki/l10n/pluralforms
/* eslint-disable */
let sets = [
{ lngs: ['ach','ak','am','arn','br','fil','gun','ln','mfe','mg','mi','oc',
{ lngs: ['ach','ak','am','arn','br','fil','gun','ln','mfe','mg','mi','oc', 'pt', 'pt-BR',
'tg','ti','tr','uz','wa'], nr: [1,2], fc: 1 },

{ lngs: ['af','an','ast','az','bg','bn','ca','da','de','dev','el','en',
'eo','es','et','eu','fi','fo','fur','fy','gl','gu','ha','he','hi',
'hu','hy','ia','it','kn','ku','lb','mai','ml','mn','mr','nah','nap','nb',
'ne','nl','nn','no','nso','pa','pap','pms','ps','pt','rm','sco',
'ne','nl','nn','no','nso','pa','pap','pms','ps','pt-PT','rm','sco',
'se','si','so','son','sq','sv','sw','ta','te','tk','ur','yo'], nr: [1,2], fc: 2 },

{ lngs: ['ay','bo','cgg','fa','id','ja','jbo','ka','kk','km','ko','ky','lo',
Expand Down Expand Up @@ -90,7 +90,7 @@ class PluralResolver {
}

getRule(code) {
return this.rules[this.languageUtils.getLanguagePartFromCode(code)];
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
}

needsPlural(code) {
Expand Down
15 changes: 15 additions & 0 deletions test/pluralResolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ describe('PluralResolver', () => {
{args: ['fr', 10], expected: 'plural'},
{args: ['fr', 10.5], expected: 'plural'},

{args: ['pt', 0], expected: ''},
{args: ['pt', 1], expected: ''},
{args: ['pt', 10], expected: 'plural'},
{args: ['pt', 10.5], expected: 'plural'},

{args: ['pt-PT', 0], expected: 'plural'},
{args: ['pt-PT', 1], expected: ''},
{args: ['pt-PT', 10], expected: 'plural'},
{args: ['pt-PT', 10.5], expected: 'plural'},

{args: ['pt-BR', 0], expected: ''},
{args: ['pt-BR', 1], expected: ''},
{args: ['pt-BR', 10], expected: 'plural'},
{args: ['pt-BR', 10.5], expected: 'plural'},

{args: ['ach', 0], expected: ''},
{args: ['ach', 1], expected: ''},
{args: ['ach', 10], expected: 'plural'},
Expand Down

0 comments on commit c5113fb

Please sign in to comment.