@emceearjun/translate
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

translate

translate provides a simple extension to help integrate internationalization with your Angular application.

Installation

npm install @emceearjun/translate --save-dev

Usage

Component

First step is to import TranslateModule into your NgModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { TranslateModule } from '@emceearjun/translate';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    TranslateModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Translations

Place two files en.json and fr.json directly in your assets folder with the following content:
Note: Replace "hello" with your desired translation in fr.json

{
    "h1": {
        "heading": "hello"
    }
}

Template

Now, use the translate pipe in your template file as follows:

<h1>{{"h1.heading" | translate | async}}</h1>

Running the application

For your translation to work, you need to provide your locale as a search parameter with your URL:

http://localhost:4200/?lang=en
http://localhost:4200/?lang=fr

Voila! That's it!

Readme

Keywords

Package Sidebar

Install

npm i @emceearjun/translate

Weekly Downloads

1

Version

0.0.4

License

MIT

Unpacked Size

119 kB

Total Files

33

Last publish

Collaborators

  • emceearjun