7777 66

For example, when a page starts with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

is it possible to detect what language the page is written in using the doctype or some other method? And if so, what language would I use?


2 answers


The language code in the doctype is to show what language the dtd is written in (usually EN for English). For the language of the page you would probably look for a language attribute in the html tag:

<html lang="en">

possible attributes and explanations:


Answered almost 10 years ago by Tony Crockford
  • Thanks, I'm interested in trying to pull the language that an html document is in because I'm trying to write a script that will a) pull the language, b) pull the current URL (I'm currently doing this with PHP), and c) feed it to a translate engine, such as Google Translate. Would I have to deal with the language attribute through PHP as well? 7777 almost 10 years ago
  • Where are the documents? locally? or are you getting them from the web? have you looked at the google translate API - that seems to do the get text, see what language it is, translate it, all on the fly using Javascript. http://code.google.com/apis/ajaxlanguage/ Tony Crockford almost 10 years ago
  • I'm trying to include it as part of a Wordpress theme I'm developing. I've looked through the source code, but it doesn't look like WP includes that in the html tags. So the Google API is probably a good place for me to start looking for solutions, thanks :-) 7777 almost 10 years ago
  • Oh I should also add that I'm hoping to find a solution that doesn't involve AJAX/Javascript but I'm not sure if there is one yet. 7777 almost 10 years ago

WP does output doctypes. Look in page source, not php source.

Look at Wordpress plugins for ways to work with Google on langauge translations.

Answered almost 10 years ago by songdogtech