Translation in javascript widget


I am working on JavaScript widget which has backend in Yii that returns the response in JSon.

My Widget is loaded using javascript which builds the forms,html and page content using js.

So How should i make translation in js file using Yii translation.

I am trying do as,

I will returns translation messages in json format in one variable from our /messages/en/widget.php as per language selected.


$.getJSON(baseurl + "/api/translations"&callback=?", function(data) {

        translations = data;


I will translate data from this json variable as,


Any Idea How should we do it better way?