How to switch language at runtime. I am not able to switch language using:
import { TranslateService } from “@ngx-translate/core”;
export class SomeClass {
constructor(private translate:TranslateService){
}
changeLanguage=()=>{
this.translate.setDefaultLang(“en”);
if (this.translate.getBrowserLang() !== undefined) {
this.translate.use(this.translate.getBrowserLang());
} else {
this.translate.use("hi");
}
}
}
}
Where does this come from?
import { TranslateService } from “@ngx-translate/core”;
export class SomeClass {
constructor(private translate:TranslateService){
}
changeLanguage=()=>{
this.translate.setDefaultLang(“en”);
if (this.translate.getBrowserLang() !== undefined) {
this.translate.use(this.translate.getBrowserLang());
} else {
this.translate.use("hi");
}
}
}
}
Then this has nothing to do with Ionic Native, changed the category.
I’m using this ion-select
component
<ion-select [(ngModel)]="language" (ionChange)="switchLanguage()">
<ion-option value="de">Deutsch</ion-option>
<ion-option value="es">Español</ion-option>
<ion-option value="en">English</ion-option>
<ion-option value="fr">Français</ion-option>
</ion-select>
And in your ts
just
language: string = "es";
switchLanguage() {
this.translate.use(this.language);
}
I am doing same but it is not working. Can you please tell ? At how many places you are importing TranslateModule ?
Only app.module.ts
on imports
array.
Can you please show me you app.module.ts
file?
These line are only available in app.module.ts in imports:[]
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
})
How can i change language on toggle ?