I am trying to change the URL when someone clicks on a choosen language using ngx-translate. I guess I should do it by subscribing to language change events and then modifying the current url to reflect the chosen language, Since I am a newbie I am not sure if I need a service to do it, or may be another way to solve it.
I want to change from this:
https://amarello.cloud/es/
To this:
https://amarello.cloud/en/
,depending on the choosen language.
This is my 'header.component.ts'
import { Component, OnInit } from '@angular/core';
//For translate language
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
menu: boolean = false;
submenu: boolean = false;
submin: boolean = false;
constructor(private translate: TranslateService)
{ translate.addLangs(['es','en']);
translate.setDefaultLang('es');
}
ngOnInit(): void {
}
open() {
if (this.menu == false) {
this.menu = true;
} else {
this.menu = false
}
if (this.submin == false) {
this.submin = true;
} else {
this.submin = false
}
}
openSub() {
if (this.submenu == false) {
this.submenu = true;
} else {
this.submenu = false
}
}
useLanguage(language: string): void {
this.translate.use(language);
// this.translate.onLangChange().subscribe(trans => {
// })
}
}