Centralized translations

This commit is contained in:
grata
2023-05-05 11:35:33 +02:00
parent d072dca42c
commit ea70e73359
8 changed files with 67 additions and 80 deletions

View File

@@ -11,16 +11,6 @@
</div>
</div>
<div class="dropdown dropdown-hover" id="translate">
<label tabindex="0" class="btn m-1 bg-black border-neutral text-base-100">{{translations.translate}}</label>
<ul tabindex="0" class="dropdown-content menu p-2 shadow rounded-box w-52">
<li (click)="switchLanguage('DE')"><a>DE</a></li>
<li (click)="switchLanguage('FR')"><a>FR</a></li>
<li (click)="switchLanguage('IT')"><a>IT</a></li>
<li (click)="switchLanguage('EN')"><a>EN</a></li>
</ul>
</div >
<div class="bg-image">
<div class="search">

View File

@@ -44,7 +44,6 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
// Initializes the component and loads translations and locations
ngOnInit(): void {
this.translations = this.readTranslationJsonService.getHomeTranslations();
console.log("translations loaded", this.translations);
this.username= this.cookieService.getUsername();
this.locationService.getLocations()
.subscribe(locations => {
@@ -130,18 +129,6 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy {
this.router.navigate(['/location', nomeLocation]);
}
}
// This async function is used to switch the language of the application.
// It takes a language code as input and updates the translations object with new translations for various UI elements.
// The getData() method of the translateService is called with the current translations and the new language code.
// The translateService returns the translated data which is then assigned to the corresponding properties of the translations object.
async switchLanguage(lang: string) {
this.translations.translate = await this.translateService.getData(this.translations.translate, lang);
this.translations.menuPlaces = await this.translateService.getData(this.translations.menuPlaces, lang);
this.translations.alertMessage = await this.translateService.getData(this.translations.alertMessage, lang);
this.translations.searchPlaceholder = await this.translateService.getData(this.translations.searchPlaceholder, lang);
this.translations.searchButton = await this.translateService.getData(this.translations.searchButton, lang);
}
}