问题
I am using French and English in my website. I have two links like "Française | English" and when user selects "Française" i place the following in header
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<meta content="fr" http-equiv="Content-Language">
and when user selects "English" i place the following in header to show respective languages
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="en" http-equiv="Content-Language">
The problem is when i switch to English from french, the links "Française | English" becomes like "Fran�aise | English".What i am doing wrong? any suggestions?
Thanks
回答1:
It sounds like you are still using UTF-8 (modern standard for encoding text) and not using ISO-8859-1 (legacy standard for encoding text that you shouldn't use any more) for the French documents.
Since you claim you are using ISO-8859-1, the browser then tries to interpret the document as using that encoding and gets some unprintable characters. The solution is to claim UTF-8 everywhere.
Since UTF-8 contains everything (and more) that is in ISO-8859-1 it wouldn't make sense to change anyway.
As an aside, Content-Language only specifies the intended audience for a document. To specify that a document really is written in French you should:
<html lang="fr">
And then you should specify that the links are in a different language, and point to alternative versions of the same document in a different language:
<ul>
<li><a href="/fr/" lang="fr" hreflang="fr" rel="alternate">Française</a></li>
<li><a href="/en/" lang="en" hreflang="en" rel="alternate">English</a></li>
</ul>
回答2:
the language attribute tells search engines what natural language the website is written in (e.g. English, Spanish or French http://www.nowgoal.com/), as opposed to the coding language (e.g. HTML). It is normally an IETF language tag for the language name. It is of most use when a website is written in multiple languages and can be included on each page to tell search engines in which language a particular page is written
回答3:
Use charset=utf-8 for both languages and make sure your source files are in UTF-8.
回答4:
UTF-8 is the only encoding you should be using, and it is the only encoding specifically encouraged for use in HTML5. UTF-8 can support any combination of human languages within the same encoding if needed (e.g., a German document including some Hindi and Chinese characters, etc.) while the same is not true for virtually all other encodings (designed when memory/processing was in shorter supply such as ISO-8859-1).
Make sure that your text editor saves in UTF-8 Unicode (not UTF-16, etc.), and if it does not, make sure that the only characters you use are ASCII based and use numeric character references, entities, or JavaScript/CSS Unicode escape sequences as need be to represent non-ASCII characters. But nowadays any decent editor should support UTF-8.
来源:https://stackoverflow.com/questions/6058662/language-format-issue-meta-tag