Bläddra i källkod

🌐 ✨ i18n roles and problems

jmacura 4 år sedan
förälder
incheckning
ac56b4c24a

+ 4 - 0
src/adjuster/adjuster-presets.service.ts

@@ -57,6 +57,10 @@ export class AdjusterPresetsService {
       }) ?? [];
   }
 
+  getLabelInLang(labels: Label[], lang: string) {
+    return labels.find((labelEntity) => labelEntity['@language'] == lang)?.['@value'] ?? labels[0]['@value'];
+  }
+
   loadRoles() {
     this.roles = this.ontology
       .filter((subject) => subject['@type']?.includes("http://www.semanticweb.org/attractiveness/Role"))

+ 3 - 3
src/adjuster/adjuster.component.html

@@ -26,11 +26,11 @@
     <div class="p-2 center-block">
       {{'ADJUSTER.myRoleIs' | translate}}:&emsp;
       <select class="form-select" [(ngModel)]="adjusterPresetsService.activeRole" (ngModelChange)="adjusterPresetsService.pickProblem($event)">
-        <option *ngFor="let role of adjusterPresetsService.roles" [ngValue]="role">{{role.labels[0]['@value']}}</option>
+        <option *ngFor="let role of adjusterPresetsService.roles" [ngValue]="role">{{getLabelInCurrentLang(role.labels)}}</option>
       </select>
       {{'ADJUSTER.myProblemIs' | translate}}:&emsp;
       <select class="form-select" [(ngModel)]="adjusterPresetsService.activeProblem" (ngModelChange)="adjusterPresetsService.applyProblem($event)">
-        <option *ngFor="let problem of adjusterPresetsService.getActiveRoleProblems()" [ngValue]="problem">{{problem.labels[0]['@value']}}</option>
+        <option *ngFor="let problem of adjusterPresetsService.getActiveRoleProblems()" [ngValue]="problem">{{getLabelInCurrentLang(problem.labels)}}</option>
       </select>
     </div>
     <button class="btn btn-secondary btn-sm" aria-expanded="false" aria-controls="advancedOptions" (click)="showAdvancedOptions = !showAdvancedOptions">
@@ -40,7 +40,7 @@
     <div class="p-2 center-block" [hidden]="!showAdvancedOptions">
       {{'ADJUSTER.classifyBySchema' | translate}}:&emsp;
       <select class="form-select" [(ngModel)]="adjusterPresetsService.activeSchema" (ngModelChange)="adjusterPresetsService.changeSchema($event)">
-        <option *ngFor="let schema of adjusterPresetsService.schemas" [ngValue]="schema">{{schema.labels[0]['@value']}}</option>
+        <option *ngFor="let schema of adjusterPresetsService.schemas" [ngValue]="schema">{{getLabelInCurrentLang(schema.labels)}}</option>
       </select>
     </div>
     <div class="p-2 center-block" [hidden]="!adjusterService.allowClusters">

+ 6 - 0
src/adjuster/adjuster.component.ts

@@ -1,6 +1,7 @@
 import {Component, OnInit, ViewRef} from '@angular/core';
 
 import {HsDialogContainerService} from 'hslayers-ng';
+import {HsLanguageService} from 'hslayers-ng';
 import {HsLayoutService} from 'hslayers-ng';
 import {HsPanelComponent} from 'hslayers-ng';
 
@@ -27,6 +28,7 @@ export class AdjusterComponent implements HsPanelComponent, OnInit {
     public adjusterService: AdjusterService,
     public adjusterPresetsService: AdjusterPresetsService,
     public hsDialogContainerService: HsDialogContainerService,
+    public hsLanguageService: HsLanguageService,
     public hsLayoutService: HsLayoutService
   ) {
     //this.descriptionVisible = false;
@@ -46,6 +48,10 @@ export class AdjusterComponent implements HsPanelComponent, OnInit {
     return factor.datasets.length > 0;
   }
 
+  getLabelInCurrentLang(labels) {
+    return this.adjusterPresetsService.getLabelInLang(labels, this.hsLanguageService.getCurrentLanguageCode());
+  }
+
   isVisible(): boolean {
     return this.hsLayoutService.panelVisible('adjuster');
   }

+ 8 - 4
src/adjuster/metadata-dialog/metadata-dialog.service.ts

@@ -1,15 +1,19 @@
 import {Injectable} from '@angular/core';
 
-import ontology from '../../data/rural_attractiveness.owl.json';
+import { AdjusterPresetsService } from '../adjuster-presets.service';
 import {DatasetDescriptor} from './metadata-dialog.component';
 
 @Injectable({providedIn: 'root'})
 export class MetadataDialogService {
-  constructor() {}
+  ontology;
+
+  constructor(public adjusterPresetsService: AdjusterPresetsService) {
+    this.ontology = this.adjusterPresetsService.ontology;
+  }
   
   loadDatasetMetadata(datasetName: string): DatasetDescriptor {
-    console.log(ontology);
-    const ontoInfo = ontology.find((subject) => subject['http://www.w3.org/2000/01/rdf-schema#label']?.find((label) => label['@value']?.includes(datasetName)))
+    console.log(this.ontology);
+    const ontoInfo = this.ontology.find((subject) => subject['http://www.w3.org/2000/01/rdf-schema#label']?.find((label) => label['@value']?.includes(datasetName)))
     console.log(ontoInfo);
     //TODO: the returned values must reflect possibility of multi-values (e.g. coverage CZ + EU)
     return {