How to keep strings out of server code



I’m starting to use log messages in the server.
The server messages use template scripts. I would like all these messages to defined in a single file, avoiding duplicated messages and making them all more standard. However, since there are variables included in the messages, that doesn’t seem like a simple task.

let date = new Date();
let userName= “John”;
console.log(Started at ${date});
console.log(Goodbye ${userName});

code file:
let date = new Date();
let userName= “John”;

msg file:
const MSG= { start: “Started at ${date}”,
bye: “Goodbye ${userName}” }

This seem similar to a i18n problem. However i18n usually does not work on the server.

Any thoughts?



We used a strategy similar to this:
We load up language files in json format from private folder at start time on server and push into db

The language file looks like this:

  "msg": "Complete on __"

And we would replace __ with the string at run time

You can also do this

  "msg": "Completed by __user__ on __time__"

And pass object to rendering method


Yes, I was thinking more in something similar to Java format, but my question was more in the term if something (a package, an API) already exists for that.

Seems not!