Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Valetudox/angular2-translate


https://github.com/Valetudox/angular2-translate

Last synced: 9 days ago
JSON representation

Awesome Lists containing this project

README

        

# Angular2 translate

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

This is a simple translate service solution for angular2. You should provide a dictionary and the service will translate it with sprintf interpolation.

Install
---------

```bash
npm install --save angular2-translate
```
Setup
---------

```javascript

import { TranslateModule } from 'angular2-translate';

const translations = {
useValue: {
main: {
text: 'I am: %s you are: %s'
},
other: {
withoutInterpolation: 'Star Wars'
}
}
};

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

```

Usage in template
---------

```javascript

import { TranslatePipe } from 'angular2-translate';

@Component({
selector: '',
template: `

{{ 'main.text' | translate:'Luke':controllerVariable }}


{{ 'other.withoutInterpolation' | translate }}


`
})
export class App {

constructor() {
this.controllerVariable = 'Darth Vader';
}
```

Usage in Controller
---------

```javascript

import { TranslateService } from 'angular2-translate';

@Component({
selector: '',
template: `Some content`
})
export class App {

constructor(translateService: TranslateService) {
this.translated = translateService.translate('main.text', ['first', 'second']);
}
```