Core: How to specify language to use in translate pipe?

Created on 14 Nov 2017  路  7Comments  路  Source: ngx-translate/core

I've been searching the documentation and source code for about an hour, but I'm unable to figure out how to force the translate pipe to use a specific language. This is the sort of syntax I'm looking for:

{{'someString' | translate:'en'}}

How do you do that?

Most helpful comment

I don't want to change the language for the whole app, just for one specific translation (to show the English word next to the localized word).

All 7 comments

If you want to set the language for your whole app, in your AppComponent :

constructor(translate: TranslateService) {
    translate.setDefaultLang('en');
}

I don't want to change the language for the whole app, just for one specific translation (to show the English word next to the localized word).

We need the same feature and are searching for an easy way to do this kind of multiple-langs in a module.

Maybe you could try this in your component and bind it to the ui:

var locale = 'en';
translate.getTranslation(locale).subscribe(value => console.log(value.key));

I think this is also discussed in this issue : https://github.com/ngx-translate/core/issues/233

I did not give it a lot of tests, but this seems to do the trick :

import { TranslateService, TranslateParser } from '@ngx-translate/core';

constructor(public translate:TranslateService, public translateParser:TranslateParser) 
{}

public getTranslationInTargetLanguage(key:string, language:string, interpolateParams:Object = null):Observable<any>
{
    return this.translate.getTranslation(language)
               .map( (res) => this.translateParser.interpolate(eval("res."+key),interpolateParams) ); 
}

Duplicate to #233

try this: https://www.npmjs.com/package/ngx-translate-in

{{'key' | translateIn: "fr" | async}}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dankerk picture dankerk  路  3Comments

bjornharvold picture bjornharvold  路  3Comments

pndewit picture pndewit  路  3Comments

rbaumi picture rbaumi  路  4Comments

guysan picture guysan  路  4Comments