SOURCE CODE: Uize.Loc.Plurals.Langs.ar (view docs)

/*______________
|       ______  |   U I Z E    J A V A S C R I P T    F R A M E W O R K
|     /      /  |   ---------------------------------------------------
|    /    O /   |    MODULE : Uize.Loc.Plurals.Langs.ar Package
|   /    / /    |
|  /    / /  /| |    ONLINE : http://uize.com
| /____/ /__/_| | COPYRIGHT : (c)2015-2016 UIZE
|          /___ |   LICENSE : Available under MIT License or GNU General Public License
|_______________|             http://uize.com/license.html
*/

/* Module Meta Data
  type: Package
  importance: 1
  codeCompleteness: 100
  docCompleteness: 100
*/

/*?
  Introduction
    The =Uize.Loc.Plurals.Langs.ar= module implements a feature for determining a plural category from a number value for the ar language.

    *DEVELOPERS:* `Chris van Rensburg`

    Plural Categories
      ........................................................
      << table >>

      title: Plural Categories
      data:
      :| Category | Rule |
      :| zero | n = 0 @integer 0 @decimal 0.0, 0.00, 0.000, 0.0000 |
      :| one | n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000 |
      :| two | n = 2 @integer 2 @decimal 2.0, 2.00, 2.000, 2.0000 |
      :| few | n % 100 = 3..10 @integer 3~10, 103~110, 1003, … @decimal 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 103.0, 1003.0, … |
      :| many | n % 100 = 11..99 @integer 11~26, 111, 1011, … @decimal 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 111.0, 1011.0, … |
      :| other |  @integer 100~102, 200~202, 300~302, 400~402, 500~502, 600, 1000, 10000, 100000, 1000000, … @decimal 0.1~0.9, 1.1~1.7, 10.1, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … |
      ........................................................
*/

Uize.module ({
  name:'Uize.Loc.Plurals.Langs.ar',
  required:'Uize.Loc.Plurals.Util',
  builder:function () {
    'use strict';

    return Uize.package ({
      getPluralCategory:function (_value) {
        return Uize.Loc.Plurals.Util.getPluralCategory (
          _value,
          function (n,i,f,t,v,w,within) {
            return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : within (n % 100,[[3,10]]) ? 'few' : within (n % 100,[[11,99]]) ? 'many' : 'other';
          }
        );
      }
    });
  }
});