PDA

View Full Version : Accented chars issue (Portoguese words)



Fabrizio.ExDev
2 Mar 2015, 1:05 AM
Hi to everyone!
I'm encountering some troubles while trying to display accented chars.
Chars like '' and '' are displayed as shown in the following picture:
51856

In my index.html page, I've placed this line but nothing's changed:


<meta charset="UTF-8">

Could you please help me?
Thanks to all.

yeghikyan
2 Mar 2015, 1:15 AM
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
I think it is not extjs issue.

Fabrizio.ExDev
2 Mar 2015, 1:32 AM
Hello, thanks for your answer.
In my index.html file, I've replaced

<meta charset="UTF-8">
with

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


...but nothing's changed.


Furthermore, I've tried to set '' as text of an HTML button and chars are correctly represented.
The same text isn't represented as expected in any ExtJs element. (Labels, buttons, grid's records, etc...).
Hope someone can help me,
Thanks again.

yeghikyan
2 Mar 2015, 3:40 AM
Are your index.html file and all the js files in utf-8 encoding?

Fabrizio.ExDev
2 Mar 2015, 11:28 PM
This is my index.html code:

<!DOCTYPE HTML><html manifest=""><head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="Content-type"content="text/html; charset=utf-8"/> <title>MyApp</title> <link rel="stylesheet" type="text/css" href="app/app.css"> <!-- The line below must be kept intact for Sencha Cmd to build your application --> <script id="microloader" type="text/javascript" src="bootstrap.js"></script></head><body></body></html>


Is there something wrong? The issue seems to be related to ExtJS-elements only, because the same chars, in HTML elements, are displayed correctly. Isn't there a way to change the Ext Framework encoding? Thanks.

yeghikyan
3 Mar 2015, 2:17 AM
AFIK extjs framework files already in utf8, what about your js files? Have you checked the encoding? what is the default encoding in your IDE? Are you using localisation/translation mechanisms?

Fabrizio.ExDev
3 Mar 2015, 2:53 AM
At the moment, I'm not using localization/translation mechanisms.I've tried editing a value from console as here:

myStore.data.items[0].set('text','');
And chars are correctly displayed (the other records of the same store still contain unknown chars).Records are returned by an Ajax call.What could it be?

Here is the call's header:
51866

yeghikyan
3 Mar 2015, 3:03 AM
so, the problem is not in extjs, what about serverside scripts or DB? :)You can alway generate simple html instead of the json and check if the encoding correct :)

yeghikyan
3 Mar 2015, 3:04 AM
there are also plugins for browsers, which represent returned JSON in human readable format, they can be useful.

yeghikyan
3 Mar 2015, 3:07 AM
you can also save the json in file with curl and get encoding with 'file' command...

Fabrizio.ExDev
3 Mar 2015, 3:31 AM
This is the returned json:
51867

As you can see, chars are correctly displayed in browser's preview.
I'm not skilled about encoding etc.. :(
What could be the cause?

yeghikyan
3 Mar 2015, 3:48 AM
Copy-paste the output to simplest editor, save it in file, then use "file " and get the encoding of the content. If it is not utf-8, ask backend developers to fix it... or open the file in new tab somehow and guck the encoding there.

yeghikyan
3 Mar 2015, 3:49 AM
the couse is in 99.9% your backend. You can also ask backend guys to check the output...

skirtle
3 Mar 2015, 2:42 PM
I'm not skilled about encoding etc.. :(

This seems like a good time to learn. I'd start here:

http://www.joelonsoftware.com/articles/Unicode.html

Then try the following:

Open up a text editor and create a file that just contains the two characters .
Save the file as UTF-8. Most text editors will let you choose this. If your doesn't, try another one.
Save it again but this time use a different encoding. Something ANSI or ISO, whatever makes sense. Personally I used ISO-8859-15.
Find yourself a utility that can give you a hex dump of the bytes in each file. I used a Unix/Linux tool called hexdump.
The UTF-8 file should contain the 4 bytes 'a3 c3 a7 c3', plus any junk your text editor felt the need to include. The ISO version will be something like 'e7 e3', just 2 bytes for the two characters.


Armed with this knowledge of what different encodings look like in hex you can then attack your server response.

Chrome has a 'Copy as cURL' option if you right-click on a request in the Network tab. Use that to pump your response into a file. Then attack it with your new knowledge of hex dumps and figure out what encoding the server is returning.

An alternative to using cURL would be a network monitoring tool like Ethereal, which also allows you to see the raw bytes without a separate hex dump tool.

The most likely problem is that the response is in an ISO-* encoding rather than UTF-8.

The screenshot showing the correct characters is the only thing that suggests the problem may lie elsewhere. However, it's possible that this is the result of the developer tools using a different encoding detection algorithm and correctly deducing the actual encoding of the response, whereas the JavaScript Ajax responseText may still be incorrect. These algorithms are only necessary because your response headers don't explicitly state the character encoding being used.

Fabrizio.ExDev
3 Mar 2015, 11:56 PM
Thanks to both for suggestions!I'll do as suggested.