Angular 2 Localization
An Angular 2 library to translate messages, dates and numbers.
This library is developed using TypeScript and Angular 2 for i18n and l10n of Angular 2 apps written in TypeScript, ES5 or ES6. It allows, in addition to translation, to localize numbers and dates of your app, adding language code, country code, and optionally script code, numbering system and calendar, through Internationalization API. It also implements the validation of numbers by locales.
Sample app built with Angular 2 Material, AoT compilation & webpack, and its source code.
Get the changelog by releases.
Angular version: ^2.4.0
Angular 2 i18n solutions
Feature | Angular 2 Native | ng2-translate External library | angular2localization External library |
---|---|---|---|
Messages | Html attribute, Message ID | Html attribute, impure pipe | Html attribute, pure pipe |
File formats | XLIFF, XMB/XTB | JSON | JSON |
No bootstrap (when language changes) | no | yes | yes |
Getting the translation in component class | not yet | yes | yes |
Numbers | pure pipe via Intl | - | Html attribute & pure pipe via Intl |
Dates | pure pipe via Intl | - | Html attribute & pure pipe via Intl |
Validation | - | - | numbers validation |
Installing
You can add angular2localization
to your project using npm
:
npm install --save angular2localization
Loading
Using SystemJS configuration
System.config({ paths: { 'npm:': 'node_modules/' }, map: { app: 'app', // angular bundles ... // other libraries 'rxjs': 'npm:rxjs', 'angular2localization': 'npm:angular2localization/bundles/angular2localization.umd.min.js' }, packages: { app: { format: 'cjs', main: './main.js', defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' } } });
Angular-CLI
No need to set up anything, just import it in your code.
Tree shaking via rollup or webpack
No need to set up anything, just import it in your code.
Ionic 2
Using Ionic 2 with this library.
Angular 2 Meteor
Using Angular 2 Meteor with this library.
Plain JavaScript
If you build apps in Angular 2 using ES5, you can include the umd
bundle in your index.html
:
<script src="node_modules/angular2localization/bundles/angular2localization.umd.min.js"></script>
and using global ng.angular2localization
namespace. For a basic usage, see this ES5 example.
AoT compilation
This library is compatible with AoT compilation, just import it in your code.
Usage
See quick start and library specification.
Related projects
Angular 2 Localization with an ASP.NET CORE MVC Service @damienbod
Building
In order to build the library if you want to contribute to it:
npm install npm test npm run build
To test locally the npm package:
npm pack ./dist
Then you can install it in your app to test it:
npm install [path]angular2localization-[version].tgz
License
MIT