views:

113

answers:

2

I'm trying to write a website in Slovak language (central Europe). What I have done is put these two meta tags into the header:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="Content-Language" content="sk" />

The problem is all characters with diacritique are substituted with garbage characters (so the encoding I not working obviously). What to do?

Here is the whole beginning of the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk">
<head>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Language" content="sk" />
+5  A: 

There are two issues at work here.

  1. Language
  2. Character encoding

Language

The Content-Language HTTP header describes the natural language of the intended audience. This may not be the same as the language the document is actually written in. Use the lang attribute to describe that.

Character encoding

This allows you to represent the letters that you wish to use. You need to make sure that your text really does use the selected encoding and that the browser is informed that that is the encoding you are using.

HTTP headers

NB: Your question mentions <meta http-equiv>. Real HTTP headers are the better place to specify this information, and they will override whatever your document claims. Make sure your server is configured correctly.

XHTML

XHTML complicates matters…

David Dorward
@David. My content negotiating website might, under certain conditions, violate your last XHTML point. Can you explain why the XML declaration is necessary here, and the HTTP header is insufficient? Is it just for non-browser XML processors?
Alohci
If you don't use UTF-8 (or UTF-16) then the specification requires it. The XML may be saved and accessed from a local data store. Somebody trying to debug the page may look at the source and assume UTF-8/16.
David Dorward
OK, thanks. Both the XML and XHTML specs allow the character encoding to be specified by "a higher level" protocol, so the only difference for XHTML here is that the meta http-equiv can't be used to establish the character encoding, because it's neither XML nor a higher level protocol. Right? So long as I don't need to support store-and-inspect I should be OK, I think.
Alohci
+4  A: 

When you save the file you have to make sure that it's created with the same encoding that you have specified in the meta tag.

I recommend that you use utf-8 instead of iso-8859-2. The unicode character set supports all characters in practically every language that exists (and even some that don't...).

Guffa
If I use UTF-8 encoding, it works. But won't it work with iso-8859-2 which is a character encoding made especially for central European languages?
Richard Knop
@Richard: If your computer is using that character set natively, you could save the file as ANSI, and it would work. You could also use HTML entities for the character codes for all non-ASCII characters, like ö for the ö character.
Guffa