Skip to content

Angular 2 Pipe in TypeScript that is used to translate your app into multi-languages. It also suitable for Inoic 2

License

Notifications You must be signed in to change notification settings

ahlidap/ng2-translate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

ng2-translate

Angular 2 Pipe in TypeScript that is used to translate your app into multi-languages. It is suitable for Inoic 2

Installation

Just copy the file eigonic-translate.ts into your project.

Usage

Follow these steps to use the module:

  1. Import the eiognic module into your code.
  2. Create languages bundle to have all the translations you have.
  3. Initialize the eigonic.Translator with the languages bandle and the default language.
  4. In the template, use the eigonic.Translator pipe named translate to convert the keywords to their translations.

app.component.ts

import { Component } from '@angular/core';
import {LangBundle} from './langBundle';
import {eigonic} from './eigonic-translate';

@Component({
  moduleId: module.id,
  selector: 'app-root',
  template: `
  <h1>
  {{title}}
</h1>

<ul>
  <li>{{'HOME'|translate}}</li>
  <li>{{'NOT TRANSLATED'|translate}}</li>
  <li>{{'SETTINGS'|translate}}</li>
</ul>
  `, 
  pipes: [eigonic.Translator]
})
export class AppComponent {
  title = 'eigonic ng2-translate works!';

  constructor() {
    eigonic.Translator.init(LangBundle.MSG, 'ar');
  }
}

langBundle.ts

export class LangBundle {
    static MSG: any = {
        "en": {
            HOME: 'Home',
            EXPORT: 'Export',
            REPORTS: 'Reports',
            SETTINGS: 'Settings'
        },
        "ar":
        {
            HOME: 'الرئيسية',
            REPORTS: 'التقارير',
            EXPORT: 'Export',
            PROFILE: 'الملف الشخصي',
            SETTINGS: 'الإعدادات'
        }
    };
}

Default language

Default language is used in case the current language is not set. It's some sort of fallback language.

Change/ switch language

To change or switch the current language.

    eigonic.Translator.switchLang('en');

License

It is Apache2 but I personally prefere the WTFPL
WTFPL

Feedback

Feel free to ask for anything.

About

Angular 2 Pipe in TypeScript that is used to translate your app into multi-languages. It also suitable for Inoic 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%