@@ -121,11 +121,11 @@ import {TranslateService} from 'ng2-translate';
121121@Component ({
122122 selector: ' app' ,
123123 template: `
124- <div>{{ 'HELLO' | translate:{value: param} }}</div>
124+ <div>{{ 'HELLO' | translate:param }}</div>
125125 `
126126})
127127export class AppComponent {
128- param: string = ' world' ;
128+ param = {value: ' world' } ;
129129
130130 constructor (translate : TranslateService ) {
131131 // this language will be used as a fallback when a translation isn't found in the current language
@@ -167,11 +167,11 @@ The `TranslateParser` understands nested JSON objects. This means that you can h
167167
168168You can then access the value by using the dot notation, in this case ` HOME.HELLO ` .
169169
170- #### 4. Use the service or the pipe :
170+ #### 4. Use the service, the pipe or the directive :
171171
172- You can either use the ` TranslateService ` or the ` TranslatePipe ` to get your translation values.
172+ You can either use the ` TranslateService ` , the ` TranslatePipe ` or the ` TranslateDirective ` to get your translation values.
173173
174- With the service, it looks like this.
174+ With the ** service** , it looks like this:
175175
176176``` ts
177177translate .get (' HELLO' , {value: ' world' }).subscribe ((res : string ) => {
@@ -180,10 +180,25 @@ translate.get('HELLO', {value: 'world'}).subscribe((res: string) => {
180180});
181181```
182182
183- And this is how you do it with the pipe.
183+ This is how you do it with the ** pipe** :
184184
185185``` html
186- <div >{{ 'HELLO' | translate:{value: param} }}</div >
186+ <div >{{ 'HELLO' | translate:param }}</div >
187+ ```
188+
189+ And in your component define ` param ` like this:
190+ ``` ts
191+ param = {value: ' world' };
192+ ```
193+
194+ This is how you use the ** directive** :
195+ ``` html
196+ <div [translate] =" 'HELLO'" [translateparams] =" {param: 'world'}" ></div >
197+ ```
198+
199+ Or even simpler using the content of your element as a key:
200+ ``` html
201+ <div translate [translateparams] =" {param: 'world'}" >HELLO</div >
187202```
188203
189204#### 5. Use HTML tags:
@@ -196,7 +211,7 @@ You can easily use raw HTML tags within your translations.
196211}
197212```
198213
199- To render them, simply use the ` innerHTML ` attributeon any element.
214+ To render them, simply use the ` innerHTML ` attribute with the pipe on any element.
200215
201216``` html
202217<div [innerHTML] =" 'HELLO' | translate" ></div >
@@ -236,7 +251,7 @@ To render them, simply use the `innerHTML` attributeon any element.
236251- ` setTranslation(lang: string, translations: Object, shouldMerge: boolean = false) ` : Manually sets an object of translations for a given language , set ` shouldMerge ` to true if you want to append the translations instead of replacing them
237252- ` addLangs(langs: Array<string>) ` : Add new langs to the list
238253- ` getLangs() ` : Returns an array of currently available langs
239- - ` get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object> ` : Gets the translated value of a key (or an array of keys )
254+ - ` get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object> ` : Gets the translated value of a key (or an array of keys ) or the key if the value was not found
240255- ` instant(key: string|Array<string>, interpolateParams?: Object): string|Object ` : Gets the instant translated value of a key (or an array of keys ). / ! \ This method is ** synchronous ** and the default file loader is asynchronous . You are responsible for knowing when your translations have been loaded and it is safe to use this method . If you are not sure then you should use the ` get ` method instead .
241256- ` set(key: string, value: string, lang?: string) ` : Sets the translated value of a key
242257- ` reloadLang(lang: string): Observable<string|Object> ` : Calls resetLang and retrieves the translations object for the current loader
@@ -310,7 +325,7 @@ export class AppModule { }
310325
311326### Parser
312327
313- If you need it for some reason , you can use the ` TranslateParser ` service .
328+ If you need it for some reason , you can use the ` DefaultParser ` service .
314329
315330#### Methods :
316331- ` interpolate(expr: string, params?: any): string ` : Interpolates a string to replace parameters .
@@ -344,6 +359,7 @@ Ionic 2 is still using angular 2 RC4, but ng2-translate uses RC5. You should fix
344359
345360## Plugins
346361- [Localize Router ](https :// github.com/Greentube/localize-router) by @meeroslav: An implementation of routes localization for Angular 2. If you need localized urls (for example /fr/page and /en/page).
362+ - [.po files Loader ](https :// www.npmjs.com/package/@biesbjerg/ng2-translate-po-loader) by @biesbjerg: Use .po translation files with ng2-translate
347363
348364
349365## Additional Framework Support
0 commit comments