Permalink
Browse files

prepare next major release

  • Loading branch information...
1 parent a7262d0 commit 20f9cf3666969e7eaa73e8f8ca9df6ee962e43de @jamuhl jamuhl committed May 9, 2016
Showing with 77 additions and 26 deletions.
  1. +1 −0 .eslintrc
  2. +2 −1 CHANGELOG.md
  3. +50 −17 i18next.js
  4. +2 −2 i18next.min.js
  5. +3 −0 package.json
  6. +15 −2 src/PluralResolver.js
  7. +4 −4 test/pluralResolver.spec.js
View
@@ -8,6 +8,7 @@ rules:
comma-dangle: [2, "never"]
padded-blocks: [0, "never"]
no-unused-vars: [2, {vars: all, args: none}]
+ prefer-arrow-callback: 1
react/prop-types:
- 0
- ignore: #coming from hoc
View
@@ -1,4 +1,5 @@
-### next
+### 3.0.0
+- **[BREAKING]** per default i18next uses now the same index as used in gettext for plurals. eg. for arabic suffixes are 0,1,2,3,4,5 instead of 0,1,2,3,11,100. You can enforce old behaviour by setting compatibilityJSON = 'v2' on i18next init.
- don't call saveMissing if no lng
### 2.5.1
View
@@ -1094,30 +1094,63 @@
};
PluralResolver.prototype.getSuffix = function getSuffix(code, count) {
+ var _this = this;
+
var rule = this.getRule(code);
if (rule) {
- if (rule.numbers.length === 1) return ''; // only singular
+ var _ret = function () {
+ if (rule.numbers.length === 1) return {
+ v: ''
+ }; // only singular
+
+ var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
+ var suffix = rule.numbers[idx];
+
+ // special treatment for lngs only having singular and plural
+ if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
+ if (suffix === 2) {
+ suffix = 'plural';
+ } else if (suffix === 1) {
+ suffix = '';
+ }
+ }
- var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
- var suffix = rule.numbers[idx];
+ var returnSuffix = function returnSuffix() {
+ return _this.options.prepend && suffix.toString() ? _this.options.prepend + suffix.toString() : suffix.toString();
+ };
- // special treatment for lngs only having singular and plural
- if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
- if (suffix === 2) {
- suffix = 'plural';
- } else if (suffix === 1) {
- suffix = '';
+ // COMPATIBILITY JSON
+ // v1
+ if (_this.options.compatibilityJSON === 'v1') {
+ if (suffix === 1) return {
+ v: ''
+ };
+ if (typeof suffix === 'number') return {
+ v: '_plural_' + suffix.toString()
+ };
+ return {
+ v: returnSuffix()
+ };
}
- }
-
- // COMPATIBILITY JSON
- if (this.options.compatibilityJSON === 'v1') {
- if (suffix === 1) return '';
- if (typeof suffix === 'number') return '_plural_' + suffix.toString();
- }
+ // v2
+ else if (_this.options.compatibilityJSON === 'v2' || rule.numbers.length === 2 && rule.numbers[0] === 1) {
+ return {
+ v: returnSuffix()
+ };
+ }
+ // v3 - gettext index
+ else if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
+ return {
+ v: returnSuffix()
+ };
+ }
+ return {
+ v: _this.options.prepend && idx.toString() ? _this.options.prepend + idx.toString() : idx.toString()
+ };
+ }();
- return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
+ if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v;
} else {
this.logger.warn('no plural rule found for: ' + code);
return '';
View
Oops, something went wrong.
View
@@ -38,6 +38,9 @@
"coveralls": "2.11.9",
"eslint": "2.9.0",
"eslint-config-airbnb": "9.0.1",
+ "eslint-plugin-import": "^1.7.0",
+ "eslint-plugin-jsx-a11y": "^1.2.0",
+ "eslint-plugin-react": "^5.0.1",
"i18next-browser-languagedetector": "0.2.2",
"i18next-localstorage-cache": "0.3.0",
"i18next-sprintf-postprocessor": "0.2.2",
View
@@ -116,13 +116,26 @@ class PluralResolver {
}
}
+ const returnSuffix = () => (
+ this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString()
+ );
+
// COMPATIBILITY JSON
+ // v1
if (this.options.compatibilityJSON === 'v1') {
if (suffix === 1) return '';
if (typeof suffix === 'number') return '_plural_' + suffix.toString();
+ return returnSuffix();
}
-
- return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
+ // v2
+ else if (this.options.compatibilityJSON === 'v2' || (rule.numbers.length === 2 && rule.numbers[0] === 1)) {
+ return returnSuffix();
+ }
+ // v3 - gettext index
+ else if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
+ return returnSuffix();
+ }
+ return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
} else {
this.logger.warn('no plural rule found for: ' + code);
return '';
@@ -59,10 +59,10 @@ describe('PluralResolver', () => {
{args: ['ar', 3], expected: '3'},
{args: ['ar', 4], expected: '3'},
{args: ['ar', 104], expected: '3'},
- {args: ['ar', 11], expected: '11'},
- {args: ['ar', 99], expected: '11'},
- {args: ['ar', 199], expected: '11'},
- {args: ['ar', 100], expected: '100'}
+ {args: ['ar', 11], expected: '4'},
+ {args: ['ar', 99], expected: '4'},
+ {args: ['ar', 199], expected: '4'},
+ {args: ['ar', 100], expected: '5'}
];
tests.forEach((test) => {

0 comments on commit 20f9cf3

Please sign in to comment.