Greasy Fork is available in English.

Discussioni » Sviluppo

Wrong text encoding of read local files

§
Pubblicato: 04/10/2020
Modificato: 04/10/2020

Hi,

As FileReader.readAsText(..., 'UTF-8'), as XHR return local content in forced singlebyte encoding, even for files saved in UTF-8, resulting in malformed words like "Meldinš", "bâtard" and similar.
I'd like to ask for a working method how to read local files in UTF8 the proper way. by setting concerned functions properly, or converting the charset ex-post, whatever works. Thanks for any ideas

wOxxOmMod
§
Pubblicato: 04/10/2020

Simply use fetch for example: fetch(url).then(r => r.text()).then(text => { console.log(text) })

§
Pubblicato: 05/10/2020

Fetch doesnot work for me on local files

wOxxOmMod
§
Pubblicato: 05/10/2020

Yep, I forgot about that.

Well, you can override the encoding in XHR:

var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.overrideMimeType('text/plain; charset=UTF-8');

Pubblica risposta

Accedi per pubblicare una risposta.