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.1.0
Feature | Angular 2 Native | ng2-translate External library | angular2localization External library |
---|---|---|---|
Messages | Html attribute, Message ID | impure pipe | pure pipe |
File formats | XLIFF, XMB/XTB | JSON | JSON |
No bootstrap (when language changes) | no | yes | yes |
Getting the translation in component class | ? | yes | yes |
Numbers | pure pipe via Intl | - | pure pipe via Intl |
Dates | pure pipe via Intl | - | pure pipe via Intl |
Validation | - | - | numbers validation |
You can add angular2localization
to your project using npm
:
npm install --save angular2localization
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'
}
}
});
No need to set up anything, just import it in your code.
No need to set up anything, just import it in your code.
Using Ionic 2 with this library.
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.
This library is compatible with AoT compilation, just import it in your code.
See quick start and library specification.
Angular 2 Localization with an ASP.NET CORE MVC Service @damienbod
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