-
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.
Currency: Implement currency formatting (symbol mode) (1/2)
- Loading branch information
Showing
15 changed files
with
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*! | ||
* Globalize v@VERSION | ||
* | ||
* http://github.com/jquery/globalize | ||
* | ||
* Copyright 2010, 2014 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", | ||
"./number", | ||
"cldr/event" | ||
], 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 ) { | ||
|
||
var alwaysArray = Globalize._alwaysArray, | ||
formatMessage = Globalize._formatMessage, | ||
numberNumberingSystem = Globalize._numberNumberingSystem, | ||
validateCldr = Globalize._validateCldr, | ||
validateDefaultLocale = Globalize._validateDefaultLocale, | ||
validateParameterPresence = Globalize._validateParameterPresence, | ||
validateParameterType = Globalize._validateParameterType, | ||
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 @@ | ||
define([], function() { | ||
|
||
/** | ||
*/ | ||
return function( /* currency, cldr, options */ ) { | ||
// FIXME | ||
}; | ||
|
||
}); |
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,17 @@ | ||
define([ | ||
"../common/format-message" | ||
], function( formatMessage ) { | ||
|
||
/** | ||
*/ | ||
return function( value, pluralForm, properties ) { | ||
var displayNames = properties.displayNames, | ||
unitPatterns = properties.unitPatterns; | ||
|
||
return formatMessage( unitPatterns[ pluralForm ] || unitPatterns.other, [ | ||
value, | ||
displayNames[ pluralForm ] || displayNames.other | ||
]); | ||
}; | ||
|
||
}); |
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,9 @@ | ||
define([], function() { | ||
|
||
/** | ||
*/ | ||
return function( /*currency, cldr, options */ ) { | ||
// FIXME | ||
}; | ||
|
||
}); |
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,59 @@ | ||
define([ | ||
"../common/regexp-not-s", | ||
"../number/numbering-system" | ||
], function( regexpNotS, numberNumberingSystem ) { | ||
|
||
/** | ||
* symbolPattern( currency, cldr ) | ||
* | ||
* Return pattern replacing `¤` with the appropriate currency symbol literal. | ||
*/ | ||
return function( currency, cldr ) { | ||
var currencySpacing, pattern, | ||
regexp = { | ||
"[:digit:]": /\d/, | ||
"[:^S:]": regexpNotS | ||
}, | ||
symbol = cldr.main([ | ||
"numbers/currencies", | ||
currency, | ||
"symbol" | ||
]); | ||
|
||
currencySpacing = [ "beforeCurrency", "afterCurrency" ].map(function( position ) { | ||
return cldr.main([ | ||
"numbers", | ||
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ), | ||
"currencySpacing", | ||
position | ||
]); | ||
}); | ||
|
||
// TODO: Allow other `u-cu`s [1]. | ||
pattern = cldr.main([ | ||
"numbers", | ||
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ), | ||
"standard" /* 1 */ | ||
]); | ||
|
||
return pattern.split( ";" ).map(function( pattern ) { | ||
|
||
// "\u00A4" = "¤" | ||
return pattern.split( "\u00A4" ).map(function( part, i ) { | ||
var currencyMatch = regexp[ currencySpacing[ i ].currencyMatch ], | ||
surroundingMatch = regexp[ currencySpacing[ i ].surroundingMatch ], | ||
insertBetween = ""; | ||
|
||
if ( currencyMatch.test( symbol.charAt( i ? symbol.length - 1 : 0 ) ) && part && | ||
surroundingMatch.test( | ||
part.charAt( i ? 0 : part.length - 1 ).replace( /[#@,.]/g, "0" ) | ||
) ) { | ||
insertBetween = currencySpacing[ i ].insertBetween; | ||
} | ||
|
||
return ( i ? insertBetween : "" ) + part + ( i ? "" : insertBetween ); | ||
}).join( "'" + symbol + "'" ); | ||
}).join( ";" ); | ||
}; | ||
|
||
}); |
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,20 @@ | ||
define([ | ||
"../always-array" | ||
], function( alwaysArray ) { | ||
|
||
return function( object, keys ) { | ||
var key, | ||
copy = {}; | ||
|
||
keys = alwaysArray( keys ); | ||
|
||
for ( key in object ) { | ||
if ( keys.indexOf( key ) === -1 ) { | ||
copy[ key ] = object[ key ]; | ||
} | ||
} | ||
|
||
return copy; | ||
}; | ||
|
||
}); |
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
Oops, something went wrong.