mustapha mechken
mustapha mechken

Reputation: 11

Generating translation CSV file

I'm using ajax/javascript to generate a English to French translations csv file. The issue is that my CSV file contains strange characters.

I think that I have to change some options in Excel?

My generated CSV file: My generated CSV file

'February' should be 'Février' and 'Metal' should be 'Métal'

Thanks :)

Here is the function that I'm using

function exportToCsv(filename, rows) {
var processRow = function (row) {
    var finalVal = '';
    for (var j = 0; j < row.length; j++) {
        var innerValue = row[j] === null ? '' : row[j].toString();
        if (row[j] instanceof Date) {
            innerValue = row[j].toLocaleString();
        };
        var result = innerValue.replace(/"/g, '""');
        if (result.search(/("|,|\n)/g) >= 0)
            result = '"' + result + '"';
        if (j > 0)
            finalVal += ',';
        finalVal += result;
    }
    return finalVal + '\n';
};

var csvFile = '';
for (var i = 0; i < rows.length; i++) {
    csvFile += processRow(rows[i]);
}

var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' });
if (navigator.msSaveBlob) { // IE 10+
    navigator.msSaveBlob(blob, filename);
} else {
    var link = document.createElement("a");
    if (link.download !== undefined) { // feature detection
        // Browsers that support HTML5 download attribute
        var url = URL.createObjectURL(blob);
        link.setAttribute("href", url);
        link.setAttribute("download", filename);
        link.style.visibility = 'hidden';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }
}
}

Upvotes: 1

Views: 1291

Answers (2)

mustapha mechken
mustapha mechken

Reputation: 11

This works for all languages that I tested! Open google docs, File, Open, chose Upload Tab and drag and drop your CSV file

Upvotes: 0

Laurens Deprost
Laurens Deprost

Reputation: 1691

This is an issue Excel has been having for ages.
What you can do is open import/paste the sheet in Google Sheets and then export as CSV.
Another option if you're on Windows is opening the sheet in Notepad and choose File -> Save As and select ANSI encoding.

Upvotes: 1

Related Questions