Skip to content

Commit

Permalink
Add placeholders for German translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Dec 3, 2024
1 parent 1307d11 commit a4cc5dc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
62 changes: 42 additions & 20 deletions src/app/_interceptors/errorInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpErrorResponse } from '@angular/common/http';
import {Observable, throwError} from 'rxjs';
import {Injectable} from '@angular/core';
import {AppState} from '../_store';
import {Store} from '@ngrx/store';
import { Observable, throwError } from 'rxjs';
import { Injectable } from '@angular/core';
import { AppState } from '../_store';
import { Store } from '@ngrx/store';
import * as fromAuth from '../_store/auth/auth.action';
import {catchError} from 'rxjs/operators';
import {Router} from '@angular/router';
import {MatSnackBar} from '@angular/material/snack-bar';
import { catchError } from 'rxjs/operators';
import { Router } from '@angular/router';
import { MatSnackBar } from '@angular/material/snack-bar';

function formatArea(area: number): string {
return area > 100000 ?
`${Math.round((area / 1000000) * 100) / 100}km²` :
`${Math.round(area * 100) / 100}m²`;
}

function formatAreaError(err: { message: [string], expected: [number], actual: [number] }): string {
const over = err.actual[0] - err.expected[0];
return $localize`Selected area is too large, allowed: ${formatArea(err.expected[0])}, selected: ${formatArea(err.actual[0])}, overflow: ${formatArea(over)}`;
}

function formatGenericError(err: any): string {
const messages = [];
for (const attr in err) {
if (!err[attr]) {
continue;
}
if (Array.isArray(err[attr])) {
messages.push(...err[attr]);
} else if (err[attr] === 'string') {
messages.push(err[attr]);
}
}
return messages.join("\n");
}

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
Expand All @@ -24,22 +50,18 @@ export class ErrorInterceptor implements HttpInterceptor {
this.store.dispatch(fromAuth.logout());
this.router.navigate(['/auth/login']);
} else {
const messages = [];
let message = "";
const err = response.error;

for (const attr in err) {
if (response.error[attr]) {
if (Array.isArray(response.error[attr])) {
messages.push(...response.error[attr]);
} else if (response.error[attr] === 'string') {
messages.push(response.error[attr]);
}
}
// TODO: Better error type recognition
if (Array.isArray(err.message) && err.message[0] === 'Order area is too large') {
message = formatAreaError(err);
} else {
message = formatGenericError(err);
}
if (messages.length === 0) {
messages.push(response.message);
if (message.length === 0) {
message = response.message;
}
this.snackBar.open(messages.join('\r\n'), 'Ok', {panelClass: 'notification-error'});
this.snackBar.open(message, 'Ok', { panelClass: 'notification-error' });
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/locale/messages.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@
<context context-type="linenumber">31</context>
</context-group>
</trans-unit>
<trans-unit id="6578332984012136226" datatype="html">
<source>TODO-GERMAN: Selected area is too large, allowed: <x id="PH" equiv-text="formatArea(err.expected[0])"/>, selected: <x id="PH_1" equiv-text="formatArea(err.actual[0])"/>, overflow: <x id="PH_2" equiv-text="formatArea(over)"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_interceptors/errorInterceptor.ts</context>
<context context-type="linenumber">19</context>
</context-group>
</trans-unit>
<trans-unit id="8151944010898811895" datatype="html">
<source>Décision soumise avec succès</source>
<target>TODO: German</target>
Expand Down
7 changes: 7 additions & 0 deletions src/locale/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@
<context context-type="linenumber">31</context>
</context-group>
</trans-unit>
<trans-unit id="6578332984012136226" datatype="html">
<source>Selected area is too large, allowed: <x id="PH" equiv-text="formatArea(err.expected[0])"/>, selected: <x id="PH_1" equiv-text="formatArea(err.actual[0])"/>, overflow: <x id="PH_2" equiv-text="formatArea(over)"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_interceptors/errorInterceptor.ts</context>
<context context-type="linenumber">19</context>
</context-group>
</trans-unit>
<trans-unit id="8151944010898811895" datatype="html">
<source>Décision soumise avec succès</source>
<context-group purpose="location">
Expand Down

0 comments on commit a4cc5dc

Please sign in to comment.