How to manage user messages in Java / Scala?

We save user messages in the properties file as format strings (for example, "Invalid parameter [%s]" ) and create the actual messages at run time. This is convenient because non-programmers can edit messages, but they throw exceptions at run time if the argument list does not match the format string.

Is there a “safe” solution with compile-time checking in Java / Scala that still allows non-technical people to create / edit user messages?

+4
source share
1 answer

The closest I saw to compile time checking of resource packages in Java is cal10n , but this is quite a bit of a boiler plate in and still does not check the correct number of arguments. This simply ensures that the keys are truly present.

Perhaps the best way is to create a simple DSL using Scala? I think this may allow your non-programmers to write message packages that seem simple but are compilers that can be checked by scala.

+2
source

Source: https://habr.com/ru/post/1399540/


All Articles