From 49ecacc797b660cd70fa3189fd132afdce1ebd78 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 25 Mar 2024 18:30:05 +0100 Subject: [PATCH] fixed texts Signed-off-by: Stephan Richter --- .../srsoftware/widerhall/data/ListMember.java | 50 +++++++++---------- .../widerhall/data/MailingList.java | 12 ++--- .../de/srsoftware/widerhall/data/User.java | 2 +- .../widerhall/mail/ProblemListener.java | 3 +- .../srsoftware/widerhall/mail/SmtpClient.java | 6 +-- .../de/srsoftware/widerhall/web/Rest.java | 50 +++++++++---------- .../widerhall/web/TemplateServlet.java | 2 +- .../java/de/srsoftware/widerhall/web/Web.java | 20 ++++---- 8 files changed, 72 insertions(+), 73 deletions(-) diff --git a/src/main/java/de/srsoftware/widerhall/data/ListMember.java b/src/main/java/de/srsoftware/widerhall/data/ListMember.java index ce2134e..65da35e 100644 --- a/src/main/java/de/srsoftware/widerhall/data/ListMember.java +++ b/src/main/java/de/srsoftware/widerhall/data/ListMember.java @@ -50,13 +50,13 @@ public class ListMember { } public String addNewModerator(String userEmail) { - if (!isAllowedToEditMods()) return t("You are not allowed to nominate new mods for {}",list.email()); + if (!isAllowedToEditMods()) return t("You are not allowed to nominate new mods for {}!",list.email()); User moderator = null; try { moderator = User.load(userEmail); } catch (SQLException e) { - LOG.warn("Failed to load user for {}",userEmail,e); - return t("Failed to load user for {}",userEmail); + LOG.warn("Failed to load user for {}!",userEmail,e); + return t("Failed to load user for {}!",userEmail); } if (moderator == null) return t("No such user: {}",userEmail); @@ -64,8 +64,8 @@ public class ListMember { try { member = ListMember.load(list,moderator); } catch (SQLException e) { - LOG.warn("Failed to load list member for {}/{}",moderator.email(),list.email(),e); - return t("Failed to load list member for {}/{}",moderator.email(),list.email()); + LOG.warn("Failed to load list member for {}/{}!",moderator.email(),list.email(),e); + return t("Failed to load list member for {}/{}!",moderator.email(),list.email()); } try { if (member == null) { @@ -146,13 +146,13 @@ public class ListMember { } public String dropMember(String userEmail) { - if (!isModerator()) return t("You are not allowed to remove members of {}",list.email()); + if (!isModerator()) return t("You are not allowed to remove members of {}!",list.email()); User user = null; try { user = User.load(userEmail); } catch (SQLException e) { - LOG.warn("Failed to load user for {}",userEmail,e); - return t("Failed to load user for {}",userEmail); + LOG.warn("Failed to load user for {}!",userEmail,e); + return t("Failed to load user for {}!",userEmail); } if (user == null) return t("No such user: {}",userEmail); @@ -160,30 +160,30 @@ public class ListMember { try { member = ListMember.load(list,user); } catch (SQLException e) { - LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e); - return t("Failed to load list member for {}/{}",user.email(),list.email()); + LOG.warn("Failed to load list member for {}/{}!",user.email(),list.email(),e); + return t("Failed to load list member for {}/{}!",user.email(),list.email()); } - if (member == null) return t("{} is no member of {}",user.email(),list.email()); - if (member.isOwner()) return t("You are not allowed to remvoe the list owner!"); + if (member == null) return t("{} is no member of {}!",user.email(),list.email()); + if (member.isOwner()) return t("You are not allowed to remove the list owner!"); try { member.unsubscribe(); } catch (SQLException e) { - LOG.warn("Failed to un-subscribe {} from {}",user.email(),list.email(),e); - return t("Failed to un-subscribe {} from {}",user.email(),list.email()); + LOG.warn("Failed to un-subscribe {} from {}!",user.email(),list.email(),e); + return t("Failed to un-subscribe {} from {}!",user.email(),list.email()); } return null; } public String dropModerator(String userEmail) { - if (!isAllowedToEditMods()) return t("You are not allowed to edit mods of {}",list.email()); + if (!isAllowedToEditMods()) return t("You are not allowed to edit mods of {}!",list.email()); User moderator = null; try { moderator = User.load(userEmail); } catch (SQLException e) { - LOG.warn("Failed to load user for {}",userEmail,e); - return t("Failed to load user for {}",userEmail); + LOG.warn("Failed to load user for {}!",userEmail,e); + return t("Failed to load user for {}!",userEmail); } if (moderator == null) return t("No such user: {}",userEmail); @@ -191,8 +191,8 @@ public class ListMember { try { member = ListMember.load(list,moderator); } catch (SQLException e) { - LOG.warn("Failed to load list member for {}/{}",moderator.email(),list.email(),e); - return t("Failed to load list member for {}/{}",moderator.email(),list.email()); + LOG.warn("Failed to load list member for {}/{}!",moderator.email(),list.email(),e); + return t("Failed to load list member for {}/{}!",moderator.email(),list.email()); } try { if (member == null) { @@ -201,8 +201,8 @@ public class ListMember { member.setState(Util.unset(member.state,STATE_MODERATOR)); } } catch (SQLException e) { - LOG.warn("Failed to make {} a subscriber of {}",moderator.email(),list.email(),e); - return t("Failed to make {} a subscriber of {}",moderator.email(),list.email()); + LOG.warn("Failed to make {} a subscriber of {}!",moderator.email(),list.email(),e); + return t("Failed to make {} a subscriber of {}!",moderator.email(),list.email()); } return null; } @@ -392,10 +392,10 @@ public class ListMember { */ public String stateText() { var words = new ArrayList(); - if (isAwaiting()) words.add("awaiting confirmation"); - if (isModerator()) words.add("moderator"); - if (isOwner()) words.add("owner"); - if (isSubscriber()) words.add("subscriber"); + if (isAwaiting()) words.add(t("awaiting confirmation")); + if (isModerator()) words.add(t("moderator")); + if (isOwner()) words.add(t("owner")); + if (isSubscriber()) words.add(t("subscriber")); return String.join(", ",words); } diff --git a/src/main/java/de/srsoftware/widerhall/data/MailingList.java b/src/main/java/de/srsoftware/widerhall/data/MailingList.java index dd1a90f..41ce7fd 100644 --- a/src/main/java/de/srsoftware/widerhall/data/MailingList.java +++ b/src/main/java/de/srsoftware/widerhall/data/MailingList.java @@ -270,7 +270,7 @@ public class MailingList implements MessageHandler, ProblemListener { var member = ListMember.load(this,user); return member.hasState(ListMember.STATE_OWNER|ListMember.STATE_SUBSCRIBER); // owners may subscribe their own mailing lists } catch (SQLException e) { - LOG.warn("Was not able to load ListMember: ",e); + LOG.warn("Was not able to load ListMember:",e); return false; } } @@ -303,7 +303,7 @@ public class MailingList implements MessageHandler, ProblemListener { ml.lastError = rs.getString(LAST_ERROR); } } catch (SQLException e) { - LOG.debug("Failed to load MailingList: ",e); + LOG.debug("Failed to load MailingList:",e); } return ml; } @@ -325,7 +325,7 @@ public class MailingList implements MessageHandler, ProblemListener { .compile().exec(); while (rs.next()) list.add(MailingList.from(rs)); } catch (SQLException e) { - LOG.debug("Failed to load MailingLists: ",e); + LOG.debug("Failed to load MailingLists:",e); } return list; } @@ -671,11 +671,11 @@ public class MailingList implements MessageHandler, ProblemListener { try { var config = Configuration.instance(); var url = new StringBuilder(config.baseUrl()).append("/web/confirm?token=").append(member.token()).toString(); - var subject = t("[{}] Please confirm your list subscription",name()); + var subject = t("[{}] Please confirm your list subscription!",name()); var text = template.add(URL,url).add(LIST_NAME,name()).render(); smtp.send(email(),name(),user.email(),subject,text); } catch (UnsupportedEncodingException e) { - throw new MessagingException(t("Failed to send email to {}",user.email()),e); + throw new MessagingException(t("Failed to send email to {}!",user.email()),e); } } @@ -711,7 +711,7 @@ public class MailingList implements MessageHandler, ProblemListener { * @throws UnsupportedEncodingException */ public void test(User user) throws MessagingException, UnsupportedEncodingException { - var subject = t("[{}]: test mail",name()); + var subject = t("[{}] test mail",name()); var text = "If you received this mail, the SMTP settings of your mailing list are correct."; smtp.login().send(email(),name(),user.email(),subject,text); } diff --git a/src/main/java/de/srsoftware/widerhall/data/User.java b/src/main/java/de/srsoftware/widerhall/data/User.java index eae649e..a3d7003 100644 --- a/src/main/java/de/srsoftware/widerhall/data/User.java +++ b/src/main/java/de/srsoftware/widerhall/data/User.java @@ -268,7 +268,7 @@ public class User { * @return */ public Map safeMap(){ - return Map.of(NAME,name,EMAIL,email,PERMISSIONS,permissionList(),PASSWORD,hashedPassword() == null ? "no" : "yes"); + return Map.of(NAME,name,EMAIL,email,PERMISSIONS,permissionList(),PASSWORD,t(hashedPassword() == null ? "no" : "yes")); } /** diff --git a/src/main/java/de/srsoftware/widerhall/mail/ProblemListener.java b/src/main/java/de/srsoftware/widerhall/mail/ProblemListener.java index bf7d260..f117c72 100644 --- a/src/main/java/de/srsoftware/widerhall/mail/ProblemListener.java +++ b/src/main/java/de/srsoftware/widerhall/mail/ProblemListener.java @@ -3,7 +3,6 @@ package de.srsoftware.widerhall.mail; import javax.mail.MessagingException; public interface ProblemListener { - public void onImapException(MessagingException e); - public void clearProblems(); + public void onImapException(MessagingException e); } diff --git a/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java b/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java index df278c5..efb6640 100644 --- a/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java +++ b/src/main/java/de/srsoftware/widerhall/mail/SmtpClient.java @@ -62,7 +62,7 @@ public class SmtpClient { MimeMultipart multipart = new MimeMultipart(); if (forwardAsAttachment){ MimeBodyPart bodyPart = new MimeBodyPart(); - bodyPart.setText("Find the forwarded message in the attachment(s)!\n"); + bodyPart.setText(t("Find the forwarded message in the attachment(s)!\n")); multipart.addBodyPart(bodyPart); // create another body part to contain the message to be forwarded @@ -109,9 +109,9 @@ public class SmtpClient { } public void send(Message message) throws MessagingException { - LOG.debug("Versende Mail…"); + LOG.debug("sending mail…"); Transport.send(message,username,password); - LOG.debug("…versendet"); + LOG.debug("…sent"); } public void send(String senderAdress, String senderName, String receivers, String subject, String content) throws MessagingException, UnsupportedEncodingException { diff --git a/src/main/java/de/srsoftware/widerhall/web/Rest.java b/src/main/java/de/srsoftware/widerhall/web/Rest.java index 6ccfc42..60f0e14 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Rest.java +++ b/src/main/java/de/srsoftware/widerhall/web/Rest.java @@ -47,17 +47,17 @@ public class Rest extends HttpServlet { private static final String SUCCESS = "success"; private Map addPermission(String userEmail, String permissions) { - if (userEmail == null || userEmail.isBlank()) return Map.of(ERROR,"missing user email address!"); + if (userEmail == null || userEmail.isBlank()) return Map.of(ERROR,t("missing user email address!")); try { int perm = Integer.parseInt(permissions); var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null); - if (user == null) return Map.of(ERROR,t("Failed to load user for address {}",userEmail)); + if (user == null) return Map.of(ERROR,t("Failed to load user for address {}!",userEmail)); user.addPermission(perm); } catch (NumberFormatException nfe){ return Map.of(ERROR,"no valid permissions provided!"); } catch (SQLException e) { - LOG.debug("Failed to load user for address {}",userEmail,e); - return Map.of(ERROR,t("Failed to load user for address {}",userEmail)); + LOG.debug("Failed to load user for address {}!",userEmail,e); + return Map.of(ERROR,t("Failed to load user for address {}!",userEmail)); } return Map.of(SUCCESS,"Updated user permissions"); } @@ -141,13 +141,13 @@ public class Rest extends HttpServlet { try { int perm = Integer.parseInt(permissions); var user = User.loadAll(List.of(userEmail)).stream().findAny().orElse(null); - if (user == null) return Map.of(ERROR,t("Failed to load user for address {}",userEmail)); + if (user == null) return Map.of(ERROR,t("Failed to load user for address {}!",userEmail)); user.dropPermission(perm); } catch (NumberFormatException nfe){ return Map.of(ERROR,"no valid permissions provided!"); } catch (SQLException e) { - LOG.debug("Failed to load user for address {}",userEmail,e); - return Map.of(ERROR,t("Failed to load user for address {}",userEmail)); + LOG.debug("Failed to load user for address {}!",userEmail,e); + return Map.of(ERROR,t("Failed to load user for address {}!",userEmail)); } return Map.of(SUCCESS,t("Updated user permissions")); } @@ -157,10 +157,10 @@ public class Rest extends HttpServlet { if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email())); try { list.enable(enable); - return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),enable ? "enabled" : "disabled")); + return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),t(enable ? "enabled" : "disabled"))); } catch (SQLException e) { - LOG.error("Failed to enable/disable mailing list: ",e); - return Map.of(ERROR,t("Failed to update list '{}'",list.email())); + LOG.error("Failed to enable/disable mailing list:",e); + return Map.of(ERROR,t("Failed to update list '{}'!",list.email())); } } @@ -181,7 +181,7 @@ public class Rest extends HttpServlet { json.put("users", (user.hashPermission(User.PERMISSION_ADMIN) ? User.loadAll() : List.of(user)).stream().map(User::safeMap).toList()); } catch (SQLException e) { LOG.debug("Failed to load user list:",e); - json.put(ERROR,"failed to load user list"); + json.put(ERROR,t("failed to load user list")); } break; case LIST_MODERATED: @@ -203,7 +203,7 @@ public class Rest extends HttpServlet { json.put("lists", MailingList.subscribable().stream().map(MailingList::minimalMap).toList()); break; default: - json.put(ERROR,"Not logged in!"); + json.put(ERROR,t("Not logged in!")); } } try { @@ -270,19 +270,19 @@ public class Rest extends HttpServlet { case USER_ADD_PERMISSION: if (user.hashPermission(User.PERMISSION_ADMIN)){ json.putAll(addPermission(userEmail,permissions)); - } else json.put(ERROR,"You are not allowed to alter user permissions!"); + } else json.put(ERROR,t("You are not allowed to alter user permissions!")); break; case USER_DROP_PERMISSION: if (user.hashPermission(User.PERMISSION_ADMIN)){ json.putAll(dropPermission(userEmail,permissions)); - } else json.put(ERROR,"You are not allowed to alter user permissions!"); + } else json.put(ERROR,t("You are not allowed to alter user permissions!")); break; default: json.put(ERROR,t("No handler for path '{}'!",path)); break; } } else { - json.put(ERROR,"Not logged in!"); + json.put(ERROR,t("Not logged in!")); } try { resp.setContentType("application/json"); @@ -298,9 +298,9 @@ public class Rest extends HttpServlet { if (!list.mayBeAlteredBy(user)) Map.of(ERROR,t("You are not allowed to edit '{}'",list.email())); try { list.hide(hide); - return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),hide ? "hidden" : "made public")); + return Map.of(SUCCESS,t("Mailing list '{}' was {}!",list.email(),t(hide ? "hidden" : "made public"))); } catch (SQLException e) { - LOG.error("Failed to (un)hide mailing list: ",e); + LOG.error("Failed to (un)hide mailing list:",e); return Map.of(ERROR,t("Failed to update list '{}'",list.email())); } } @@ -313,7 +313,7 @@ public class Rest extends HttpServlet { LOG.warn("Failed to load list member for {}/{}",user.email(),list.email(),e); return Map.of(ERROR,t("Failed to load list member for {}/{}",user.email(),list.email())); } - if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}",user.email(),list.email())); + if (moderator == null) return Map.of(ERROR,t("{} is not a member of {}!",user.email(),list.email())); var error = moderator.addNewModerator(userEmail); @@ -321,7 +321,7 @@ public class Rest extends HttpServlet { } private Map listDetail(MailingList list, User user) { - if (list == null) return Map.of(ERROR,"no list email provided!"); + if (list == null) return Map.of(ERROR,t("no list email provided!")); var map = new HashMap<>(); if (list.hasState(MailingList.STATE_FORWARD_FROM)) map.put(KEY_FORWARD_FROM,true); if (list.hasState(MailingList.STATE_FORWARD_ATTACHED)) map.put(KEY_FORWARD_ATTACHED,true); @@ -366,8 +366,8 @@ public class Rest extends HttpServlet { } private Map listMembers(MailingList list, User user) { - if (list == null) return Map.of(ERROR,"no list email provided!"); - if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'",list.email())); + if (list == null) return Map.of(ERROR,t("no list email provided!")); + if (!list.membersMayBeListedBy(user)) Map.of(ERROR,t("You are not allowed to list members of '{}'!",list.email())); try { var members = list.members() .sorted((m1,m2)->m1.user().name().compareTo(m2.user().name())) @@ -376,19 +376,19 @@ public class Rest extends HttpServlet { return Map.of(MEMBERS,members,LIST,list.minimalMap()); } catch (SQLException e) { LOG.error("Failed to load member list: ",e); - return Map.of(ERROR,t("Failed to load member list '{}'",list.email())); + return Map.of(ERROR,t("Failed to load member list '{}'!",list.email())); } } private Map testList(MailingList list, User user) { - if (list == null) return Map.of(ERROR,"no list email provided!"); - if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'",list.email())); + if (list == null) return Map.of(ERROR,t("no list email provided!")); + if (!list.mayBeTestedBy(user)) Map.of(ERROR,t("You are not allowed to test '{}'!",list.email())); try { list.test(user); return Map.of(SUCCESS,t("Sent test email to {}",user.email())); } catch (Exception e) { LOG.warn("Failed to send test email",e); - return Map.of(ERROR,t("Failed to send test email to {}",user.email())); + return Map.of(ERROR,t("Failed to send test email to {}!",user.email())); } } } diff --git a/src/main/java/de/srsoftware/widerhall/web/TemplateServlet.java b/src/main/java/de/srsoftware/widerhall/web/TemplateServlet.java index bd55559..a85f861 100644 --- a/src/main/java/de/srsoftware/widerhall/web/TemplateServlet.java +++ b/src/main/java/de/srsoftware/widerhall/web/TemplateServlet.java @@ -52,7 +52,7 @@ public abstract class TemplateServlet extends HttpServlet { resp.getWriter().println(template.render()); return null; } catch (IOException e) { - return t("Failed to load template '{}'",path); + return t("Failed to load template '{}'!",path); } } return t("No template for path '{}'!",path); diff --git a/src/main/java/de/srsoftware/widerhall/web/Web.java b/src/main/java/de/srsoftware/widerhall/web/Web.java index 4ee6b10..617e104 100644 --- a/src/main/java/de/srsoftware/widerhall/web/Web.java +++ b/src/main/java/de/srsoftware/widerhall/web/Web.java @@ -160,7 +160,7 @@ public class Web extends TemplateServlet { return loadTemplate(INDEX,Map.of(USER,listMember.user().safeMap(),NOTES,"Confirmed list subscription!"),resp); } - return t("Unknown user or token"); + return t("Unknown user or token!"); } catch (Exception e) { LOG.debug("Failed to confirm list membership:",e); return t("Confirmation of list membership failed!"); @@ -260,7 +260,7 @@ public class Web extends TemplateServlet { return loadTemplate(ADMIN,data,resp); } catch (SQLException e) { LOG.warn("Editing list {} by {} failed",list.email(),user.email(),e); - return t("Editing list {} by {} failed",list.email(),user.email()); + return t("Editing list {} by {} failed!",list.email(),user.email()); } } @@ -294,7 +294,7 @@ public class Web extends TemplateServlet { return post(req,resp); case RELOAD: loadTemplates(); - data.put(NOTES,t("Templates have been reloaded")); + data.put(NOTES,t("Templates have been reloaded!")); path = INDEX; case CSS: case INDEX: @@ -402,7 +402,7 @@ public class Web extends TemplateServlet { if (!error && !list.mayBeAlteredBy(user)) { error = true; - data.put(ERROR,t("You are not alter settings of this list!")); + data.put(ERROR,t("You are not allowed to alter settings of this list!")); } if (!error){ @@ -463,9 +463,9 @@ public class Web extends TemplateServlet { if (email == null || email.isBlank() || name == null || name.isBlank() || pass == null || pass.isBlank() || - pass_repeat == null || pass_repeat.isBlank()) return loadTemplate(REGISTER,Map.of(ERROR,"Fill all fields, please!",NAME,name,EMAIL,email),resp); - if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,"Passwords do not match!",NAME,name,EMAIL,email),resp); - if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,"Password to short or to simple!",NAME,name,EMAIL,email),resp); + pass_repeat == null || pass_repeat.isBlank()) return loadTemplate(REGISTER,Map.of(ERROR,t"Fill all fields, please!"),NAME,name,EMAIL,email),resp); + if (!pass.equals(pass_repeat)) return loadTemplate(REGISTER,Map.of(ERROR,t("Passwords do not match!"),NAME,name,EMAIL,email),resp); + if (Util.simplePassword(pass)) return loadTemplate(REGISTER,Map.of(ERROR,t("Password to short or to simple!"),NAME,name,EMAIL,email),resp); var firstUser = false; try { @@ -565,12 +565,12 @@ public class Web extends TemplateServlet { data.put(EMAIL,email); if (user != null) data.put(USER,user.safeMap()); if (list == null){ - data.put(ERROR,"No list provided by form data!"); + data.put(ERROR,t("No list provided by form data!")); return loadTemplate(UNSUBSCRIBE,data,resp); } else data.put(LIST,list.email()); if (user == null) { if (email == null || email.isBlank()) { - data.put(ERROR, "Email is required for list un-subscription!"); + data.put(ERROR, t("Email is required for list un-subscription!")); return loadTemplate(UNSUBSCRIBE, data, resp); } var pass = req.getParameter(PASSWORD); @@ -581,7 +581,7 @@ public class Web extends TemplateServlet { req.getSession().setAttribute(USER,user); data.put(USER,user.safeMap()); } catch (InvalidKeyException | SQLException e) { - data.put(ERROR,"Invalid email/password combination!"); + data.put(ERROR,t("Invalid email/password combination!")); return loadTemplate(UNSUBSCRIBE,data,resp); } }