Allow a custom pattern for the Intl currency constructor
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178254504
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c7304c..1da230e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.15.3
+ * Add a customPattern parameter to the currency constructor. This can be used
+ to provide a custom pattern if you have one, e.g. for accounting formats.
+
## 0.15.2
* Group the padding digits to the left of the number, if present. e.g. 00,001.
* Tweak lookup code to support translated messages as JSON rather than code.
diff --git a/lib/src/intl/number_format.dart b/lib/src/intl/number_format.dart
index 4b187e3..4ca2d22 100644
--- a/lib/src/intl/number_format.dart
+++ b/lib/src/intl/number_format.dart
@@ -238,10 +238,18 @@
/// currency's default takes priority over the locale's default.
/// new NumberFormat.currency(locale: 'en_US')
/// will format with two, which is the default for that locale.
+ ///
+ /// The [customPattern] parameter can be used to specify a particular
+ /// format. This is useful if you have your own locale data which includes
+ /// unsupported formats (e.g. accounting format for currencies.)
// TODO(alanknight): Should we allow decimalDigits on other numbers.
NumberFormat.currency(
- {String locale, String name, String symbol, int decimalDigits})
- : this._forPattern(locale, (x) => x.CURRENCY_PATTERN,
+ {String locale,
+ String name,
+ String symbol,
+ int decimalDigits,
+ String customPattern})
+ : this._forPattern(locale, (x) => customPattern ?? x.CURRENCY_PATTERN,
name: name,
currencySymbol: symbol,
decimalDigits: decimalDigits,
diff --git a/pubspec.yaml b/pubspec.yaml
index c658519..9c14eda 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: intl
-version: 0.15.2
+version: 0.15.3-dev
author: Dart Team <misc@dartlang.org>
description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
homepage: https://github.com/dart-lang/intl
diff --git a/test/number_format_test.dart b/test/number_format_test.dart
index aa0363c..91ddab2 100644
--- a/test/number_format_test.dart
+++ b/test/number_format_test.dart
@@ -260,6 +260,15 @@
var padded = format.format(0);
expect(padded, '٠٠٠');
});
+
+ // Exercise a custom pattern. There's not actually much logic here, so just
+ // validate that the custom pattern is in fact being used.
+ test('Custom currency pattern', () {
+ var format = new NumberFormat.currency(
+ name: 'XYZZY', customPattern: '[\u00a4][#,##.#]');
+ var text = format.format(12345.67);
+ expect(text, '[XYZZY][1,23,45.67]');
+ });
}
String stripExtras(String input) {