PHP Classes

Add multiple languages to a Web: Add multiple languages to a Web site very easy.

Recommend this page to a friend!
  Info   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 63%Total: 4,315 All time: 678 This week: 96Up
Version License PHP version Categories
addmultiplelanguajes 1.1MIT/X Consortium ...4Localization, HTTP


This class allows to implement multiple languages to a Web site developed in PHP Language.

Language class detects language browser automatically and display the Web site content in the correct language, or in a default language, also allows to implement a system to change the language.

It checks the HTTP request User-Agent and Accept-Language headers to determine the user preferred language.

The class can also load PHP scripts with locale text definitions for the user preferred language. These locale definitions are returned as an associative array.

Picture of Deyby Vasquez
Name: Deyby Vasquez <contact>
Classes: 1 package by
Country: Colombia Colombia
Age: ???
All time rank: 6996 in Colombia Colombia
Week rank: 371 Up3 in Colombia Colombia Up


Need a class or function which convert my website language
english to urdu text converter

Please Give this class
I want to make translator in my website


************************************************************************************************************** * * * Class name: class.Language.php * * Author: Deyby Vasquez * * E-mail: * * Version: 1.0 * * Licence: MIT Licence * * Web site: * * * ************************************************************************************************************** ************************************************************************************************************** WHAT DOES class.Language.php DO? ************************************************************************************************************** Allows to implement multiple languages in a Web site developed in PHP language. This class detects the visiting client language and displays the content in the correct language, if the language is not supported it displays the content in a default language. It's easy to implement a selecting language system e.g. a form, in order that users can select the language. Just configure the languages into an associative array file. ************************************************************************************************************** INSTALLATION ************************************************************************************************************** 1. Unzip the files and upload the unziped files to the root directory. 2. That's it just test it e.g: http://localhost/nameOfUnzippedFile or http://yourdomain/nameOfUnzippedFile ************************************************************************************************************** CREATING YOUR OWN PAGES FROM 0 ************************************************************************************************************** 1. Unzip the files and upload the class.language.php file to the root directory. 2. Create the associative array with the content to the page for each language you require e.g: <?php /* English language configuration */ $lang = array ( /* title page */ 'title' => "Example page in english", /* Content items */ 'welcome' => "Hello world", 'language' => "The language page is in English", 'en' => "English", 'es' => "Spanish", 'fr' => "French", ); ?> 3. Save it with two language first letters and conf extension e.g. en.conf into a languages directory. 4. Set a default language variable e.g $DEFAULT_LANGUAGE = 'en'; and languages directory path e.g $LANGUAGE_DIR = '../languages'; into a configuration file or in the pages. 5. Include the class in the pages that you're going to display multiple languages e.g: require_once ("class.languages.php"); 6. instantiating the class and apply the getLanguage method e.g: $language = new Language(); $lang = $language->getLanguage(@$_POST['lang']); 7. That's it just you have to display the content in your pages e.g: echo $lang['welcome']; *************************************************************************************************************** CREATING SELECTING SYSTEM (Optional) FROM 0 *************************************************************************************************************** 1. Create a system e.g: A form <form name="language" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select onchange = "document.language.submit()" name="lang"> <option selected="selected"><?php echo $lang['select-language']; ?></option> <option value="en"><?php echo $lang['en']; ?></option> <option value="es"><?php echo $lang['es']; ?></option> <option value="fr"><?php echo $lang['fr']; ?></option> </select> </form> 2. You can use both methods POST or GET. 3. Be assure to set a variable name for the select item of the form e.g: <select onchange = "document.language.submit()" name="lang"> 4. The parameter that you pass to getLanguage method varies depending on method form e.g: If you use method="post" set $lang = $language->getLanguage(@$_POST['lang']); If you use method="get" set $lang = $language->getLanguage(@$_GET['lang']); 5. That's it ...! *************************************************************************************************************** MORE EXAMPLES *************************************************************************************************************** class.Language.php with Smarty you can access to a Spanish video and you can download the example code for free from: class.Language.php using a selecting language system, Spanish video and example code from: class.Language.php simple configuration, Spanish video and example code from: *************************************************************************************************************** NOTE *************************************************************************************************************** All examples acompaning this class must be uploaded to the root directory. *************************************************************************************************************** THANKS FOR USING IT ***************************************************************************************************************

  Files folder image Files  
File Role Description
Files folder imagelanguages (3 files)
Plain text file class.Language.php Class Language class
Accessible without login Plain text file index.conf Example file configuration
Accessible without login Plain text file readme Doc. How to use
Accessible without login Plain text file index.php Example Main page
Accessible without login Plain text file page2.php Example page two

  Files folder image Files  /  languages  
File Role Description
  Accessible without login Plain text file en.conf Example english locale file
  Accessible without login Plain text file es.conf Example Spanish locale file
  Accessible without login Plain text file fr.conf Example French locale file example

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:678
This week:96Up
User Ratings User Comments (1)
 All time