Added Translations

This commit is contained in:
grata
2023-04-18 09:43:00 +02:00
parent e5b9e20f32
commit 3ebba88398
9 changed files with 156 additions and 102 deletions

View File

@@ -0,0 +1,27 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {translations} from "../interface/translations";
@Injectable({
providedIn: 'root'
})
export class ReadTranslateJsonService {
private translationData: translations = {} as translations;
constructor(private http: HttpClient) {
this.http.get<translations>('assets/i18n/en.json').subscribe(data => {
this.translationData.alertMessage = data.alertMessage;
this.translationData.translate = data.translate;
this.translationData.searchButton = data.searchButton;
this.translationData.searchPlaceholder = data.searchPlaceholder;
this.translationData.menuPlaces = data.menuPlaces;
this.translationData.menuNear = data.menuNear;
console.log("data loaded", this.translationData)
});
}
getData(): translations {
console.log("data loaded", this.translationData)
return this.translationData;
}
}

View File

@@ -53,8 +53,4 @@ export class ReadjsonService{
tap(data => console.log("data requested", data))
);
}
}

View File

@@ -1,21 +1,16 @@
import { Injectable } from '@angular/core';
//import { Translate } from '@google-cloud/translate/build/src/v2';
import {DeepLService} from "./deepL.service";
import {Injectable} from "@angular/core";
@Injectable({
providedIn: 'root'
})
export class TranslateService {
constructor(private deepLService: DeepLService) {
//private translate: Translate;
// constructor() {
// this.translate = new Translate({projectId: 'Modulo-152'});
//}
//async translateText(text: string, target: string): Promise<string> {
//const [translation] = await this.translate.translate(text, target);
//return translation;
//}
}
async getData(input: string, lang: string): Promise<string> {
const response = await this.deepLService.translate(input, lang).toPromise();
return response.translations[0].text;
}
}