PHP Classes

PHP Language Change: Change application language using arrays of text

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 97 All time: 9,853 This week: 560Up
Version License PHP version Categories
language-change 1.0Freeware5Localization, PHP 5
Description 

Author

This is a simple class that can change application language using arrays of text.

It can check if a cookie is set to determine the current language to be used for the texts in a site. If the cookie is not set, the class redirects the current request to access a script that sets the language cookie.

When the language cookie is set the class can load a script that defines an array with texts for the application to use in the language that was set.

In Spanish:

Este script puede cambiar el idioma de algunas palabras de tu pagina en tomando como parametro el valor de una cookie. Devuelve un array con las palabras en el idioma preferido.

Picture of Dannel
  Performance   Level  
Name: Dannel <contact>
Classes: 9 packages by
Country: Cuba Cuba
Innovation award
Innovation award
Nominee: 5x

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Example</title>
  <style>
  a{
    text-decoration: none;
    color: white;
  }


  span.menu{
    top: 0;
    left: 0;
    position: fixed;
    height:100px;
    width: 100%;
    background-color: #666666;
    color: white;
    display: inline-block;
     text-align: center;
  }
   span.option{
     font-size: 2em;
     display: inline;
     margin: 5px;
   }
   span.option:hover{
     background-color: #8D8D8D;
     cursor: pointer;
   }


  </style>
</head>

<body>
<?php include 'src/langclass.php'; $obj= new lang;?>

<span class="menu">

<span class="option">
<a><?=$obj->setLang()['home']?></a>
</span>
<span class="option">
<?php if($_COOKIE['lang']=='esp'){$l='eng';}else{$l='esp';} ?>
<a href="language.change.php?lang=<?=$l?>"><?=$obj->setLang()['lang']?></a>
</span>
<span class="option">
<a><?=$obj->setLang()['edit']?> </a>
</span>
<span class="option">
<a><?=$obj->setLang()['leave']?></a>
</span>
<span class="option">
<a><?=$obj->setLang()['help']?></a>
</span>
<h2 align="center"><?=$obj->setLang()['welcome']?></h2>
</span>
        <p style="padding-top:110px;">The rest of the page. . .</p>
</body>

</html>


  Files folder image Files (6)  
File Role Description
Files folder imagesrc (3 files)
Accessible without login Plain text file example.php Example Main example
Accessible without login Plain text file language.change.php Aux. Lang script to change cookie
Accessible without login Plain text file language.set.php Aux. Lang script to set the cookie

  Files folder image Files (6)  /  src  
File Role Description
  Accessible without login Plain text file arrayeng.php Conf. Array include
  Accessible without login Plain text file arrayesp.php Conf. Array include
  Plain text file langclass.php Class Class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:97
This week:0
All time:9,853
This week:560Up
User Comments (1)
sorry but is no longer abel now.
5 years ago (Viktor)
35%StarStar