import {Component, OnInit} from '@angular/core'; import {CookieService} from "ngx-cookie-service"; import {Router} from "@angular/router"; import {homeTranslations, listTranslations, managementTranslations} from "./interface/translations"; import {TranslateService} from "./service/language/translate.service"; import {ReadTranslateJsonService} from "./service/language/readTranslateJson.service"; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit{ title = 'm-152'; homeTranslations: homeTranslations = {} as homeTranslations; listTranslations: listTranslations = {} as listTranslations; managementTranslation: managementTranslations = {} as managementTranslations; constructor( private cookieService: CookieService, private router: Router, private translateService: TranslateService, private readTranslationJsonService: ReadTranslateJsonService, ) { } ngOnInit() { this.homeTranslations = this.readTranslationJsonService.getHomeTranslations(); this.listTranslations = this.readTranslationJsonService.getListTransaltions(); this.managementTranslation = this.readTranslationJsonService.getManagementTranslations(); } clearAllCookies() { const allCookies = this.cookieService.getAll(); for (const cookieName in allCookies) { this.cookieService.delete(cookieName); } this.router.navigate(['/login']); } // 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) { // Load Home Page Translations this.homeTranslations.translate = await this.translateService.getData(this.homeTranslations.translate, lang); this.homeTranslations.menuPlaces = await this.translateService.getData(this.homeTranslations.menuPlaces, lang); this.homeTranslations.alertMessage = await this.translateService.getData(this.homeTranslations.alertMessage, lang); this.homeTranslations.searchPlaceholder = await this.translateService.getData(this.homeTranslations.searchPlaceholder, lang); this.homeTranslations.searchButton = await this.translateService.getData(this.homeTranslations.searchButton, lang); // Load List Page Translations this.listTranslations.distance = await this.translateService.getData(this.listTranslations.distance, lang); this.listTranslations.locationName = await this.translateService.getData(this.listTranslations.locationName, lang); this.listTranslations.positionNotFoundErrorMessage = await this.translateService.getData(this.listTranslations.positionNotFoundErrorMessage, lang); // Load Management Page Translations this.managementTranslation.users = await this.translateService.getData(this.managementTranslation.users, lang); this.managementTranslation.locations = await this.translateService.getData(this.managementTranslation.locations, lang); this.managementTranslation.waypoints = await this.translateService.getData(this.managementTranslation.waypoints, lang); this.managementTranslation.name = await this.translateService.getData(this.managementTranslation.name, lang); this.managementTranslation.username = await this.translateService.getData(this.managementTranslation.username, lang); this.managementTranslation.password = await this.translateService.getData(this.managementTranslation.password, lang); this.managementTranslation.location = await this.translateService.getData(this.managementTranslation.location, lang); this.managementTranslation.region = await this.translateService.getData(this.managementTranslation.region, lang); this.managementTranslation.lat = await this.translateService.getData(this.managementTranslation.lat, lang); this.managementTranslation.lon = await this.translateService.getData(this.managementTranslation.lon, lang); this.managementTranslation.description = await this.translateService.getData(this.managementTranslation.description, lang); this.managementTranslation.locationName = await this.translateService.getData(this.managementTranslation.locationName, lang); this.managementTranslation.image = await this.translateService.getData(this.managementTranslation.image, lang); this.managementTranslation.translate = await this.translateService.getData(this.managementTranslation.translate, lang); this.managementTranslation.addLocationButton = await this.translateService.getData(this.managementTranslation.addLocationButton, lang); this.managementTranslation.addUserButton = await this.translateService.getData(this.managementTranslation.addUserButton, lang); this.managementTranslation.addWaypointButton = await this.translateService.getData(this.managementTranslation.addWaypointButton, lang); this.managementTranslation.add = await this.translateService.getData(this.managementTranslation.add, lang); this.managementTranslation.close = await this.translateService.getData(this.managementTranslation.close, lang); } }