-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Borrow santhoshtr/CLDRPluralRuleParser. Ref #220
- Loading branch information
Showing
12 changed files
with
1,097 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Globalize.plural( value [, locale] ) | ||
|
||
Return the count group String: `zero`, `one`, `two`, `few`, `many`, or `other`. | ||
|
||
### Parameters | ||
|
||
**value** | ||
|
||
Number to be formatted, eg. `0` (integer), or `3.14` (decimal). | ||
|
||
**locale** Optional | ||
|
||
Locale string that overrides default. | ||
|
||
|
||
### Example | ||
|
||
```javascript | ||
Globalize.locale( "en" ); | ||
Globalize.plural( 0 ); // "other" | ||
Globalize.plural( 1 ); // "one" | ||
Globalize.plural( 2 ); // "other" | ||
|
||
Globalize.plural( 0, "ar" ); // "zero" | ||
Globalize.plural( 1, "ar" ); // "one" | ||
Globalize.plural( 2, "ar" ); // "two" | ||
Globalize.plural( 3, "ar" ); // "few" | ||
|
||
Globalize.plural( 0, "ru" ); // "many" | ||
Globalize.plural( 1, "ru" ); // "one" | ||
Globalize.plural( 2, "ru" ); // "few" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*! | ||
* Globalize v@VERSION | ||
* | ||
* http://github.com/jquery/globalize | ||
* | ||
* Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors | ||
* Released under the MIT license | ||
* http://jquery.org/license | ||
* | ||
* Date: @DATE | ||
*/ | ||
(function( root, factory ) { | ||
|
||
// UMD returnExports | ||
if ( typeof define === "function" && define.amd ) { | ||
|
||
// AMD | ||
define([ | ||
"cldr", | ||
"../globalize" | ||
], factory ); | ||
} else if ( typeof exports === "object" ) { | ||
|
||
// Node, CommonJS | ||
module.exports = factory( require( "cldrjs" ), require( "globalize" ) ); | ||
} else { | ||
|
||
// Global | ||
factory( root.Cldr, root.Globalize ); | ||
} | ||
}(this, function( Cldr, Globalize ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
define([ | ||
"./common/get-locale", | ||
"./core", | ||
"./plural/form" | ||
], function( commonGetLocale, Globalize, pluralForm ) { | ||
|
||
/** | ||
* Globalize.plural( value, locale ) | ||
* | ||
* @value [Number] | ||
* | ||
* @locale [String] | ||
* | ||
* Return the count group String: zero | one | two | few | many | other. | ||
*/ | ||
Globalize.plural = function( value, locale ) { | ||
var form; | ||
|
||
if ( typeof value !== "number" ) { | ||
throw new Error( "Value is not a number" ); | ||
} | ||
|
||
locale = commonGetLocale( locale ); | ||
|
||
if ( !( form = pluralForm( value, locale ) ) ) { | ||
throw new Error( "Plural form not found!" ); | ||
} | ||
|
||
return form; | ||
}; | ||
|
||
return Globalize; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
define([ | ||
"CLDRPluralRuleParser", | ||
"./rules" | ||
], function( CLDRPluralRuleParser, pluralRules ) { | ||
|
||
/** | ||
* pluralForm( value, cldr ) | ||
* | ||
* @value [Number] | ||
* | ||
* @cldr [Cldr instance]. | ||
* | ||
* Return the corresponding form (zero | one | two | few | many | other) of a value given locale @cldr. | ||
*/ | ||
return function( value, cldr ) { | ||
var form, | ||
rules = pluralRules( cldr ); | ||
|
||
for( form in rules ) { | ||
if( CLDRPluralRuleParser( rules[ form ], value ) ) { | ||
return form.replace( /pluralRule-count-/, "" ); | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
define(function() { | ||
|
||
/** | ||
* pluralRules( cldr ) | ||
* | ||
* @cldr [Cldr instance]. | ||
* | ||
* Return all the plural rules of a language. | ||
*/ | ||
return function( cldr ) { | ||
return cldr.supplemental( "plurals-type-cardinal/{language}" ); | ||
}; | ||
|
||
}); |
Oops, something went wrong.