PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Konstantin S. Budylov   phpMultiLang   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example for using
Class: phpMultiLang
Retrieve internationalized texts from data files
Author: By
Last change: Example is updated
Date: 19 years ago
Size: 3,048 bytes
 

Contents

Class file image Download
<?php
/**************************************************************************

    class phpMultiLang version 2.0 example script

***************************************************************************/
require "class.phpMultiLang.php";
require
"functions.inc.php";

$Lang = new phpMultiLang("langs","");
           
/*Set a root directory for language files,
             and directory for cache*/


/*Assign languages with locale configurations*/
   
$Lang -> AssignLanguage('ru',null,array("LC_ALL","ru"));
   
$Lang -> AssignLanguage('en',null,array("LC_ALL","en"));



  
// Adding the language data.

  //files
  
$Lang -> AssignLanguageSource('ru','ru.lang',3600);
  
$Lang -> AssignLanguageSource('en','en.lang',3600);


  
//or arrays, (keys will be indexes, and values - strings)

  
$Lang -> AssignLanguageSource('ru',array("string1"=>"Какая-то строка"));
  
$Lang -> AssignLanguageSource('en',array("string1"=>"Some string"));

  
$Lang -> AssignLanguageSource('ru',array("string2"=>"Строка с %s модификаторами %s"));
  
$Lang -> AssignLanguageSource('en',array("string2"=>"String with %s modifiers %s"));

  
$Lang -> AssignLanguageSource('ru',array("select_lang"=>"Select language"));
  
$Lang -> AssignLanguageSource('en',array("select_lang"=>"Выберите язык"));
  
//Selecting language
  
if(!isset($_GET['lang']))$lang = "ru";
   else
$lang = $_GET['lang'];
  
//At last, we have found out, what language we shall use
   //It also we initialize
  
$Lang -> SetLanguage($lang,TRUE); //If second argument is true - the caching wil be enabled for current language
  
$Lang -> AssignLanguageSource('ru',array("current_locale"=>"Текущая установленная локаль: %s%s%s."));
  
$Lang -> AssignLanguageSource('en',array("current_locale"=>"The current locale is: %s%s%s"));

 
?>
<form>
<?=$Lang->GetString("select_lang")?>:
<select name="lang">
<option value='ru'<?if($Lang->GetLanguage()=="en") echo "selected";?>>Русский</option>
<option value='en' <?if($Lang->GetLanguage()=="ru") echo "selected";?>>English</option>
</select><br>
<input type=submit value="select">
</form>
<hr>
<?
  
//Out!
  
echo $Lang -> GetString("string1")."<br>";
   echo
$Lang -> GetString("string2")."<br>";

  
//format string
  
echo $Lang -> GetFString("string2",array("<font color='red'>","</font>"))."<br>";

   echo
$Lang -> GetString("filestring1")."<br>";
   echo
$Lang -> GetString("filestring2")."<br>";
   echo
$Lang -> GetString("filestring3")."<br>";
   echo
$Lang -> GetString("filestring4")."<br>";



  
//Nice feature - we receive the reference to a string on it's index.
  
$d =&$Lang->GetStringReference('string1');

  
//And now with this line it is possible to make all, everything
  
$d = "Changed string";

  
//Look:
  
echo $Lang->GetString("string1")."<br><br>";
   echo
$Lang->GetFString("current_locale",array("<i>",$Lang->GetLocale(),"</i>"));
echo
"<hr><a href='docs/doc_".$Lang -> GetLanguage().".html'>".$Lang->GetString('docs')."</a>";
?>