From 196d374b305c3dc78ca653ff42be48c9b59dba4e Mon Sep 17 00:00:00 2001 From: Hallie Scasta Date: Wed, 16 Nov 2022 15:00:54 -0600 Subject: [PATCH 1/3] created translate function in ts --- liquid-prep-app/angular.json | 3 +- liquid-prep-app/package.json | 1 + liquid-prep-app/src/app/app.module.ts | 1 + .../measure-soil/measure-soil.component.ts | 15 ++++ .../my-crops/my-crops.component.html | 2 +- .../components/my-crops/my-crops.component.ts | 14 ++++ .../seed-date/seed-date.component.ts | 15 ++++ .../select-crop/select-crop.component.html | 3 + .../select-crop/select-crop.component.ts | 15 ++++ .../components/settings/settings.component.ts | 16 +++++ .../slide-indicator.component.ts | 16 +++++ .../components/welcome/welcome.component.html | 3 + .../components/welcome/welcome.component.ts | 70 ++++++++++++++++++- liquid-prep-app/src/app/models/Translation.ts | 3 + .../app/service/LanguageTranslatorService.ts | 40 +++++++++++ liquid-prep-app/src/config-sample.json | 3 - liquid-prep-app/src/proxy.conf.json | 7 ++ 17 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 liquid-prep-app/src/app/models/Translation.ts create mode 100644 liquid-prep-app/src/app/service/LanguageTranslatorService.ts delete mode 100644 liquid-prep-app/src/config-sample.json create mode 100644 liquid-prep-app/src/proxy.conf.json diff --git a/liquid-prep-app/angular.json b/liquid-prep-app/angular.json index 35e8b70..54c7d4e 100644 --- a/liquid-prep-app/angular.json +++ b/liquid-prep-app/angular.json @@ -75,7 +75,8 @@ "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { - "browserTarget": "liquid-prep-app:build" + "browserTarget": "liquid-prep-app:build", + "proxyConfig": "src/proxy.conf.json" }, "configurations": { "production": { diff --git a/liquid-prep-app/package.json b/liquid-prep-app/package.json index 3f24534..8c7703d 100644 --- a/liquid-prep-app/package.json +++ b/liquid-prep-app/package.json @@ -29,6 +29,7 @@ "@angular/platform-browser-dynamic": "^13.2.0", "@angular/router": "^13.2.0", "@angular/service-worker": "^13.2.0", + "cors": "^2.8.5", "ng2-search-filter": "^0.5.1", "ngx-swiper-wrapper": "^10.0.0", "ngx-webstorage-service": "^4.1.0", diff --git a/liquid-prep-app/src/app/app.module.ts b/liquid-prep-app/src/app/app.module.ts index 19977ba..c1b8683 100644 --- a/liquid-prep-app/src/app/app.module.ts +++ b/liquid-prep-app/src/app/app.module.ts @@ -62,6 +62,7 @@ const DEFAULT_SWIPER_CONFIG: SwiperConfigInterface = { BrowserModule, MaterialModule, AppRoutingModule, + HttpClientModule, ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, }), diff --git a/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts b/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts index 6779ca3..467360f 100644 --- a/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts +++ b/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts @@ -320,6 +320,21 @@ export class MeasureSoilComponent implements OnInit, AfterViewInit { this.measureView = status; } + public translate() { + // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" {}); } diff --git a/liquid-prep-app/src/app/components/my-crops/my-crops.component.html b/liquid-prep-app/src/app/components/my-crops/my-crops.component.html index e9cb8e8..3391207 100644 --- a/liquid-prep-app/src/app/components/my-crops/my-crops.component.html +++ b/liquid-prep-app/src/app/components/my-crops/my-crops.component.html @@ -3,7 +3,7 @@
Today, {{ currentDate }}
hourglass_empty -
+
error
diff --git a/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts b/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts index 209cb94..aeb8dab 100644 --- a/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts +++ b/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts @@ -82,6 +82,20 @@ export class MyCropsComponent implements OnInit { this.location.back(); } + public translate() { + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" + +
diff --git a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts index 9d10ac5..d3afc7b 100644 --- a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts +++ b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts @@ -47,6 +47,21 @@ export class SelectCropComponent implements OnInit{ ); } + public translate() { + // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + + if (!allElements[i].innerHTML.includes(" SKIP +
diff --git a/liquid-prep-app/src/app/components/welcome/welcome.component.ts b/liquid-prep-app/src/app/components/welcome/welcome.component.ts index c663941..982234d 100644 --- a/liquid-prep-app/src/app/components/welcome/welcome.component.ts +++ b/liquid-prep-app/src/app/components/welcome/welcome.component.ts @@ -3,7 +3,9 @@ import { SwiperOptions } from 'swiper'; import { Router, ActivatedRoute} from '@angular/router'; import {LOCAL_STORAGE, StorageService} from 'ngx-webstorage-service'; import {SwiperComponent} from "ngx-swiper-wrapper"; - +// import {Translation} from 'src/app/models/Translation'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; @Component({ selector: 'app-welcome', @@ -17,7 +19,7 @@ export class WelcomeComponent implements OnInit { private IS_FIRST_START = `first-start`; constructor( - private router: Router, + private router: Router, private languageService: LanguageTranslatorService, private route: ActivatedRoute, @Inject( LOCAL_STORAGE ) private storage: StorageService) { } @@ -45,8 +47,15 @@ export class WelcomeComponent implements OnInit { public disabled = false; + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + result: Object; + private firstStart = true; + ngOnInit(): void { this.firstStart = this.storage.get(this.IS_FIRST_START); if (this.firstStart !== undefined && this.firstStart === false){ @@ -76,6 +85,63 @@ export class WelcomeComponent implements OnInit { public onSwiperEvent(event: string): void { } + + public update_text(translations) { + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + for (var i = 0; i < allElements.length; i++) { + console.log("current trans: " + this.translations[i]); + allElements[i].innerHTML = this.translations[i]; + console.log("updated text: " + allElements[i].innerHTML); + } + } + public async translate() { + // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + if (!allElements[i].innerHTML.includes(" { + + // for (i = 0; i < response.translations.length; i++) { + // this.translations.push(response.translations[i].translation); + // } + for (i = 0; i < this.text_pos.length; i++) { + //console.log(allElements[this.text_pos[i]].innerHTML); + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + // console.log("trans list: "); + // console.log(this.translations); + // setTimeout(() => { console.log("waiting ..."); }, 5000); + // this.update_text(this.translations); + + } + + // updateTranslation() { + // this.languageService.getTranslation(this.translations, this.selectedLanguage).subscribe((response: any) => { + // this.today = (response.translations[0].translation); + // this.addYourCrop = (response.translations[1].translation); + // this.selectOption = (response.translations[2].translation); + // this.add = (response.translations[3].translation); + // }); + // // don't know how to make date into string + // this.languageService.getTranslation("November 16, 2022", this.selectedLanguage).subscribe((response: any) => { + // this.translation = (response.translations[0].translation); + // this.currentDate = (this.translation); + // }); + // } + + + onSlideNav(direction: string){ if (direction === 'next'){ diff --git a/liquid-prep-app/src/app/models/Translation.ts b/liquid-prep-app/src/app/models/Translation.ts new file mode 100644 index 0000000..b4a8924 --- /dev/null +++ b/liquid-prep-app/src/app/models/Translation.ts @@ -0,0 +1,3 @@ +export class Translation { + public translation: string; +} \ No newline at end of file diff --git a/liquid-prep-app/src/app/service/LanguageTranslatorService.ts b/liquid-prep-app/src/app/service/LanguageTranslatorService.ts new file mode 100644 index 0000000..f307449 --- /dev/null +++ b/liquid-prep-app/src/app/service/LanguageTranslatorService.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' // just before your class +}) + +export class LanguageTranslatorService { + constructor(private http: HttpClient) { } + apiUrl = "https://api.us-south.language-translator.watson.cloud.ibm.com/instances/b0491abd-7640-4d72-98e6-a68035a39968/v3/translate?version=2018-05-01" + getTranslation(text, language) { + let translation + console.log('sending request!!') + const httpOptions = { headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'Authorization': 'Basic ' + btoa("apikey:ZghpOfAbpgdLuoAgV7-kOEYlG6CJSTem-wSHo9NrWues"), + // 'observe': 'response' + }), + // observe: 'response' + }; + const requestOptions: Object = { + //If your response is text not json + responseType: 'text' + } + let headers = new HttpHeaders(); + headers = headers.append("Authorization", "Basic " + btoa("apikey:ZghpOfAbpgdLuoAgV7-kOEYlG6CJSTem-wSHo9NrWues")); + headers = headers.append("Content-Type", "application/json"); + // headers = headers.append("observe", "response"); + let model = "en-en" // default is english? + if (language == "french") { + model = "en-fr"; + } + if (language == "spanish") { + model = "en-es"; + } + let body = {"text": text, "model_id":"en-es"} + + return this.http.post(this.apiUrl, body, httpOptions); + } +} \ No newline at end of file diff --git a/liquid-prep-app/src/config-sample.json b/liquid-prep-app/src/config-sample.json deleted file mode 100644 index cb5810e..0000000 --- a/liquid-prep-app/src/config-sample.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "backendAPIEndpoint": "add the backend URL endpoint here" -} \ No newline at end of file diff --git a/liquid-prep-app/src/proxy.conf.json b/liquid-prep-app/src/proxy.conf.json new file mode 100644 index 0000000..dbec7ca --- /dev/null +++ b/liquid-prep-app/src/proxy.conf.json @@ -0,0 +1,7 @@ +{ +"/api*": { + "target":"http://localhost:4200", + "secure":false, + "logLevel":"debug" + } +} \ No newline at end of file From 851d0ec72d169c51e2b8c16bafe6ecff8b2c17a5 Mon Sep 17 00:00:00 2001 From: Hallie Scasta Date: Wed, 16 Nov 2022 15:39:18 -0600 Subject: [PATCH 2/3] added translate function to all ts component files --- .../app/components/advice/advice.component.ts | 34 ++++++++++++- .../measure-soil/measure-soil.component.ts | 48 ++++++++++++------- .../components/my-crops/my-crops.component.ts | 48 +++++++++++++------ .../seed-date/seed-date.component.ts | 45 +++++++++++------ .../select-crop/select-crop.component.ts | 26 ++++++++-- .../components/settings/settings.component.ts | 45 +++++++++++------ .../slide-indicator.component.ts | 43 ++++++++++++----- .../components/welcome/welcome.component.ts | 16 ++----- 8 files changed, 215 insertions(+), 90 deletions(-) diff --git a/liquid-prep-app/src/app/components/advice/advice.component.ts b/liquid-prep-app/src/app/components/advice/advice.component.ts index 280e6e9..5a7c9d7 100644 --- a/liquid-prep-app/src/app/components/advice/advice.component.ts +++ b/liquid-prep-app/src/app/components/advice/advice.component.ts @@ -6,6 +6,9 @@ import { WaterAdviceService } from 'src/app/service/WaterAdviceService'; import {Crop} from '../../models/Crop'; import {CropDataService} from '../../service/CropDataService'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; + @Component({ selector: 'app-advice', templateUrl: './advice.component.html', @@ -35,9 +38,14 @@ export class AdviceComponent implements OnInit { ['HIGH', 'color-high'] ]); + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + constructor( private route: ActivatedRoute, - private router: Router, + private router: Router, private languageService: LanguageTranslatorService, private waterAdviceService: WaterAdviceService, private cropService: CropDataService ) {} @@ -62,6 +70,30 @@ export class AdviceComponent implements OnInit { }); } + public translate() { + + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + + } + public volumeClicked() { } diff --git a/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts b/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts index 467360f..b59d720 100644 --- a/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts +++ b/liquid-prep-app/src/app/components/measure-soil/measure-soil.component.ts @@ -8,6 +8,8 @@ import { SoilMoisture } from '../../models/SoilMoisture'; import { LineBreakTransformer } from './LineBreakTransformer'; import { Crop, Stage } from '../../models/Crop'; import { CropDataService } from '../../service/CropDataService'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; @Component({ selector: 'app-measure-soil', @@ -17,7 +19,7 @@ import { CropDataService } from '../../service/CropDataService'; export class MeasureSoilComponent implements OnInit, AfterViewInit { constructor( private route: ActivatedRoute, - private router: Router, + private router: Router, private languageService: LanguageTranslatorService, private location: Location, private soilService: SoilMoistureService, private cropService: CropDataService @@ -68,6 +70,11 @@ export class MeasureSoilComponent implements OnInit, AfterViewInit { ['HIGH', '/assets/moisture-water/soil_moisture_high.png'], ]); + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + ngOnInit(): void { const cropId = this.route.snapshot.paramMap.get('id'); this.crop = this.cropService.getCropFromMyCropById(cropId); @@ -76,6 +83,30 @@ export class MeasureSoilComponent implements OnInit, AfterViewInit { ngAfterViewInit(): void {} + public translate() { + + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + + } + public onSensorConnect(connectionOption) { if (connectionOption === 'usb') { this.connectUSB().then((sensorValue) => { @@ -320,21 +351,6 @@ export class MeasureSoilComponent implements OnInit, AfterViewInit { this.measureView = status; } - public translate() { - // let allInBody = document.querySelectorAll('body > *') as NodeListOf; - var allInBody = document.getElementsByTagName('body')[0]; - var allElements = allInBody.getElementsByTagName('*'); - - for (var i = 0; i < allElements.length; i++) { - - if (!allElements[i].innerHTML.includes(" {}); } diff --git a/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts b/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts index aeb8dab..299b4df 100644 --- a/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts +++ b/liquid-prep-app/src/app/components/my-crops/my-crops.component.ts @@ -9,6 +9,9 @@ import { TodayWeather } from 'src/app/models/TodayWeather'; import { CropDataService } from 'src/app/service/CropDataService'; import { DateTimeUtil } from 'src/app/utility/DateTimeUtil'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; + @Component({ selector: 'app-my-crops', templateUrl: './my-crops.component.html', @@ -32,8 +35,13 @@ export class MyCropsComponent implements OnInit { public myCropStatus: 'no-crop' | 'crop-selected' = 'no-crop'; public errorMessage = ''; + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + constructor( - private router: Router, private location: Location, + private router: Router, private location: Location, private languageService: LanguageTranslatorService, private weatherService: WeatherDataService, private cropDataService: CropDataService ) { this.updateWeatherInfo(); @@ -57,6 +65,30 @@ export class MyCropsComponent implements OnInit { } + public translate() { + + var allInBody = document.getElementsByTagName('body')[0]; + var allElements = allInBody.getElementsByTagName('*'); + + for (var i = 0; i < allElements.length; i++) { + if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + + } + public tabClicked(tab) { this.activeTab = tab; if (tab === tab[0]) { @@ -82,20 +114,6 @@ export class MyCropsComponent implements OnInit { this.location.back(); } - public translate() { - var allInBody = document.getElementsByTagName('body')[0]; - var allElements = allInBody.getElementsByTagName('*'); - - for (var i = 0; i < allElements.length; i++) { - - if (!allElements[i].innerHTML.includes(" *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); for (var i = 0; i < allElements.length; i++) { - if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + + } + + public volumeClicked() { + + } + + public backClicked() { + this.location.back(); } clickConfirm(userSelectedDate: Date) { diff --git a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts index d3afc7b..5d84db4 100644 --- a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts +++ b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts @@ -5,6 +5,8 @@ import {Location} from '@angular/common'; import { CropListResponse } from '../../models/api/CropListResponse'; import { Crop } from '../../models/Crop'; import { CropDataService } from '../../service/CropDataService'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; @Component({ selector: 'app-select-crop', @@ -25,7 +27,12 @@ export class SelectCropComponent implements OnInit{ NO_NEW_CROPS = ''; public requestingCrop = true; - constructor(private router: Router, private location: Location, + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + + constructor(private router: Router, private location: Location, private languageService: LanguageTranslatorService, private cropService: CropDataService) { } ngOnInit(): void { @@ -48,18 +55,27 @@ export class SelectCropComponent implements OnInit{ } public translate() { - // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); for (var i = 0; i < allElements.length; i++) { - if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + } backToMyCrops(){ diff --git a/liquid-prep-app/src/app/components/settings/settings.component.ts b/liquid-prep-app/src/app/components/settings/settings.component.ts index d9d05fd..d5e2212 100644 --- a/liquid-prep-app/src/app/components/settings/settings.component.ts +++ b/liquid-prep-app/src/app/components/settings/settings.component.ts @@ -2,6 +2,9 @@ import { Component, OnInit, Input } from '@angular/core'; import { Location } from '@angular/common'; import { Router } from '@angular/router'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; + @Component({ selector: 'app-settings', templateUrl: './settings.component.html', @@ -9,32 +12,46 @@ import { Router } from '@angular/router'; }) export class SettingsComponent implements OnInit { - constructor(private router: Router, private location: Location) { } - - ngOnInit(): void { - } + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; - public volumeClicked() { - this.router.navigateByUrl('/my-crops'); - } + constructor(private router: Router, private location: Location, private languageService: LanguageTranslatorService) { } - public backClicked() { - this.location.back(); + ngOnInit(): void { } public translate() { - // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); for (var i = 0; i < allElements.length; i++) { - if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; + + } + }); + } - + + public volumeClicked() { + this.router.navigateByUrl('/my-crops'); + } + + public backClicked() { + this.location.back(); + } + } diff --git a/liquid-prep-app/src/app/components/slide-indicator/slide-indicator.component.ts b/liquid-prep-app/src/app/components/slide-indicator/slide-indicator.component.ts index 8dda490..2b7698d 100644 --- a/liquid-prep-app/src/app/components/slide-indicator/slide-indicator.component.ts +++ b/liquid-prep-app/src/app/components/slide-indicator/slide-indicator.component.ts @@ -1,5 +1,8 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; +import {LanguageTranslatorService} from '../../service/LanguageTranslatorService'; +import { Subscribable } from 'rxjs'; + class Indicator { constructor(public ref: number) {} } @@ -15,7 +18,12 @@ export class SlideIndicatorComponent implements OnInit, OnChanges{ @Input() public length: number; public indicators: Indicator[] = []; - constructor() { + public selectedLanguage = 'spanish'; + public text_pos: number[] = []; + public text_to_trans: string[] = []; + public translations: string[] = []; + + constructor(private languageService: LanguageTranslatorService) { } ngOnInit(): void { @@ -33,27 +41,36 @@ export class SlideIndicatorComponent implements OnInit, OnChanges{ } } - public getIndicatorClass(ref: number): string { - if (ref === this.current){ - return 'active'; - }else { - return 'inactive'; - } - } - public translate() { - // let allInBody = document.querySelectorAll('body > *') as NodeListOf; + var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); for (var i = 0; i < allElements.length; i++) { - if (!allElements[i].innerHTML.includes(" { + + for (i = 0; i < this.text_pos.length; i++) { + + setTimeout(() => { console.log("waiting ..."); }, 1000); + allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; - allElements[i].innerHTML = "howdy!"; } + }); + + } + + public getIndicatorClass(ref: number): string { + if (ref === this.current){ + return 'active'; + }else { + return 'inactive'; } } - + } diff --git a/liquid-prep-app/src/app/components/welcome/welcome.component.ts b/liquid-prep-app/src/app/components/welcome/welcome.component.ts index 982234d..f5a7f0e 100644 --- a/liquid-prep-app/src/app/components/welcome/welcome.component.ts +++ b/liquid-prep-app/src/app/components/welcome/welcome.component.ts @@ -51,7 +51,6 @@ export class WelcomeComponent implements OnInit { public text_pos: number[] = []; public text_to_trans: string[] = []; public translations: string[] = []; - result: Object; private firstStart = true; @@ -95,7 +94,7 @@ export class WelcomeComponent implements OnInit { console.log("updated text: " + allElements[i].innerHTML); } } - public async translate() { + public translate() { // let allInBody = document.querySelectorAll('body > *') as NodeListOf; var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); @@ -104,25 +103,18 @@ export class WelcomeComponent implements OnInit { if (!allElements[i].innerHTML.includes(" { + this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => { - // for (i = 0; i < response.translations.length; i++) { - // this.translations.push(response.translations[i].translation); - // } for (i = 0; i < this.text_pos.length; i++) { //console.log(allElements[this.text_pos[i]].innerHTML); - setTimeout(() => { console.log("waiting ..."); }, 1000); + // setTimeout(() => { console.log("waiting ..."); }, 2000); allElements[this.text_pos[i]].innerHTML = response.translations[i].translation; } }); - // console.log("trans list: "); - // console.log(this.translations); - // setTimeout(() => { console.log("waiting ..."); }, 5000); - // this.update_text(this.translations); } From f7123f497c81e810c4076083a6e2d5d3b55f8bd6 Mon Sep 17 00:00:00 2001 From: alisalin5 <68750636+alisalin5@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:01:03 -0600 Subject: [PATCH 3/3] added button for translate --- .../app/components/my-crops/my-crops.component.html | 11 ++++++++++- .../app/components/my-crops/my-crops.component.ts | 7 +++---- .../components/seed-date/seed-date.component.html | 11 ++++++++++- .../app/components/seed-date/seed-date.component.ts | 4 ++-- .../select-crop/select-crop.component.html | 9 ++++++--- .../components/select-crop/select-crop.component.ts | 4 ++-- .../app/components/welcome/welcome.component.html | 13 ++++++++++--- .../src/app/components/welcome/welcome.component.ts | 4 ++-- .../src/app/service/LanguageTranslatorService.ts | 9 +-------- 9 files changed, 46 insertions(+), 26 deletions(-) diff --git a/liquid-prep-app/src/app/components/my-crops/my-crops.component.html b/liquid-prep-app/src/app/components/my-crops/my-crops.component.html index 3391207..b687346 100644 --- a/liquid-prep-app/src/app/components/my-crops/my-crops.component.html +++ b/liquid-prep-app/src/app/components/my-crops/my-crops.component.html @@ -26,7 +26,16 @@
- +
+ + + + + + + + +
- +
+ + + + + + + + +
select seed date diff --git a/liquid-prep-app/src/app/components/seed-date/seed-date.component.ts b/liquid-prep-app/src/app/components/seed-date/seed-date.component.ts index 7a9cd6f..689f194 100644 --- a/liquid-prep-app/src/app/components/seed-date/seed-date.component.ts +++ b/liquid-prep-app/src/app/components/seed-date/seed-date.component.ts @@ -48,7 +48,7 @@ export class SeedDateComponent implements OnInit { ); } - public translate() { + public translate(modelID) { var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); @@ -60,7 +60,7 @@ export class SeedDateComponent implements OnInit { this.text_to_trans.push(allElements[i].innerHTML); } } - this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => { + this.languageService.getTranslation(this.text_to_trans, modelID).subscribe((response: any) => { for (i = 0; i < this.text_pos.length; i++) { diff --git a/liquid-prep-app/src/app/components/select-crop/select-crop.component.html b/liquid-prep-app/src/app/components/select-crop/select-crop.component.html index 9a12089..3305e59 100644 --- a/liquid-prep-app/src/app/components/select-crop/select-crop.component.html +++ b/liquid-prep-app/src/app/components/select-crop/select-crop.component.html @@ -23,6 +23,7 @@ + - + +
@@ -56,3 +57,5 @@
+ + diff --git a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts index 5d84db4..eb3da74 100644 --- a/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts +++ b/liquid-prep-app/src/app/components/select-crop/select-crop.component.ts @@ -54,7 +54,7 @@ export class SelectCropComponent implements OnInit{ ); } - public translate() { + public translate(modelID) { var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); @@ -66,7 +66,7 @@ export class SelectCropComponent implements OnInit{ this.text_to_trans.push(allElements[i].innerHTML); } } - this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => { + this.languageService.getTranslation(this.text_to_trans, modelID).subscribe((response: any) => { for (i = 0; i < this.text_pos.length; i++) { diff --git a/liquid-prep-app/src/app/components/welcome/welcome.component.html b/liquid-prep-app/src/app/components/welcome/welcome.component.html index 9a41e74..5e406a4 100644 --- a/liquid-prep-app/src/app/components/welcome/welcome.component.html +++ b/liquid-prep-app/src/app/components/welcome/welcome.component.html @@ -3,9 +3,16 @@ - +
+ + + + + + + + +
diff --git a/liquid-prep-app/src/app/components/welcome/welcome.component.ts b/liquid-prep-app/src/app/components/welcome/welcome.component.ts index f5a7f0e..81c1075 100644 --- a/liquid-prep-app/src/app/components/welcome/welcome.component.ts +++ b/liquid-prep-app/src/app/components/welcome/welcome.component.ts @@ -94,7 +94,7 @@ export class WelcomeComponent implements OnInit { console.log("updated text: " + allElements[i].innerHTML); } } - public translate() { + public translate(modelID) { // let allInBody = document.querySelectorAll('body > *') as NodeListOf; var allInBody = document.getElementsByTagName('body')[0]; var allElements = allInBody.getElementsByTagName('*'); @@ -106,7 +106,7 @@ export class WelcomeComponent implements OnInit { this.text_to_trans.push(allElements[i].innerHTML.toLowerCase()); } } - this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => { + this.languageService.getTranslation(this.text_to_trans, modelID).subscribe((response: any) => { for (i = 0; i < this.text_pos.length; i++) { //console.log(allElements[this.text_pos[i]].innerHTML); diff --git a/liquid-prep-app/src/app/service/LanguageTranslatorService.ts b/liquid-prep-app/src/app/service/LanguageTranslatorService.ts index f307449..2511512 100644 --- a/liquid-prep-app/src/app/service/LanguageTranslatorService.ts +++ b/liquid-prep-app/src/app/service/LanguageTranslatorService.ts @@ -26,14 +26,7 @@ export class LanguageTranslatorService { headers = headers.append("Authorization", "Basic " + btoa("apikey:ZghpOfAbpgdLuoAgV7-kOEYlG6CJSTem-wSHo9NrWues")); headers = headers.append("Content-Type", "application/json"); // headers = headers.append("observe", "response"); - let model = "en-en" // default is english? - if (language == "french") { - model = "en-fr"; - } - if (language == "spanish") { - model = "en-es"; - } - let body = {"text": text, "model_id":"en-es"} + let body = {"text": text, "model_id":language} return this.http.post(this.apiUrl, body, httpOptions); }