Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Valetudox/angular2-translate
https://github.com/Valetudox/angular2-translate
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/Valetudox/angular2-translate
- Owner: Valetudox
- License: mit
- Created: 2015-12-24T05:37:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-19T14:30:41.000Z (almost 8 years ago)
- Last Synced: 2024-09-19T06:18:44.502Z (about 2 months ago)
- Language: TypeScript
- Size: 27.3 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-angular-components - angular2-translate - simple translate service solution for Angular 2 (Uncategorized / Uncategorized)
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']);
}
```