akoenig/express-lingua — Issue #7: How do I insert dynamic data to a translated string?
Author: goloroden
Created: 2012-01-20 20:04:54+00:00
State: open

I have the following situation: A website contains a string that is translated using express-lingua.
Inside this string there is a value that needs to be inserted dynamically, as it comes from a database. So basically I have a string in my i18n file which looks like:

bla bla bla %d bla bla bla

This %d is the placeholder for the dynamic data.
On each request I load this data from the database to have a "fresh" value.

So how do I combine the i18n resource string and the dynamic data?

I've tried by accessing res.lingua.content.foo and replacing %d by the value by using util.format. This works on the first request, but since the i18n value is cached, on each further request there is no %d so the value gets added to the i18n string.

What is the best way to solve this?