Jump to content

Czech Text


Recommended Posts

Czech this out:I've got a page that shows a bunch of database text, and when the text comes out of the database it goes through a UTF-8 encoding algorithm (which I can't guarantee is correct) before being sent to the browser. This happens during an AJAX request. This is the encode/decode algorithm, in java script:

//+ Jonas Raoni Soares Silva//@ http://jsfromhell.com/geral/utf-8 [rev. #1]UTF8 = {	encode: function(s){		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]		);		return s.join("");	},	decode: function(s){		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;			((a = s[i][c](0)) & 0x80) &&			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")		);		return s.join("");	}};

All string values get encoded before output. Much of it is working fine, it shows text on the page such as this:

On screen: C"Poskytnutí príležitostí variabilite" --> "Poskytnutí príležitostí zamesnancum"narration text:"jedné z hybných sil" --> "jeden z Enablers"On screen:"3 Hybné síly" --> "Enablers"narration text:"s ostatními hybnými silami" --> "s ostatními Enablers"
That gets displayed in the browser correctly, even though the AJAX response shows up like this in Firebug:
narration text:\n\n\"jedné z hybných sil\" --> \"jeden z Enablers\"\n\nOn screen:\n\"3 Hybné síly\" --> \"Enablers\"\n\nnarration text:\n\"s ostatními hybnými silami\" --> \"s ostatními Enablers\"

There is a single piece of text from the database that isn't coming through correctly. On the page it gets displayed like this:

The AJAX response looks like this (note the \u sequences):
On Screen\"\n\"POUŽÃ\u008dVAJÃ\u008d SE HYBNÃ\u0089 SÃ\u008dLY\" --> \"POUŽÃ\u008dVAJÃ\u008d SE ENABLERS\"

The text actually stored in the database is:

So the capital accented I and E characters seem to be causing problems, but I'm not sure why, and I'm not sure why the AJAX response for that chunk of text contains the \u escape sequences that none of the other responses have.Where is this going wrong?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...