|
|
Pr�t � lire
You are here: irt.org | Articles | Dynamic HTML (DHTML) | Pr�t � lire Published on: Saturday 2nd May 1998 By: Martin Webb
IntroductionHave you ever wanted to display a different page in another language for non-English visitors to your site? This article explains how, in Netscape Navigator 4 and Microsoft Internet Explorer 4, you can trap which language the visitors browser is using and then show them either a pre-translated version of your page. For Microsoft Internet Explorer 4 this article also shows how to use page transitions to disolve a document into the translated document. Why Prêt à lire? Well its a play on words: Prêt à Porter meaning Ready to Wear, Prêt à lire meaning Ready to Read. Trapping the browsers languageThe following JavaScript 1.2 code will check the value of the navigator objects language property in NN4 and the browserLanguage property in MSIE4:
As can be seen from the list of language values there are several subsets of each main language. To avoid too much work, we can restrict ourselves to the main set of languages by extracting the first two characters of the language variable using the substring() method. Redirecting the visitorThe following JavaScript code, detects the language as above, but then restricts the languages it supports to just French ('fr'), German ('de'), Italian ('it'), Spanish ('es') and Portuguese ('pt'). Any other languages found are ignored and English ('en') is used instead. The showpage() function accepts the language code and opens up a new window centered in the middle of the screen, with the required pre-translated document loaded, where the filenames of the pre-translated documents are msg-en.htm, msg-fr.hmtl, msg-de.htm, msg-it.htm, msg-es.htm and msg-pt.htm:
Special EffectsHow about displaying the page in English, and before the visitors eyes fading out the English version and fading in the translated version? Impossible? Not with Microsoft Internet Explorer 4 and page transitions. Placing the following META tags in the head of your documents you can fade in the document as it loads (page-Enter) and fade out the document as it unloads (page-Exit):
The revealTrans() procedure requires two parameters, Duration the number of seconds that the transition should last, and Transition the type of transition required, there are 23 types, type 12 being Random Dissolve. Now all we need is a mechanism to display the English document then after a small delay to display the translated document. The following JavaScript code will display the english.htm document in a centered popup window, but only if the browsers language is French, German, Spanish, Italian or Portuguese:
The english.htm document displays the English text, and then sets a timer using setTimeout() to load the required foreign language version after 5 seconds:
Working ExamplesWhy not try out the two working examples Redirecting the visitor and Special Effects - both of these working examples simulates a french browser. View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|