[ Team LiB ] |
Detecting the Browser's Preferred LocaleThe browser sends a number of header fields in each request indicating certain preferences. One of these preferences is a list of languages that the browser prefers for Web pages. The ACCEPT-LANGUAGE header value contains a list of languages that the browser is prepared to handle. Using this header value, you can locate a locale that you are prepared to support and deliver content targeted toward that locale. For example, suppose you have a Web site that is in both German and English. Although each version contains links to allow you to change languages at any time, you might want to default the user to the language his browser prefers. For example, if you see de-DE as the preferred language, you send the user to the German version of the page, and if you see en-US or en-UK, you send the user to the English version. Listing 22.1 shows a JSP that detects the preferred language sent by the browser and chooses one of two possible pages. Listing 22.1 Source Code for MyPage.jsp
Don't Expect Immediate Changes
Figure 22.1 shows the JSP when viewed from a browser with a preferred language setting of English (en/US), and Figure 22.2 shows the JSP viewed from a browser that prefers German (de/DE). Figure 22.1. You can create a multilingual Web site by detecting the preferred language.Figure 22.2. When you provide alternate language pages, include links to see the other language versions.Setting a Preferred Language
|
[ Team LiB ] |
No comments:
Post a Comment