dellermann / i18n-asset-pipeline

An asset-pipeline plugin for client-side i18n.
Apache License 2.0
3 stars 8 forks source link

Messages with arguments can not be used #11

Open aarifIg opened 8 years ago

aarifIg commented 8 years ago

I have an entry in messages.properties with arguments like: user.login.success={0}, you have logged in.

how will i use it in java script.

benjaminartz commented 8 years ago

I agree this should be built in, but here's what I did to get around it... After the generated code is loaded, anywhere in javascript... (function (win) { win.$oldL = $L; win.$L = function (options) { var retVal = $oldL(options.code); if (options.params) { for (var i = 0; i < options.params.length; i++) { var re = new RegExp("\\{" + i + "\\}","g"); retVal = retVal.replace(re, options.params[i]); } } return retVal; } }(this));

Then you just use it like... $L({code: 'your.message.code', params: ['optional', 'params']});