-1

I have simple German localization global object in my page:

GermanLocalization = {
    Required: "Alle Pflichtfelder müssen belegt werden.",
    AddAttacBeforeSave: "Datei kann nicht hochgeladen werden, bevor der Datensatz erstellt ist.",
    FileToBig: "Die Dateigröße überschreitet die maximale Uploadgröße."
}

When I read my variable in code all special German letter are read wrong, as a question mark (image below).

enter image description here

My index.html page has utf-8 encoding:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

My page is acctualy frame into the other page which succesfully shows German letter. I do not know what is it problem with my page, or JavaScript since debuger shows how my variable read those chars wrongly.

Milos
  • 1,678
  • 4
  • 23
  • 49
  • 1
    Did you try to open it in Notepad++, Encoding → Convert to UTF-8 en save the file ? – Cylexx Jul 28 '17 at 07:34
  • possible duplicate https://stackoverflow.com/questions/16658463/utf-8-characters-not-displaying-in-chrome – Val Jul 28 '17 at 07:34
  • Is the ` – Patrick Roberts Jul 28 '17 at 07:34
  • Simple question: is your file *actually* encoded in UTF-8…?! – deceze Jul 28 '17 at 07:40
  • I put it in Nodepad++ and everything is ok when I select Encode in UTF-8. I also did, Convert to UTF-8, and copy again in my script file. I still does not work. – Milos Jul 28 '17 at 07:49
  • I have this problem in all browsers, not just in chrome. – Milos Jul 28 '17 at 07:52
  • "Copy again"…? Step back: how exactly are you ensuring your actual source code file is saved as UTF-8? – deceze Jul 28 '17 at 07:53
  • It is simple js file created in VS 2015. I took text via google translate and put in my js file. Usually it works. – Milos Jul 28 '17 at 07:57
  • And VS 2015 saves the file as UTF-8?! – deceze Jul 28 '17 at 07:57
  • You were right. VS 2015 did not save js file as UTF-8, than as a ANSI. I need to open my JavaScript file in notepad++, convert to UTF-8, save again and it works. Put you comment as an answer how I can accept it. – Milos Jul 28 '17 at 08:04
  • There's gotta be a direct way to do this in VS, but I've never touched it, so can't give any advice there. – deceze Jul 28 '17 at 08:10

2 Answers2

3

If your JavaScript file is truly encoded as UTF-8, then this looks a classic case of UTF-8 being misinterpreted as another encoding, in this case by the JavaScript interpreter. Try specifying an encoding for your script, e.g. with:

<script src="myscripts.js" charset="UTF-8">
madscientist159
  • 550
  • 4
  • 12
  • 1
    is it still necessary to do this if `myscript.js` is served with `Content-Type: application/json; charset=utf-8` ? – Kos Jul 28 '17 at 07:36
  • @Kos no, but if that's already the case, then your script was not saved using UTF-8 and you'll need to change the encoding from whatever it's currently saved as. – Patrick Roberts Jul 28 '17 at 07:37
  • I would say a classic case of something being declared as UTF-8 not actually being UTF-8. – deceze Jul 28 '17 at 07:39
  • With the additional information given by OP, yes, that seems to be true. To the OP for next time, more detail in the question (how your script was instantiated, for instance) never hurts! – madscientist159 Jul 28 '17 at 07:40
  • It still does not work for me, even I put charset="UTF-8 to my script. Maybe it is a problem my variable goes to global scope and gets some other encoding. – Milos Jul 28 '17 at 07:42
1

Your file is not actually saved as UTF-8. Make sure your editor is configured to save it as UTF-8.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • You were right. VS 2015 did not save js file as UTF-8, than as a ANSI. I need to open my JavaScript file in notepad++, convert to UTF-8, save again and it works. – Milos Jul 28 '17 at 08:12