kbss-cvut / fta-fmea-ui

GNU General Public License v3.0
6 stars 6 forks source link

Localize error messages #572

Closed palagdan closed 1 month ago

palagdan commented 2 months ago

Resolves partially #550

palagdan commented 2 months ago

@blcham I can't localize all the errors from the backend because many errors are dynamically generated. So, I replaced only errors with plain text, that does not contains some value from the backend.

kostobog commented 2 months ago

@blcham When we optimize the text there will be grammar issues and it will be harder to maintain by translators. Variant 2 is nice as it is compact but we should consider that it will be needed to refactor error codes for generic entity errors and also introduce a entity type argument in responseUtis.handleServerError.

blcham commented 2 months ago

ad 1)

When we optimize the text there will be grammar issues and it will be harder to maintain by translators.

I was not able to find any grammar issue although i do not like it much either.

ad 2)

we can discuss on the meeting.

palagdan commented 2 months ago

@blcham

I wanted to discuss one more thing. How should we handle dynamic exception messages like the following with messageId:

public class EntityNotFoundException extends FtaFmeaException {

    public EntityNotFoundException(String message) {
        super(message);
    }

    public static EntityNotFoundException create(String resourceName, Object identifier) {
        return new EntityNotFoundException(resourceName + " identified by " + identifier + " not found.");
    }

}
kostobog commented 2 months ago

@palagdan @blcham Idea for question in comment The server can send the arguments for a parametrized error message. For example:

public class ErrorInfo {
    private String message;
    private String messageId;
    private Map<String, String> messageArguments;
    private String requestUri;
}

For the example above, consider that server sends messageArguments as follows:

{ 
  resourceName: "Component"
  identifier: "component-id"
}

Message template can be declared as follows "errorId": " {{resourceName}} identified by {{identifier}} not found."

And specific message can be constructed as: t(data.messageId, data.messageArguments)

palagdan commented 2 months ago

@blcham

Thanks for the tip @kostobog regarding the arguments! I've implemented it on the backend—could you take a look? I've tested these errors, and now they are localized in Czech too:

Screenshot from 2024-09-17 13-16-40 Screenshot from 2024-09-17 13-18-21 Screenshot from 2024-09-17 14-08-25 Screenshot from 2024-09-17 22-12-49