Rails offer a functionality of passing variable to translation:
http://guides.rubyonrails.org/i18n.html#passing-variables-to-translations
I'd like to be able to use these files on the client, i.e. in Javascript. The files are already translated to JSON, but I'd like to be able to set parameters in the translated strings.
For example:
There are %{apple_count} apples in basket ID %{basket_id}.
Where %{apple_count} and %{basket_id} will be replaced with parameters.
This is the call I want to use in JS (i.e. I want to implement origStr):
var str = replaceParams(origStr, {apple_count: 5, basket_id: "aaa"});
I am guessing the best strategy would be to use a regular expression. If so, please offer a good regular expression. But I'm open to hear any other options.