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/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("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => {
+
+ 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 6779ca3..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("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => {
+
+ 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) => {
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..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
@@ -3,7 +3,7 @@
Today, {{ currentDate }}
hourglass_empty
-
@@ -26,7 +26,16 @@
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
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 b5d7e61..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
@@ -6,6 +6,9 @@ import { Crop, Stage } from '../../models/Crop';
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-seed-date',
templateUrl: './seed-date.component.html',
@@ -18,7 +21,7 @@ export class SeedDateComponent implements OnInit {
maxDate = new Date();
constructor(
- private router: Router,
+ private router: Router, private languageService: LanguageTranslatorService,
private location: Location,
private route: ActivatedRoute,
private cropService: CropDataService
@@ -26,6 +29,11 @@ export class SeedDateComponent implements OnInit {
this.userSelectiondate = new Date();
}
+ 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.cropService.getCropData(cropId)
@@ -39,6 +47,30 @@ export class SeedDateComponent implements OnInit {
}
);
}
+
+ public translate(modelID) {
+
+ var allInBody = document.getElementsByTagName('body')[0];
+ var allElements = allInBody.getElementsByTagName('*');
+
+ for (var i = 0; i < allElements.length; i++) {
+ if (!allElements[i].innerHTML.includes("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, modelID).subscribe((response: any) => {
+
+ 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/select-crop/select-crop.component.html b/liquid-prep-app/src/app/components/select-crop/select-crop.component.html
index 1888366..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 @@
+
+
+
@@ -53,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 9d10ac5..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
@@ -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 {
@@ -47,6 +54,30 @@ export class SelectCropComponent implements OnInit{
);
}
+ public translate(modelID) {
+
+ var allInBody = document.getElementsByTagName('body')[0];
+ var allElements = allInBody.getElementsByTagName('*');
+
+ for (var i = 0; i < allElements.length; i++) {
+ if (!allElements[i].innerHTML.includes("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, modelID).subscribe((response: any) => {
+
+ 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(){
this.location.back();
}
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 4974cb9..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,11 +12,40 @@ import { Router } from '@angular/router';
})
export class SettingsComponent implements OnInit {
- 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) { }
ngOnInit(): 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("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => {
+
+ 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');
}
@@ -21,4 +53,5 @@ export class SettingsComponent implements OnInit {
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 9f54fae..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,6 +41,30 @@ export class SlideIndicatorComponent implements OnInit, OnChanges{
}
}
+ 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("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML);
+ }
+ }
+ this.languageService.getTranslation(this.text_to_trans, this.selectedLanguage).subscribe((response: any) => {
+
+ 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 getIndicatorClass(ref: number): string {
if (ref === this.current){
return 'active';
@@ -40,4 +72,5 @@ export class SlideIndicatorComponent implements OnInit, OnChanges{
return 'inactive';
}
}
+
}
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 92687a5..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,6 +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 c663941..81c1075 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,14 @@ export class WelcomeComponent implements OnInit {
public disabled = false;
+ public selectedLanguage = 'spanish';
+ public text_pos: number[] = [];
+ public text_to_trans: string[] = [];
+ public translations: string[] = [];
+
private firstStart = true;
+
ngOnInit(): void {
this.firstStart = this.storage.get(this.IS_FIRST_START);
if (this.firstStart !== undefined && this.firstStart === false){
@@ -76,6 +84,56 @@ 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 translate(modelID) {
+ // 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("") && allElements[i].innerHTML.length != 0) {
+ this.text_pos.push(i);
+ console.log(i + ": " + allElements[i].innerHTML);
+ this.text_to_trans.push(allElements[i].innerHTML.toLowerCase());
+ }
+ }
+ 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);
+ // setTimeout(() => { console.log("waiting ..."); }, 2000);
+ allElements[this.text_pos[i]].innerHTML = response.translations[i].translation;
+
+ }
+ });
+
+ }
+
+ // 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..2511512
--- /dev/null
+++ b/liquid-prep-app/src/app/service/LanguageTranslatorService.ts
@@ -0,0 +1,33 @@
+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 body = {"text": text, "model_id":language}
+
+ 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