PHP Library for Langauge Detection and Translation
You could use a Php library to load language data from the client's browser and then modified the menu
options accordingly. See brief description of library use (follow the URL to find out more)
- The library can be found at: http://techpatterns.com/downloads/php_language_detection.php
- The library includes the function get_languages().
Calling get_languages( 'data' ); returns an array of all the client's selected browser languages. I pull the the basic language string from the first language on the list and use it to reference an array of pre-translated menu options. $langs = get_languages( 'data' ); $lang = $langs[0][3]; $menuHome = array("English"=>"Home", "Spanish"=>"Casa", "French"=>"Accueil"); $menuProducts = array("English"=>"Products", "Spanish"=>"Producto", "French"=>"Produit"); $menuCart = array("English"=>"Cart", "Spanish"=>"Carro", "French"=>"Chariot"); …
NOW you can print out the navigation links by printint out the corresponding language array element
<a href="index.php"><?php echo $menuHome[$lang]; ?></a> <a href="products.php"><?php echo $menuProducts[$lang]; ?></a> <a href="shoppingcart.php"><?php echo $menuCart[$lang]; ?></a>