diff --git a/src/app/app.component.html b/src/app/app.component.html index 56ef914..e8b8145 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,2 +1,12 @@ + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 52418a7..c8af843 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,22 +1,37 @@ -import { Component } from '@angular/core'; +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 { +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) { @@ -24,4 +39,44 @@ export class AppComponent { } 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); + } } diff --git a/src/app/component/list/list.component.html b/src/app/component/list/list.component.html index 52ab192..a5c4d55 100644 --- a/src/app/component/list/list.component.html +++ b/src/app/component/list/list.component.html @@ -1,13 +1,3 @@ -

{{translations.locationName}}{{locationParams}} diff --git a/src/app/component/list/list.component.ts b/src/app/component/list/list.component.ts index c86922a..0fb6303 100644 --- a/src/app/component/list/list.component.ts +++ b/src/app/component/list/list.component.ts @@ -35,8 +35,6 @@ export class ListComponent implements OnInit, OnChanges { constructor( private route: ActivatedRoute, private positionService: positionService, - private translateService: TranslateService, - private readTranslationJsonService: ReadTranslateJsonService, private locationService: LocationService, private waypointService: WaypointService, private cookieService: cookieService, @@ -44,7 +42,6 @@ export class ListComponent implements OnInit, OnChanges { } async ngOnInit() { - this.translations = this.readTranslationJsonService.getListTransaltions(); this.username = this.cookieService.getUsername(); this.route.params.subscribe(params => { this.locationParams = params['location']; @@ -96,13 +93,6 @@ export class ListComponent implements OnInit, OnChanges { }, 2000); } - async switchLanguage(lang: string) { - this.translations.translate = await this.translateService.getData(this.translations.translate, lang); - this.translations.distance = await this.translateService.getData(this.translations.distance, lang); - this.translations.locationName = await this.translateService.getData(this.translations.locationName, lang); - this.translations.positionNotFoundErrorMessage = await this.translateService.getData(this.translations.positionNotFoundErrorMessage, lang); - } - private checkDataPopulated(): void { if (this.locations && this.location) { console.log("Dati popolati correttamente:", this.locations, this.location); diff --git a/src/app/component/management/management.component.html b/src/app/component/management/management.component.html index 55c1955..28a060a 100644 --- a/src/app/component/management/management.component.html +++ b/src/app/component/management/management.component.html @@ -1,14 +1,3 @@ - -

{{translations.users}}

diff --git a/src/app/component/management/management.component.ts b/src/app/component/management/management.component.ts index 5956763..58f6656 100644 --- a/src/app/component/management/management.component.ts +++ b/src/app/component/management/management.component.ts @@ -115,28 +115,4 @@ export class ManagementComponent implements OnInit { closeWaypointForm() { this.showWaypointForm = false; } - - async switchLanguage(lang: string) { - - // Man - this.translations.users = await this.translateService.getData(this.translations.users, lang); - this.translations.locations = await this.translateService.getData(this.translations.locations, lang); - this.translations.waypoints = await this.translateService.getData(this.translations.waypoints, lang); - this.translations.name = await this.translateService.getData(this.translations.name, lang); - this.translations.username = await this.translateService.getData(this.translations.username, lang); - this.translations.password = await this.translateService.getData(this.translations.password, lang); - this.translations.location = await this.translateService.getData(this.translations.location, lang); - this.translations.region = await this.translateService.getData(this.translations.region, lang); - this.translations.lat = await this.translateService.getData(this.translations.lat, lang); - this.translations.lon = await this.translateService.getData(this.translations.lon, lang); - this.translations.description = await this.translateService.getData(this.translations.description, lang); - this.translations.locationName = await this.translateService.getData(this.translations.locationName, lang); - this.translations.image = await this.translateService.getData(this.translations.image, lang); - this.translations.translate = await this.translateService.getData(this.translations.translate, lang); - this.translations.addLocationButton = await this.translateService.getData(this.translations.addLocationButton, lang); - this.translations.addUserButton = await this.translateService.getData(this.translations.addUserButton, lang); - this.translations.addWaypointButton = await this.translateService.getData(this.translations.addWaypointButton, lang); - this.translations.add = await this.translateService.getData(this.translations.add, lang); - this.translations.close = await this.translateService.getData(this.translations.close, lang); - } } diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 4a02806..55f182e 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -11,16 +11,6 @@ - -