49756435a81e2b4606bbb3333dabe0000c982038.svn-base 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. if (!dojo._hasResource["dojo.currency"]) { // _hasResource checks added by
  2. // build. Do not use _hasResource
  3. // directly in your code.
  4. dojo._hasResource["dojo.currency"] = true;
  5. dojo.provide("dojo.currency");
  6. dojo.require("dojo.number");
  7. dojo.require("dojo.i18n");
  8. dojo.requireLocalization("dojo.cldr", "currency", null,
  9. "ko,zh,ja,en,en-ca,en-au,ROOT,en-us,it,fr,pt,es,de");
  10. dojo.require("dojo.cldr.monetary");
  11. dojo.currency._mixInDefaults = function(options) {
  12. options = options || {};
  13. options.type = "currency";
  14. // Get locale-depenent currency data, like the symbol
  15. var bundle = dojo.i18n.getLocalization("dojo.cldr", "currency",
  16. options.locale)
  17. || {};
  18. // Mixin locale-independent currency data, like # of places
  19. var iso = options.currency;
  20. var data = dojo.cldr.monetary.getData(iso);
  21. dojo.forEach(["displayName", "symbol", "group", "decimal"], function(
  22. prop) {
  23. data[prop] = bundle[iso + "_" + prop];
  24. });
  25. data.fractional = [true, false];
  26. // Mixin with provided options
  27. return dojo.mixin(data, options);
  28. }
  29. dojo.currency.format = function(/* Number */value, /* Object? */options) {
  30. // summary:
  31. // Format a Number as a String, using locale-specific settings
  32. //
  33. // description:
  34. // Create a string from a Number using a known localized pattern.
  35. // Formatting patterns appropriate to the locale are chosen from the
  36. // CLDR http://unicode.org/cldr
  37. // as well as the appropriate symbols and delimiters. See
  38. // http://www.unicode.org/reports/tr35/#Number_Elements
  39. //
  40. // value:
  41. // the number to be formatted.
  42. //
  43. // options: object {currency: String, pattern: String?, places: Number?,
  44. // round: Number?, symbol: String?, locale: String?}
  45. // currency- the ISO4217 currency code, a three letter sequence like
  46. // "USD"
  47. // See http://en.wikipedia.org/wiki/ISO_4217
  48. // symbol- override currency symbol. Normally, will be looked up in
  49. // table of supported currencies, and ISO currency code will
  50. // be used if not found. See dojo.i18n.cldr.nls->currency.js
  51. // pattern- override formatting pattern with this string (see
  52. // dojo.number.applyPattern)
  53. // places- fixed number of decimal places to show. Default is defined by
  54. // the currency.
  55. // round- 5 rounds to nearest .5; 0 rounds to nearest whole (default).
  56. // -1 means don't round.
  57. // locale- override the locale used to determine formatting rules
  58. return dojo.number.format(value, dojo.currency._mixInDefaults(options));
  59. }
  60. dojo.currency.regexp = function(/* Object? */options) {
  61. //
  62. // summary:
  63. // Builds the regular needed to parse a number
  64. //
  65. // description:
  66. // Returns regular expression with positive and negative match, group
  67. // and decimal separators
  68. //
  69. // options: object {pattern: String, locale: String, strict: Boolean,
  70. // places: mixed}
  71. // currency- the ISO4217 currency code, a three letter sequence like
  72. // "USD"
  73. // See http://en.wikipedia.org/wiki/ISO_4217
  74. // symbol- override currency symbol. Normally, will be looked up in
  75. // table of supported currencies, and ISO currency code will
  76. // be used if not found. See dojo.i18n.cldr.nls->currency.js
  77. // pattern- override pattern with this string
  78. // locale- override the locale used to determine formatting rules
  79. // strict- strict parsing, false by default
  80. // places- number of decimal places to accept. Default is defined by
  81. // currency.
  82. return dojo.number.regexp(dojo.currency._mixInDefaults(options)); // String
  83. }
  84. dojo.currency.parse = function(/* String */expression, /* Object? */options) {
  85. //
  86. // summary:
  87. // Convert a properly formatted string to a primitive Number,
  88. // using locale-specific settings.
  89. //
  90. // description:
  91. // Create a Number from a string using a known localized pattern.
  92. // Formatting patterns are chosen appropriate to the locale.
  93. // Formatting patterns are implemented using the syntax described at
  94. // *URL*
  95. //
  96. // expression: A string representation of a Number
  97. //
  98. // options: object {pattern: string, locale: string, strict: boolean}
  99. // currency- the ISO4217 currency code, a three letter sequence like
  100. // "USD"
  101. // See http://en.wikipedia.org/wiki/ISO_4217
  102. // symbol- override currency symbol. Normally, will be looked up in
  103. // table of supported currencies, and ISO currency code will
  104. // be used if not found. See dojo.i18n.cldr.nls->currency.js
  105. // pattern- override pattern with this string
  106. // locale- override the locale used to determine formatting rules
  107. // strict- strict parsing, false by default
  108. // places- number of decimal places to accept. Default is defined by
  109. // currency.
  110. // fractional- where places are implied by pattern or explicit 'places'
  111. // parameter, whether to include the fractional portion.
  112. // By default for currencies, it the fractional portion is optional.
  113. return dojo.number.parse(expression, dojo.currency
  114. ._mixInDefaults(options));
  115. }
  116. }