4.9 Is it possible to localize text in the browser? |
As with any good HTML browser, it is possible to read what language the WAP device is configured for, depending on whether it includes this in the HTTP headers it sends to the web server. Most devices do, so this variable can be read and text can be localized based on this. The HTTP header is called Accept-Language and contains one or more language identifiers separated by a comma. Each identifier is a two character code, based on ISO-639, for instance en for English, no for Norwegian and so on. For the full description of the Accept-Language header, see the HTTP 1.1 Reference, section 14.4. For a complete list of language codes, see this ISO-639 document. The following bit of PHP code shows the way to read the Accept-Language header and select the language. The code should be easy enough to convert to other script languages. The basic concept is to read the two first characters from the Accept-Language header and simply choose the language based on that.
<wml> <card id="loc" title="Localized Text"> <p> <? switch(substr($HTTP_ACCEPT_LANGUAGE,0,2)) { case "en": echo("Your WAP device is configured for English language"); break; case "no": echo("Din WAP-dings er konfigurert for Norsk spr�k"); break; case "sv": echo("Din WAP-sak �r konfigurerad f�r Svensk spr�k"); break; default: echo("I have no idea what language your WAP device is using.."); } ?> </p> </card> </wml> This and most other code examples in this FAQ is available as demo applications at DEMO |
[ Main ] [ 04 - Serving WML contents ] |
© Copyright The Wireless FAQ. All Rights Reserved. Terms | Site Map |