I need a format for storing log messages (in a database).
Messages need to be stored in a language independent format, so they can later be displayed in the users chosen language (and locale).
The message-patterns can contain substitutions, that might be
- Numbers, dates, etc. (which should be formatted according to locale)
- Untranslatable substrings (user-supplied data, which can’t be translated, for instance a customer name or an address)
- Translatable substrings (from the system, which should also be translated)
Currently I store messages as a key and a set of parameters, which I then feed into the Java ResourceBundle format.
So I store message_key="user_logged_in"
, message_parameters="rasmus_faber,2017-12-07"
and look up message_key_translation_en="User {0} logged in at {1}"
.
But this format does not (as far as I can tell) support embedding sub-translations.
For instance if the system had hard-coded user roles and I wanted to include the translated role in the message, I do not have a simple way to do it.
One way might be something like message_key="user_logged_in_with_role"
, message_parameters="rasmus_faber,2017-12-07,ADMINISTRATOR"
and look up message_key_translation_en="User {0} logged in at {1}, user is {2:translation}"
.
This seems like a problem other people must have encountered and I would strongly prefer not do invent my own format.
So what is the standard way to format messages like that? (And it is a bonus if I can find a Java library to perform the actual formatting).