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;
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.WARNING;
import static java.net.HttpURLConnection.*;
import static java.text.MessageFormat.format;
import com.sun.net.httpserver.HttpExchange;
import de.srsoftware.tools.Path;
@@ -72,7 +74,9 @@ public abstract class BaseHandler extends PathHandler {
}
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 {

View File

@@ -13,13 +13,15 @@ import static java.text.MessageFormat.format;
public class UmbrellaException extends RuntimeException{
private final int statusCode;
private Object[] fills;
public UmbrellaException(String message, Object ... fills){
this(HTTP_SERVER_ERROR,message,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;
}
@@ -34,6 +36,10 @@ public class UmbrellaException extends RuntimeException{
return new UmbrellaException(message,fills);
}
public Object[] fills(){
return fills;
}
public static UmbrellaException forbidden(String message, Object... fills) {
return new UmbrellaException(HTTP_FORBIDDEN,message,fills);
}