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?
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}}
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).