Angular 4 Internalization

I am using Angular 2 localization support for dates and currencies.

Localization is configured at the level of the main application module. In my application module settings, if I configured the provider LOCALE_IDmagically, I have localization support.

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ AppComponent ],
  providers: [
    { provide: LOCALE_ID, useValue: 'nl' }
  ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

Now, if I use a currency pipe in my application as follows:

@Component({
  selector: 'my-app',
  template: '<h1>{{title}}</h1>' +
            '<div>{{convertNumber | currency}}</div>',
})

export class AppComponent {
   title = 'Currency Test';
   convertNumber = '12.30';
}

You can find a working example in this plnkr code .

I got this conclusion USD 12,30.

The exchange rate for the Netherlands is not the dollar.

Based on this question, I have two questions:

  • When do I set up LOCALE_IDwhat exactly happens? Where is this localization file?
  • USD EUR, . (, €) (€), (EUR).

-, Angular 2 .

?

.

+4
1

, :

, currency 159 Source1

formatNumber = > Source2

NumberFormatter.format. locale ( )

, NumberFormatter.format Source3 Intl.NumberFormat

mdn: https://developer.mozilla.org/tr/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat

:

var number = 123456.789;

// request a currency format
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// → 123.456,79 €

, , currency ​​ .

https://github.com/angular/angular/blob/master/packages/common/src/pipes/intl.ts#L34

, Angular locale (, nl - EUR),

options.currency = typeof currency == 'string' ? currency : undefined;

, :

'<div>{{convertNumber | currency:"EUR":true}}</div>',

: https://plnkr.co/edit/Ln6br8ZKQdCbA8Ejn5Cr?p=preview

Angular , USD Source4

+1

Source: https://habr.com/ru/post/1676513/


All Articles