started backend translations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-12-05 14:38:46 +01:00
parent ebf9a83b60
commit 0d02f3cbda
6 changed files with 19 additions and 5 deletions

View File

@@ -2,9 +2,11 @@
package de.srsoftware.umbrella.core; package de.srsoftware.umbrella.core;
import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.ModuleRegistry.translator;
import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.WARNING; import static java.lang.System.Logger.Level.WARNING;
import static java.net.HttpURLConnection.*; import static java.net.HttpURLConnection.*;
import static java.text.MessageFormat.format;
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.tools.Path; import de.srsoftware.tools.Path;
@@ -72,7 +74,9 @@ public abstract class BaseHandler extends PathHandler {
} }
public boolean send(HttpExchange ex, UmbrellaException e) throws IOException { public boolean send(HttpExchange ex, UmbrellaException e) throws IOException {
return sendContent(ex,e.statusCode(),e.getMessage()); String lang = languages(ex).stream().findFirst().orElse(null);
var translatedMessage = translator().translate(lang,e.getMessage());
return sendContent(ex,e.statusCode(),format(translatedMessage,e.fills()));
} }
public boolean unauthorized(HttpExchange ex) throws IOException { public boolean unauthorized(HttpExchange ex) throws IOException {

View File

@@ -13,13 +13,15 @@ import static java.text.MessageFormat.format;
public class UmbrellaException extends RuntimeException{ public class UmbrellaException extends RuntimeException{
private final int statusCode; private final int statusCode;
private Object[] fills;
public UmbrellaException(String message, Object ... fills){ public UmbrellaException(String message, Object ... fills){
this(HTTP_SERVER_ERROR,message,fills); this(HTTP_SERVER_ERROR,message,fills);
} }
public UmbrellaException(int statusCode, String message, Object ... fills){ public UmbrellaException(int statusCode, String message, Object ... fills){
super(fills == null || fills.length<1 ? message : format(message,fills)); super(message);
this.fills = fills;
this.statusCode = statusCode; this.statusCode = statusCode;
} }
@@ -34,6 +36,10 @@ public class UmbrellaException extends RuntimeException{
return new UmbrellaException(message,fills); return new UmbrellaException(message,fills);
} }
public Object[] fills(){
return fills;
}
public static UmbrellaException forbidden(String message, Object... fills) { public static UmbrellaException forbidden(String message, Object... fills) {
return new UmbrellaException(HTTP_FORBIDDEN,message,fills); return new UmbrellaException(HTTP_FORBIDDEN,message,fills);
} }

View File

@@ -137,7 +137,7 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) project = Project.of(rs); if (rs.next()) project = Project.of(rs);
rs.close(); rs.close();
if (project == null) throw UmbrellaException.notFound("No project found for id {0}",projectId); if (project == null) throw UmbrellaException.notFound("no_project_for_id",projectId);
rs = select(ALL).from(TABLE_CUSTOM_STATES).where(PROJECT_ID,equal(projectId)).exec(db); rs = select(ALL).from(TABLE_CUSTOM_STATES).where(PROJECT_ID,equal(projectId)).exec(db);
var states = project.allowedStates(); var states = project.allowedStates();

View File

@@ -270,7 +270,7 @@ CREATE TABLE IF NOT EXISTS {0} (
public Task load(long taskId) throws UmbrellaException { public Task load(long taskId) throws UmbrellaException {
var map = load(List.of(taskId)); var map = load(List.of(taskId));
var task = map.get(taskId); var task = map.get(taskId);
if (task == null) throw UmbrellaException.notFound("No task found for id {0}",taskId); if (task == null) throw UmbrellaException.notFound("no_task_for_id",taskId);
return task; return task;
} }

View File

@@ -183,6 +183,8 @@
"new_password": "neues Passwort", "new_password": "neues Passwort",
"new_property": "neue Eigenschaft", "new_property": "neue Eigenschaft",
"no_company": "keine Firma", "no_company": "keine Firma",
"no_project_for_id": "Kein Projekt mit ID {0} gefunden!",
"no_task_for_id": "Keine Aufgabe mit ID {0} gefunden!",
"note": "Notiz", "note": "Notiz",
"notes": "Notizen", "notes": "Notizen",
"not_recent_version": "Die ist nicht die neuste Version dieser Seite!", "not_recent_version": "Die ist nicht die neuste Version dieser Seite!",

View File

@@ -183,6 +183,8 @@
"new_password": "new password", "new_password": "new password",
"new_property": "new property", "new_property": "new property",
"no_company": "no company", "no_company": "no company",
"no_project_for_id": "No project found for id {0}",
"no_task_for_id": "No task found for id {0}",
"note": "note", "note": "note",
"notes": "notes", "notes": "notes",
"not_recent_version": "This is not the current version of this page!", "not_recent_version": "This is not the current version of this page!",