node-csv-parser return value to variable

I have the following function:

//translate strings
function translate(lng, str)
{
    var translation = '';
    csv().from(__dirname + '/../application/_common/lng/' + lng + '.csv', {delimiter: ';'})
    .transform( function(row, index) {
        if(row[0] == str) {
            return row[1];
        }
    })
    .on('data', function(data) {
        translation = data;
    })
    .on('end', function() { return translation; });
}

and I want to get the value found in the csv into a variable like this:

var translation = translate('en', 'translate_me');

The problem is that the function does not return anything!

Well, you don't return anything, you only return things from inner functions, but the outer function doesn't. If CSV is synchonous, do this:

function translate(lng, str)
{
    var translation = '';
    csv().from(__dirname + '/../application/_common/lng/' + lng + '.csv', {delimiter: ';'})
    .transform( function(row, index) {
        if(row[0] == str) {
            return row[1];
        }
    })
    .on('data', function(data) {
        translation = data;
    })
    .on('end', function() { return translation; });  // This just returns something from the inner function, which has no effect.
    return translation; // actually return the translation
}

If CSV is _asynchronous, it gets a little bit harder. Do this:

function translate(lng, str, callback) // Note the extra parameter
{
    var translation = '';
    csv().from(__dirname + '/../application/_common/lng/' + lng + '.csv', {delimiter: ';'})
    .transform( function(row, index) {
        if(row[0] == str) {
            return row[1];
        }
    })
    .on('data', function(data) {
        translation = data;
    })
    .on('end', function() { callback(translation); }); // call the callback
}

Now you would call it like this:

var translation;
translate('en', 'translate_me', function(val){ translation = val; });