fix(i18n): Currency/Date/Number pipe use injected locale (#11093)

This commit is contained in:
Victor Berchet
2016-08-26 09:16:01 -07:00
committed by GitHub
parent 4d7d2a2daa
commit 0a053a4cd5
5 changed files with 27 additions and 16 deletions

View File

@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Pipe, PipeTransform} from '@angular/core';
import {Inject, LOCALE_ID, Pipe, PipeTransform} from '@angular/core';
import {StringMapWrapper} from '../facade/collection';
import {DateFormatter} from '../facade/intl';
import {DateWrapper, NumberWrapper, isBlank, isDate, isString} from '../facade/lang';
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
// TODO: move to a global configurable location along with other i18n components.
var defaultLocale: string = 'en-US';
/**
* Formats a date value to a string based on the requested format.
@ -96,6 +96,7 @@ export class DatePipe implements PipeTransform {
'shortTime': 'jm'
};
constructor(@Inject(LOCALE_ID) private _locale: string) {}
transform(value: any, pattern: string = 'mediumDate'): string {
if (isBlank(value)) return null;
@ -112,7 +113,7 @@ export class DatePipe implements PipeTransform {
if (StringMapWrapper.contains(DatePipe._ALIASES, pattern)) {
pattern = <string>StringMapWrapper.get(DatePipe._ALIASES, pattern);
}
return DateFormatter.format(value, defaultLocale, pattern);
return DateFormatter.format(value, this._locale, pattern);
}
private supports(obj: any): boolean {