Socket
Socket
Sign inDemoInstall

angular-l10n

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-l10n

An Angular library to translate messages, dates and numbers


Version published
Weekly downloads
9.1K
decreased by-2.5%
Maintainers
1
Weekly downloads
 
Created
Source

Angular localization

Build Status npm version

An Angular library to translate messages, dates and numbers.

This library is for localization of Angular 2+ apps written in TypeScript, ES6 or ES5. 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 Material, AoT compilation & webpack, and its source code.

Get the changelog by releases.

Angular i18n solutions

FeatureAngular Officialngx-translate External libraryangular-l10n External library
MessagesHtml attributes, message IDsdirectives, impure pipesdirectives, pure pipes
File formatsXLIFF, XMB/XTBJSONJSON
No bootstrap (when language changes)noyesyes
Getting the translation in component classnot yetyesyes
Numberspure pipes using CLDR-directives & pure pipes via Intl
Datespure pipes using CLDR-directives & pure pipes via Intl
Validation--numbers validation

Installing

You can add angular-l10n to your project using npm:

npm install angular-l10n --save 

To install the prerelease package:

npm install --save angular-l10n@next

Loading

Using SystemJS configuration
System.config({
    map: {
        'angular-l10n': 'node_modules/angular-l10n/bundles/angular-l10n.umd.js'
    }
});
Angular CLI

No need to set up anything, just import it in your code.

Rollup or webpack

No need to set up anything, just import it in your code.

Plain JavaScript

If you build apps in Angular using ES5, you can include the umd bundle in your index.html:

<script src="node_modules/angular-l10n/bundles/angular-l10n.umd.js"></script>

and use global ng.l10n namespace.

AoT compilation, Server Side Rendering & strict

This library is compatible with AoT compilation & Server Side Rendering. It also supports the strict TypeScript compiler option.

Usage

Configuration

const l10nConfig: L10nConfig = {
    locale: {
        languages: [
            { code: 'en', dir: 'ltr' },
            { code: 'it', dir: 'ltr' }
        ],
        defaultLocale: { languageCode: 'en', countryCode: 'US' },
        currency: 'USD',
        storage: StorageStrategy.Cookie
    },
    translation: {
        providers: [
            { type: ProviderType.Static, prefix: './assets/locale-' }
        ],
        caching: true,
        missingValue: 'No key'
    }
};

@NgModule({
    imports: [
        ...
        HttpClientModule,
        LocalizationModule.forRoot(l10nConfig)
    ],
    ...
})
export class AppModule {

    constructor(public l10nLoader: L10nLoader) {
        this.l10nLoader.load();
    }

}

Pure pipes with Decorators

@Component({
    ...
    template: `
        <p>{{ 'Greeting' | translate:lang }}</p>

        <p title="{{ 'Greeting' | translate:lang }}">{{ 'Title' | translate:lang }}</p>

        <p>{{ today | l10nDate:defaultLocale:'fullDate' }}</p>       
        <p>{{ pi | l10nDecimal:defaultLocale:'1.5-5' }}</p>
        <p>{{ value | l10nCurrency:defaultLocale:currency:'symbol':'1.2-2' }}</p>
    `
})
export class HomeComponent implements OnInit {

    @Language() lang: string;
    @DefaultLocale() defaultLocale: string;
    @Currency() currency: string;
    
    ngOnInit(): void { }

}

Directives

@Component({
    ...
    template: `
        <p l10nTranslate>Greeting</p>

        <p l10n-title title="Greeting" l10nTranslate>Title</p>

        <p l10nDate="fullDate">{{ today }}</p>    
        <p l10nDecimal="1.5-5">{{ pi }}</p>
        <p l10nCurrency="1.2-2" [currencyDisplay]="'symbol'">{{ value }}</p>
    `
})
export class HomeComponent {}

See the following documentation to learn more about all the features:

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

Contributing

License

MIT

Keywords

FAQs

Package last updated on 27 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc