4

translate

translate
SYNOPSIS

translate($s, $lang)

DESCRIPTION

translate returns the translation of $s in $lang or false in case of failure.

The strings which are translated are defined in the file includes/strings.inc:

  1. includes
    1. strings.inc

An optional parameter allows to specify another translation table.

  1. global $strings;
  2.  
  3. $strings = array(
  4.     array(
  5.     ),
  1.     'en' => array(
  2.         'description'           => '',
  3.         'keywords'              => 'iZend',
  4.         'http_bad_request:title'            => 'Bad Request',
  5.         'http_forbidden:title'              => 'Forbidden',
  1.     'fr' => array(
  2.         'description'           => '',
  3.         'keywords'              => 'iZend',
  4.         'http_bad_request:title'            => 'Mauvaise requĂȘte',
  5.         'http_forbidden:title'              => 'Interdit',

strings.inc defines the global variable $strings. $strings holds a table which associates for each language managed by the program a list of character strings and their translations. The array of strings which are not language dependent is placed at position 0.

CODE
  1. global $strings;
  2.  
  3. $strings = array();
  4.  
  5. @include 'strings.inc';

Loads the global variable $strings from the file strings.inc.

  1. function translate($s, $lang, $from=false) {
  2.     global $strings;
  3.  
  4.     $stab=$from ? $from : $strings;
  5.  
  6.     if ($s) {
  7.         if ($lang && array_key_exists($lang, $stab) && array_key_exists($s, $stab[$lang])) {
  8.             return $stab[$lang][$s];
  9.         }
  10.         if (array_key_exists(0, $stab) && array_key_exists($s, $stab[0])) {
  11.             return $stab[0][$s];
  12.         }
  13.     }
  14.  
  15.     return false;
  16. }
SEE ALSO

engine

Comments

To add a comment, click here.