Skip to content

An Angular 2 library to translate messages, dates and numbers

License

Notifications You must be signed in to change notification settings

MedAnd/angular2localization

 
 

Repository files navigation

Angular 2 Localization

npm version

An Angular 2 library to translate messages, dates and numbers.

Sample app built with Angular 2 Material: demo

Get the changelog: releases

Installation

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>

Getting the translation

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.

Scenarios

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

Internationalization API

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.

Boilerplates

Angular 2 Localization with an ASP.NET CORE MVC Service @damienbod

##License MIT

About

An Angular 2 library to translate messages, dates and numbers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.6%
  • JavaScript 2.4%