LinuxReviws.org --get your your Linux knowledge
> Linux Reviews > Howtos >

How to get web pages serviced in your native language

Common web servers are able to serve different pages depending on what languages the visitor understands. You can easily configure what languages you understand in your browser to get web pages default you your native tung when available.


  1. How to set your browsers language settings
  2. How to serve content based on visitors language settings


There is so far only a hand-full of sites that use the automatic language selection features found in modern browsers and web servers. But it is quite possible, and easy, to show different pages based on the users language preferences.

1. How to set your browsers language settings

1.1. Epiphany

In the menu, select Edit -> Preferences. Click the tab Language. Click More... if you want to add more than one language sorted by preference.

Epiphanys language in menus and choices follows the system variable LC_ALL. (LC_ALL=no_NO for Norwegian).

1.2. Konqueror / KDE

Konqueror uses the language set for KDE in KDE Control Center. To change language in KDE:

From KDEs menu, go:

K -> Settings -> Control Center.

or run the command kcontrol.

Now select Country/Region & Language and where you can Add Language(s) you want. The first (top) language you select is used in KDE, the other languages prioritize what language to use on websites supporting multiple languages when your first choice is unavailable.

1.3. Mozilla 1.x

Choose

Edit -> Preferences,

from the menu and then

Navigator -> Languages

to select preferred page language in Mozilla 1.x.

1.4. Mozilla Firefox

Go to the address (in the location bar)

about:config

And find

intl.accept_languages

Click on it so you get a dialog box open and enter the preferred languages (no, nb, nn, en-us, en).

0.9.1+ Edit -> Preferences -> General -> Languages

1.5. Opera

File -> Preferences (alt-p) -> Languages -> Add...

Here you can select the languages you want supported when viewing websites.

You can choose what language Opera itself should use from the same menu. Look for your language on this page if your distribution did not include language (.lng) files for Opera:

2. How to serve content based on visitors language settings

2.1. Apache

You need to edit the apache configuration file (commonapache2.conf / httpd.conf) and add language codes reflecting those used by browsers and file extensions.

Example:

  <IfModule mod_mime.c>
      AddLanguage nn .nn
      AddLanguage no .no
      AddLanguage nb .nb
      AddLanguage da .dk
      AddLanguage sv .se
   <IfModule mod_negotiation.c>
      LanguagePriority en no nb da sv en fr de
   </IfModule>
  </IfModule>

Now make a file index.html.no with content in Norwegian ("Nei takk, ikke fiskeboller"), something Swedish in index.html.se ("Ska leta upp en skön när jag somnade på en tjockmadrass") and something for everyone in index.html.html ("u r 0wn3d"). Note that the default index / front page should be named index.html.html, this will not work if you call it index.html.

If a visitors browser has support for nb, Norsk Bokmål, Apache will look for and serve index.html.no. The awesome people in Sweden will view index.html.se and the rest of the world will experience index.html.html.

It is also possible to use ForceLanguagePriority and Prefer to make a rule so all visitors without support of any of the languages listed in your LanguagePriority get the first available language listed there instead of index.html.html.

   <IfModule mod_negotiation.c>
      ForceLanguagePriority Prefer Fallback
   </IfModule>

2.2. PHP

In php you can use $_SERVER['HTTP_ACCEPT_LANGUAGE'] to determine your visitors supported languages.

Example:

  <?php 
  
    $browserlang=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
      
    // Get preferred language
    if (strpos($browserlang, 'no') !== FALSE)
     $userlang='no';
    elseif (strpos($browserlang, 'nb') !== FALSE)
     $userlang='no';    
    elseif (strpos($browserlang, 'nn') !== FALSE)
     $userlang='no';    
    else
     $userlang='en'; 
  
      
    switch ( $userlang ) { 
     case no: 
       include("no.html"); 
       break; 
     case en: 
       include("en.html"); 
       break; 
      } 
  
  
  ?>

Meet new people