Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Feb 28, 2016
1 parent 5997702 commit e5729f0
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ translate.setTranslation('en', {
- `use(lang: string): Observable<any>`: Changes the lang currently used
- `getTranslation(lang: string): Observable<any>`: Gets an object of translations for a given language with the current loader
- `setTranslation(lang: string, translations: Object)`: Manually sets an object of translations for a given language
- `setMissingTranslationHandler(handler: MissingTranslationHandler): void`: sets the Missing Translation Handler which will be
used when the requested translation is not available
- `getLangs()`: Returns an array of currently available langs
- `get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>`: Gets the translated value of a key (or an array of keys)
- `instant(key: string|Array<string>, interpolateParams?: Object): string|Object`: Gets the instant translated value of a key (or an array of keys)
Expand All @@ -118,10 +120,10 @@ translate.setTranslation('en', {
#### Write & use your own loader
If you want to write your own loader, you need to create a class that implements `TranslateLoader`.
The only required method is `getTranslation` that must return an `Observable`. If your loader is synchronous, just use `Observable.of` to create an observable from your static value.

##### Example
```js
class CustomLoader implements TranslateLoader {
constructor() {}

getTranslation(lang: string): Observable<any> {
return Observable.of({"KEY": "Value"});
}
Expand All @@ -146,37 +148,16 @@ export class AppComponent {
}
```

### TranslatePipe
You can call the TranslatePipe with some optional parameters that will be transpolated into the translation for the given key.

Example:
```html
<p>Say {{ 'HELLO' | translate:{value: "world"} }}</p>
```

With the given translation: `"HELLO": "hello {{value}}"`.
#### How to handle missing translations
You can use the method `setMissingTranslationHandler` to define a handler that will be called when the requested translation is not available.
The only required method is `handle` where you can do whatever you want. Just don't forget that it will be called synchronously from the `get` & `instant` methods.

### Parser
#### Methods:
- `interpolate(expr: string, params?: any): string`: Interpolates a string to replace parameters.

`This is a {{ key }}` ==> `This is a value` with `params = { key: "value" }`
- `flattenObject(target: Object): Object`: Flattens an object
`{ key1: { keyA: 'valueI' }}` ==> `{ 'key1.keyA': 'valueI' }`


### Missing Translation Handler
#### Methods:
- `setMissingTranslationHandler(handler: MissingTranslationHandler): void`: sets the Missing Translation Handler which will be
used when the requested translation is not available

#### Example:
Create an Missing Translation Handler
##### Example:
Create a Missing Translation Handler
```js
import {MissingTranslationHandler} from 'ng2-translate/ng2-translate';

export class MyMissingTranslationHandler implements MissingTranslationHandler {

handle(key: string) {
console.log(key);
}
Expand All @@ -191,3 +172,22 @@ constructor(translate: TranslateService) {
...
}
```

### TranslatePipe
You can call the TranslatePipe with some optional parameters that will be transpolated into the translation for the given key.

Example:
```html
<p>Say {{ 'HELLO' | translate:{value: "world"} }}</p>
```

With the given translation: `"HELLO": "hello {{value}}"`.

### Parser
#### Methods:
- `interpolate(expr: string, params?: any): string`: Interpolates a string to replace parameters.

`This is a {{ key }}` ==> `This is a value` with `params = { key: "value" }`
- `flattenObject(target: Object): Object`: Flattens an object
`{ key1: { keyA: 'valueI' }}` ==> `{ 'key1.keyA': 'valueI' }`

0 comments on commit e5729f0

Please sign in to comment.