An Angular 2 library to translate messages, dates and numbers.
Sample app built with Angular 2 Material: demo
Get the changelog: releases
You can add angular2localization
to your project via Node and npm:
npm install --save angular2localization
To load the package you have two methods:
- Loading the bundle:
<script src="node_modules/angular2localization/bundles/angular2localization.js"></script>
- Using
SystemJS
:
<script>
System.config({
map: {
...
'angular2localization': 'node_modules/angular2localization'
},
packages: {
...
'angular2localization': { defaultExtension: 'js' }
}
});
</script>
Now this library uses pure pipes. To know the advantages over impure pipes, please see here.
Type | Format | Syntax |
---|---|---|
Message | String | `expression |
Date | Date/Number | `expression |
Number | Decimal | `expression |
Number | Percentage | `expression |
Number | Currency | `expression |
To know the full use, see the Wiki page.
Scenario | Scope of | Wiki page |
---|---|---|
First | You need to localize dates and numbers, but no messages | Wiki |
Second | You only need to translate messages | Wiki |
Third | You need to translate messages, dates and numbers | Wiki |
To localize dates and numbers, this library uses Intl
API, through Angular 2.
All modern browsers, except Safari, have implemented this API. You can use Intl.js to extend support to all browsers.
Just add one script tag in your index.html
:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en-US"></script>
When specifying the features
, you have to specify what locale, or locales to load.
N.B. When a feature is not supported, however, for example in older browsers, now angular2localization
does not generate an error in the browser, but returns the value without performing operations.
Angular 2 Localization with an ASP.NET CORE MVC Service @damienbod
##License MIT