From b24c702579773a5cd74358084d67e0146da897ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Tue, 4 Dec 2018 21:43:54 +0100 Subject: [PATCH] Add translation service to statistic-componennts --- .../list-statistic/list-statistic.component.html | 8 ++++---- .../list-statistic/list-statistic.component.ts | 16 +++++++++++----- .../shared/statistics/statistics.component.html | 2 +- .../shared/statistics/statistics.component.ts | 8 +++++++- src/assets/i18n/creator/de.json | 7 +++++++ src/assets/i18n/creator/en.json | 7 +++++++ 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/app/components/shared/list-statistic/list-statistic.component.html b/src/app/components/shared/list-statistic/list-statistic.component.html index 25e324e3b..9be304daa 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.html +++ b/src/app/components/shared/list-statistic/list-statistic.component.html @@ -9,28 +9,28 @@ <table mat-table [dataSource]="dataSource" class="mat-elevation-z8"> <ng-container matColumnDef="content"> - <mat-header-cell *matHeaderCellDef> Content </mat-header-cell> + <mat-header-cell *matHeaderCellDef> {{'content.content' | translate}} </mat-header-cell> <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, 'emptyCC' : cp.percent < status.zero }">{{cp.content.subject}}</mat-cell> </ng-container> <ng-container matColumnDef="percentage"> - <mat-header-cell *matHeaderCellDef> Percentage </mat-header-cell> + <mat-header-cell *matHeaderCellDef> {{'statistic.percentage' | translate }} </mat-header-cell> <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.percent.toFixed() + ' %'}}</mat-cell> </ng-container> <ng-container matColumnDef="counts"> - <mat-header-cell *matHeaderCellDef> Total </mat-header-cell> + <mat-header-cell *matHeaderCellDef> {{'statistic.total' | translate}} </mat-header-cell> <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.counts}}</mat-cell> </ng-container> <ng-container matColumnDef="abstentions"> - <mat-header-cell *matHeaderCellDef> Abstentions </mat-header-cell> + <mat-header-cell *matHeaderCellDef> {{'statistic.abstentions' | translate}} </mat-header-cell> <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.abstentions}}</mat-cell> diff --git a/src/app/components/shared/list-statistic/list-statistic.component.ts b/src/app/components/shared/list-statistic/list-statistic.component.ts index 9cec4ae32..69a2c2f05 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.ts +++ b/src/app/components/shared/list-statistic/list-statistic.component.ts @@ -6,8 +6,10 @@ import { ContentType } from '../../../models/content-type.enum'; import { AnswerOption } from '../../../models/answer-option'; import { ContentChoice } from '../../../models/content-choice'; import { Combination } from '../../../models/round-statistics'; +import { TranslateService } from '@ngx-translate/core'; +import { LanguageService } from '../../../services/util/language.service'; -export class ContentPercents { +export class ContentStatistic { content: Content; percent: number; counts: number; @@ -37,15 +39,19 @@ export class ListStatisticComponent implements OnInit { empty: -1, zero: 0 }; - dataSource: ContentPercents[]; + dataSource: ContentStatistic[]; total = 0; totalP = 0; contentCounter = 0; - constructor(private contentService: ContentService) { + constructor(private contentService: ContentService, + private translateService: TranslateService, + protected langService: LanguageService) { + langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit() { + this.translateService.use(localStorage.getItem('currentLang')); this.contentService.getContentChoiceByIds(this.contentGroup.contentIds).subscribe(contents => { this.getData(contents); }); @@ -55,9 +61,9 @@ export class ListStatisticComponent implements OnInit { this.contents = contents; const length = contents.length; let percent; - this.dataSource = new Array<ContentPercents>(length); + this.dataSource = new Array<ContentStatistic>(length); for (let i = 0; i < length; i++) { - this.dataSource[i] = new ContentPercents(null, 0, 0, 0 ); + this.dataSource[i] = new ContentStatistic(null, 0, 0, 0 ); this.dataSource[i].content = this.contents[i]; if (contents[i].format === ContentType.CHOICE) { this.contentService.getAnswer(contents[i].id).subscribe(answer => { diff --git a/src/app/components/shared/statistics/statistics.component.html b/src/app/components/shared/statistics/statistics.component.html index 77a64c31e..6bc2ef84a 100644 --- a/src/app/components/shared/statistics/statistics.component.html +++ b/src/app/components/shared/statistics/statistics.component.html @@ -1,7 +1,7 @@ <div fxLayout="row" fxLayoutGap="20px" fxLayoutAlign="center"> <mat-card> <mat-card-header> - <h2>Learning status</h2> + <h2>{{'statistic.learning-status' | translate}}</h2> </mat-card-header> <mat-divider></mat-divider> <mat-tab-group> diff --git a/src/app/components/shared/statistics/statistics.component.ts b/src/app/components/shared/statistics/statistics.component.ts index cef4ce979..757ebe017 100644 --- a/src/app/components/shared/statistics/statistics.component.ts +++ b/src/app/components/shared/statistics/statistics.component.ts @@ -3,6 +3,8 @@ import { ActivatedRoute } from '@angular/router'; import { RoomService } from '../../../services/http/room.service'; import { ContentGroup } from '../../../models/content-group'; import { Room } from '../../../models/room'; +import { TranslateService } from '@ngx-translate/core'; +import { LanguageService } from '../../../services/util/language.service'; /* TODO: Use TranslateService */ @@ -19,7 +21,10 @@ export class StatisticsComponent implements OnInit { constructor( private route: ActivatedRoute, - private roomService: RoomService) { + private roomService: RoomService, + private translateService: TranslateService, + protected langService: LanguageService) { + langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit(): void { @@ -27,6 +32,7 @@ export class StatisticsComponent implements OnInit { } getRoom(id: string): void { + this.translateService.use(localStorage.getItem('currentLang')); this.roomService.getRoom(id).subscribe(room => { this.contentGroups = room.contentGroups; }); diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index b5645bf47..6d3d17fed 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -21,6 +21,7 @@ "default-content-group": "Standard" }, "content": { + "content": "Frage", "create": "Erstellen", "collection": "Sammlung", "body": "Inhalt", @@ -54,5 +55,11 @@ "description": "Beschreibung", "max-ls": "Max. Zeichen:", "create-session": "Session erstellen" + }, + "statistic": { + "learning-status": "Lernstand", + "total": "Total", + "percentage": "Prozent", + "abstentions": "Enthaltungen" } } diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 2da377443..95f47fa0a 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -20,6 +20,7 @@ "default-content-group": "Default" }, "content": { + "content": "Content", "create": "Create", "collection": "Collection", "body": "Body", @@ -53,5 +54,11 @@ "description": "Description", "max-ls": "Max. letters / signs:", "create-session": "Create session" + }, + "statistic": { + "learning-status": "Learning status", + "total": "Total", + "percentage": "Percentage", + "abstentions": "Abstentions" } } -- GitLab