16

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.         'payment_rejected:title'        => 'Payment rejected',
  2.         'donate:name'           => 'Donation to ' . $sitename,
  3.     ),
  4.     'fr' => array(
  5.         'description'           => '',

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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].