translate with parameters
mmaquevice opened this issue · 3 comments
Hey,
With angular-translate we can use parameters in our messages like $translate('i18n.key', {parameter: value}), however this is not yet possible with growl.
Is this feature in any backlog ? I can make a PR...
Thx
Hello,
Feel free to create a PR to implement the feature. Right now I do this:
this.$get = ["$rootScope", "$interpolate", "$filter", function ($rootScope, $interpolate, $filter) {
var translate;
try {
translate = $filter("translate");
} catch (e) {
//
}
function broadcastMessage(message) {
if (translate) {
message.text = translate(message.text, message.variables);
}
var polation = $interpolate(message.text);
message.text = polation(message.variables);
$rootScope.$broadcast("growlMessage", message);
}
I honestly never used the translate feature of Angular so improvements are more then welcome!
Thanks,
Actually your implementation works fine
growl.success('my.key', {variables: {var: value}});
I don't think an improvement about that is really required.
Thank you for your quick reply
This block of code should look like this instead:
if (translate) {
message.text = translate(message.text, message.variables);
} else {
var polation = $interpolate(message.text);
message.text = polation(message.variables);
}
If someone isn't using angular-translate and the $translate filter, then it should fall back to $interpolate - if they are then angular-translate will interpolate the variables already.