Commit 70163b4a authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

simplified language change, now offers names instead of flags

parent 7d033267
{
"name": "mc_frontend",
"version": "0.9.6",
"version": "0.9.7",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
......
......@@ -3,7 +3,6 @@ import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'change-language', loadChildren: './change-language/change-language.module#ChangeLanguagePageModule' },
{ path: 'confirm-cancel', loadChildren: './confirm-cancel/confirm-cancel.module#ConfirmCancelPageModule' },
{ path: 'author', loadChildren: './author/author.module#AuthorPageModule' },
{ path: 'author-detail', loadChildren: './author-detail/author-detail.module#AuthorDetailPageModule' },
......@@ -18,8 +17,9 @@ const routes: Routes = [
{ path: 'sources', loadChildren: './sources/sources.module#SourcesPageModule' },
{ path: 'test', loadChildren: './test/test.module#TestPageModule' },
{ path: 'text-range', loadChildren: './text-range/text-range.module#TextRangePageModule' },
{ path: 'vocabulary-check', loadChildren: './vocabulary-check/vocabulary-check.module#VocabularyCheckPageModule' }, { path: 'exercise', loadChildren: './exercise/exercise.module#ExercisePageModule' },
{ path: 'vocabulary-check', loadChildren: './vocabulary-check/vocabulary-check.module#VocabularyCheckPageModule' },
{ path: 'exercise', loadChildren: './exercise/exercise.module#ExercisePageModule' },
];
......
......@@ -11,15 +11,13 @@ import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from 'src/app/app.component';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {ChangeLanguagePage} from 'src/app/change-language/change-language.page';
import {ChangeLanguagePageModule} from 'src/app/change-language/change-language.module';
import {HelperService} from 'src/app/helper.service';
import {ConfirmCancelPageModule} from 'src/app/confirm-cancel/confirm-cancel.module';
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
declarations: [AppComponent],
entryComponents: [ChangeLanguagePage],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
......@@ -33,7 +31,6 @@ import {APP_BASE_HREF} from '@angular/common';
deps: [HttpClient]
}
}),
ChangeLanguagePageModule,
ConfirmCancelPageModule
],
providers: [
......
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {Routes, RouterModule} from '@angular/router';
import {IonicModule} from '@ionic/angular';
import {ChangeLanguagePage} from './change-language.page';
import {TranslateLoader, TranslateModule} from "@ngx-translate/core";
import {HttpClient} from "@angular/common/http";
import {HelperService} from "src/app/helper.service";
const routes: Routes = [
{
path: '',
component: ChangeLanguagePage
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes),
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
useFactory: (HelperService.createTranslateLoader),
deps: [HttpClient]
}
}),
],
declarations: [ChangeLanguagePage]
})
export class ChangeLanguagePageModule {
}
<ion-header>
<ion-toolbar>
<ion-title>{{ 'LANGUAGE_CHANGE' | translate }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<button (click)="changeLanguage('en')">
<img src="assets/imgs/en.svg" width="80px" height="48px">
</button>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<button (click)="changeLanguage('de')">
<img src="assets/imgs/de.svg" width="80px" height="48px">
</button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ChangeLanguagePage } from './change-language.page';
describe('ChangeLanguagePage', () => {
let component: ChangeLanguagePage;
let fixture: ComponentFixture<ChangeLanguagePage>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ChangeLanguagePage ],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ChangeLanguagePage);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import {Component, OnInit} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {HelperService} from 'src/app/helper.service';
import {CorpusService} from 'src/app/corpus.service';
@Component({
selector: 'app-change-language',
templateUrl: './change-language.page.html',
styleUrls: ['./change-language.page.scss'],
})
export class ChangeLanguagePage implements OnInit {
constructor(public translate: TranslateService,
public corpusService: CorpusService) {
}
changeLanguage(newLanguage: string) {
if (this.translate.currentLang !== newLanguage) {
this.translate.use(newLanguage).subscribe(() => {
HelperService.loadTranslations(this.translate);
this.corpusService.initPhenomenonMap();
this.corpusService.processAnnisResponse(this.corpusService.annisResponse);
this.corpusService.adjustTranslations();
});
}
}
ngOnInit() {
}
}
......@@ -98,12 +98,12 @@ export class CorpusService {
checkAnnisResponse() {
return new Promise((resolve) => {
if (this.annisResponse) {
resolve();
return resolve();
}
this.helperService.loadMostRecentSetup().then(() => {
this.annisResponse = HelperService.mostRecentSetup.annisResponse;
this.currentUrn = HelperService.mostRecentSetup.currentUrn;
resolve();
return resolve();
});
});
}
......@@ -127,10 +127,10 @@ export class CorpusService {
const updateInfo: object = {corpora: {lastAccessTime: new Date().getTime()}};
window.localStorage.setItem(HelperService.config['localStorageKeyUpdateInfo'], JSON.stringify(updateInfo));
this.processCorpora(corpusList);
resolve();
return resolve();
} else {
this.loadCorporaFromLocalStorage();
resolve();
return resolve();
}
}, async (error: HttpErrorResponse) => {
this.loadCorporaFromLocalStorage();
......@@ -140,7 +140,7 @@ export class CorpusService {
position: 'top'
});
toast.present().then();
resolve(error);
return resolve(error);
});
});
}
......@@ -167,14 +167,14 @@ export class CorpusService {
return new Promise((resolve, reject) => {
this.currentText = '';
if (HelperService.isVocabularyCheck) {
resolve();
return resolve();
} else {
HelperService.currentError = null;
HelperService.isLoading = true;
this.getCTStextPassage(this.currentUrn).subscribe((ar: AnnisResponse) => {
HelperService.isLoading = false;
this.processAnnisResponse(ar, saveToCache);
resolve();
return resolve();
}, async (error: HttpErrorResponse) => {
HelperService.isLoading = false;
HelperService.currentError = error;
......@@ -184,7 +184,7 @@ export class CorpusService {
position: 'top'
});
toast.present().then();
reject();
return reject();
});
}
});
......
......@@ -7,6 +7,7 @@ import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {CaseValue, DependencyValue, PartOfSpeechValue} from 'src/app/models/enum';
import {TranslateService} from '@ngx-translate/core';
import {Storage} from '@ionic/storage';
import {Language} from 'src/app/models/language';
@Injectable({
providedIn: 'root'
......@@ -27,6 +28,7 @@ export class HelperService {
public static config: object;
public static corpusUpdateCompletedString: string;
public static currentError: HttpErrorResponse;
public static currentLanguage: Language;
public static currentPopover: any;
public static dependencyMap: { [rawValue: string]: DependencyValue } = {
acl: DependencyValue.adjectivalClause,
......@@ -74,6 +76,10 @@ export class HelperService {
public static isLoading = false;
public static isDevMode = ['localhost'].indexOf(window.location.hostname) > -1; // set this to "false" for simulated production mode
public static isVocabularyCheck = false;
public static languages: Language[] = [new Language({
name: 'English',
shortcut: 'en'
}), new Language({name: 'Deutsch', shortcut: 'de'})];
public static mostRecentSetup: ApplicationState = null;
public static partOfSpeechMap: { [rawValue: string]: PartOfSpeechValue } = {
ADJ: PartOfSpeechValue.adjective,
......@@ -97,8 +103,10 @@ export class HelperService {
constructor(public http: HttpClient,
private storage: Storage,
public translate: TranslateService,
) {
this.initConfig().then();
this.initLanguage();
}
// The translate loader needs to know where to load i18n files in Ionic's static asset pipeline.
......@@ -189,7 +197,7 @@ export class HelperService {
setTimeout(resolveWait, 50);
});
}
resolve();
return resolve();
});
}
......@@ -201,16 +209,24 @@ export class HelperService {
const part1: string = location.protocol.concat('//').concat(window.location.host);
HelperService.config['backendBaseUrl'] = part1.concat(HelperService.config['backendBaseApiPath']).concat('/');
}
resolve();
return resolve();
});
});
}
initLanguage(): void {
// dirty hack to wait for the translateService intializing
setTimeout(() => {
HelperService.currentLanguage = HelperService.languages.find(x => x.shortcut === this.translate.currentLang);
HelperService.loadTranslations(this.translate);
});
}
loadMostRecentSetup() {
return new Promise(async (resolve) => {
this.storage.get(HelperService.config['localStorageKeyMostRecentSetup']).then((mrs: string) => {
HelperService.mostRecentSetup = JSON.parse(mrs);
resolve();
return resolve();
});
});
}
......@@ -219,7 +235,7 @@ export class HelperService {
return new Promise((resolve) => {
const lskmrs: string = HelperService.config['localStorageKeyMostRecentSetup'];
this.storage.set(lskmrs, JSON.stringify(HelperService.mostRecentSetup)).then(() => {
resolve();
return resolve();
});
});
}
......
......@@ -8,10 +8,11 @@
</div>
<div class="toolbar-right">
<ion-spinner *ngIf="HelperService.isLoading"></ion-spinner>
<button (click)="changeLanguage($event).then()">
<img src="{{'assets/imgs/' + translate.currentLang + '.svg'}}" width="50px" height="30px"
alt="{{ 'LANGUAGE_CHANGE' | translate }}">
</button>
<ion-select [(ngModel)]="HelperService.currentLanguage" (ngModelChange)="changeLanguage($event)" name="currentLanguage"
placeholder="{{HelperService.currentLanguage.name}}">
<ion-select-option *ngFor="let lang of HelperService.languages"
value="{{lang.shortcut}}">{{lang.name}}</ion-select-option>
</ion-select>
</div>
</ion-toolbar>
</ion-header>
......
.lastMainElement {
height: 40%;
}
// celebration (balloons) background for the front page
//ion-content {
// --background: url('https://banner2.kisspng.com/20180309/qye/kisspng-toy-balloon-logo-round-balloon-5aa24037188f43.2515953015205827111007.jpg') no-repeat 50% 40%/500px 30%;
......
import {Component, OnInit} from '@angular/core';
import {HelperService} from 'src/app/helper.service';
import {NavController, PopoverController, ToastController} from '@ionic/angular';
import {NavController, ToastController} from '@ionic/angular';
import {HttpClient} from '@angular/common/http';
import {TranslateService} from '@ngx-translate/core';
import {ExerciseService} from 'src/app/exercise.service';
import {CorpusService} from 'src/app/corpus.service';
import {ChangeLanguagePage} from 'src/app/change-language/change-language.page';
@Component({
selector: 'app-home',
......@@ -22,17 +21,18 @@ export class HomePage implements OnInit {
public translate: TranslateService,
public corpusService: CorpusService,
public toastCtrl: ToastController,
public popoverController: PopoverController,
) {
}
async changeLanguage(ev: any = null) {
const popover = await this.popoverController.create({
component: ChangeLanguagePage,
event: ev,
translucent: true
});
return await popover.present();
changeLanguage(newLanguage: string) {
if (this.translate.currentLang !== newLanguage) {
this.translate.use(newLanguage).subscribe(() => {
HelperService.loadTranslations(this.translate);
this.corpusService.initPhenomenonMap();
this.corpusService.processAnnisResponse(this.corpusService.annisResponse);
this.corpusService.adjustTranslations();
});
}
}
ionViewDidEnter() {
......
export class Language {
public name: string;
public shortcut: string;
constructor(init?: Partial<Language>) {
Object.assign(this, init);
}
}
......@@ -61,16 +61,16 @@ export class TextRangePage {
this.mapCitationLabelsToValues(cls2, 2, citationLabelsStart, this.citationValuesStart).then(() => {
const cle2: string = citationLabelsEnd[2];
this.mapCitationLabelsToValues(cle2, 2, citationLabelsEnd, this.citationValuesEnd).then(() => {
resolve();
return resolve();
});
});
} else {
resolve();
return resolve();
}
});
}, () => reject());
} else {
resolve();
return resolve();
}
});
}, () => reject());
......@@ -80,7 +80,7 @@ export class TextRangePage {
private addReferences(targetCitationLevel: string, relevantCitations: Citation[] = []) {
return new Promise((resolve, reject) => {
if (relevantCitations.some(x => !x)) {
resolve();
return resolve();
}
const urnLastPart: string = relevantCitations.map(x => x.isNumeric ? x.value.toString() : x.label).join('.');
const fullUrn: string = this.corpusService.currentCorpus.source_urn + (urnLastPart ? ':' + urnLastPart : '');
......@@ -98,7 +98,7 @@ export class TextRangePage {
isNumeric,
level: targetCitationLevel,
label: urnModified,
value: (isNumeric ? newCitations.length + 1 : +urnModified)
value: (isNumeric ? +urnModified : newCitations.length + 1)
}));
});
newCitations.forEach((citation) => {
......@@ -118,7 +118,7 @@ export class TextRangePage {
const secondLabel: string = this.corpusService.currentCorpus.citations[rc0Label].subcitations[rc1Label].label;
this.currentlyAvailableCitations.push(firstLabel.concat('.', secondLabel, '.', citation.label));
}
resolve();
return resolve();
});
}, async (error: HttpErrorResponse) => {
HelperService.isLoading = false;
......@@ -129,7 +129,7 @@ export class TextRangePage {
position: 'top'
});
toast.present().then();
reject();
return reject();
});
});
}
......@@ -236,34 +236,34 @@ export class TextRangePage {
return new Promise((resolve, reject) => {
if (index === 0 && this.corpusService.currentCorpus.citations[label]) {
valueList.push(this.corpusService.currentCorpus.citations[label].value);
resolve();
return resolve();
} else if (index === 1) {
if (!this.corpusService.currentCorpus.citations[citationLabels[index - 1]]) {
if (!!+label) {
valueList.push(+label);
resolve();
return resolve();
} else {
reject();
return reject();
}
}
if (Object.keys(this.corpusService.currentCorpus.citations[citationLabels[index - 1]].subcitations).length === 0) {
const relevantCitations: Citation[] = [this.corpusService.currentCorpus.citations[citationLabels[index - 1]]];
this.addReferences(this.corpusService.currentCorpus.citation_level_2, relevantCitations).then(() => {
valueList.push(this.corpusService.currentCorpus.citations[citationLabels[index - 1]].subcitations[label].value);
resolve();
return resolve();
}, () => reject());
} else {
valueList.push(this.corpusService.currentCorpus.citations[citationLabels[index - 1]].subcitations[label].value);
resolve();
return resolve();
}
} else if (index === 2) {
if (!this.corpusService.currentCorpus.citations[citationLabels[index - 2]] ||
!this.corpusService.currentCorpus.citations[citationLabels[index - 2]].subcitations[citationLabels[index - 1]]) {
if (!!+label) {
valueList.push(+label);
resolve();
return resolve();
} else {
reject();
return reject();
}
}
const citation: Citation = this.corpusService.currentCorpus.citations[citationLabels[index - 2]];
......@@ -271,15 +271,15 @@ export class TextRangePage {
if (Object.keys(subCitation.subcitations).length === 0) {
this.addReferences(this.corpusService.currentCorpus.citation_level_3, [citation, subCitation]).then(() => {
valueList.push(subCitation.subcitations[label].value);
resolve();
return resolve();
}, () => reject());
} else {
valueList.push(subCitation.subcitations[label].value);
resolve();
return resolve();
}
} else if (!!+label) {
valueList.push(+label);
resolve();
return resolve();
}
});
}
......@@ -333,10 +333,10 @@ export class TextRangePage {
const baseCit: Citation = this.corpusService.currentCorpus.citations[relTextRangePart[0]];
if (baseCit && (Object.keys(baseCit.subcitations).length ||
this.corpusService.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default])) {
resolve();
return resolve();
} else {
this.addReferences(this.corpusService.currentCorpus.citation_level_2, [baseCit]).then(() => {
resolve();
return resolve();
});
}
}).then(() => {
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="600" viewBox="0 0 5 3">
<desc>Flag of Germany</desc>
<rect id="black_stripe" width="5" height="3" y="0" x="0" fill="#000"/>
<rect id="red_stripe" width="5" height="2" y="1" x="0" fill="#D00"/>
<rect id="gold_stripe" width="5" height="1" y="2" x="0" fill="#FFCE00"/>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="600" viewBox="0,0 25,15">
<rect width="25" height="15" fill="#00247d"/>
<path d="M 0,0 L 25,15 M 25,0 L 0,15" stroke="#fff" stroke-width="3"/>
<path d="M 12.5,0 V 15 M 0,7.5 H 25" stroke="#fff" stroke-width="5"/>
<path d="M 12.5,0 V 15 M 0,7.5 H 25" stroke="#cf142b" stroke-width="3"/>
</svg>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment