languages
[ class tree: languages ] [ index: languages ] [ all elements ]

Source for file Babelfish.php

Documentation is available at Babelfish.php

  1. <?php
  2. /**
  3.  * @package languages
  4.  * @version $Header$
  5.  *
  6.  *  Tiki is copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  7.  *  All Rights Reserved. See below for details and a complete list of authors.
  8.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  9.  *
  10.  *  This file copyright (c) 2002-2003, Ross Smith II
  11.  */
  12.  
  13. /**
  14.  * @package languages
  15.  */
  16. class Babelfish {
  17.     /**
  18.      *    Return the host name of the server
  19.      *
  20.      *    @todo move to BitBase class
  21.      */
  22.     function host({
  23.         if (isset($_SERVER['HTTP_HOST'])) {
  24.             // HTTP_HOST already includes a ':port' if it is used
  25.             return $_SERVER['HTTP_HOST'];
  26.         }
  27.  
  28.         if (!isset($_SERVER['SERVER_NAME'])) {
  29.             return false;
  30.         }
  31.  
  32.         $rv $_SERVER['SERVER_NAME'];
  33.  
  34.         if (!isset($_SERVER['SERVER_PORT'])) {
  35.             return $rv;
  36.         }
  37.         
  38.         if (isset($_SERVER['HTTPS']&& ($_SERVER['HTTPS'== 'on')) {
  39.             if ($_SERVER['SERVER_PORT'!= 443{
  40.                 $rv .= ':' $_SERVER['SERVER_PORT'];
  41.             }
  42.         else {
  43.             if ($_SERVER['SERVER_PORT'!= 80{
  44.                 $rv .= ':' $_SERVER['SERVER_PORT'];
  45.             }
  46.         }
  47.  
  48.         return $rv;
  49.     }
  50.     
  51.     /**
  52.      *    Return babelfish URL to translate \c $lang_from to \c $lang_to
  53.      *
  54.      * @param lang_from 
  55.      * @param lang_to 
  56.      */
  57.     function url($lang_from$lang_to{
  58.         static $url_map array(
  59.             'en'    => 'english',
  60.             'fr'    => 'french',
  61.             'de'    => 'german',
  62.             'it'    => 'italian',
  63.             'es'    => 'spanish',
  64.             'pt'    => 'portugese',
  65.         );
  66.  
  67.         $lang_from strtolower($lang_from);
  68.         $lang_to strtolower($lang_to);
  69.         
  70.         if (!isset($url_map[$lang_from])) {
  71.             return '';
  72.         }
  73.         
  74.         $url 'http://jump.altavista.com/translate_' $url_map[$lang_from'.go' .
  75.             '?http://babelfish.altavista.com/babelfish/tr?doit=done' .
  76.             '&amp;lp=' $lang_from '_' $lang_to .
  77.             '&amp;urltext=http';
  78.         if (isset($_SERVER['HTTPS']&& $_SERVER['HTTPS'== 'on'{
  79.             $url .= 's';
  80.         }
  81.         $url .= '://' Babelfish::host($_SERVER['REQUEST_URI'.
  82.             (strpos('?'$_SERVER['REQUEST_URI']'&amp;' '?'.
  83.             'babelfish=' $lang_from '_' $lang_to;
  84.  
  85.         return $url;
  86.     }
  87.  
  88.     /**
  89.      *    Return HTML of babelfish links
  90.      *
  91.      *    @param lang_from Language to translate from
  92.      */
  93.     function links($lang_from 'en'{
  94.         static $fishes array(
  95.             'en' => array(    # English
  96.                 'de' => '&Uuml;bersetzen&nbsp;Sie&nbsp;diese&nbsp;Seite&nbsp;ins&nbsp;Deutsche',
  97.                 'es' => 'Traduzca&nbsp;esta&nbsp;paginaci&oacute;n&nbsp;a&nbsp;espa&ntilde;ol',
  98.                 'fr' => 'Traduisez&nbsp;cette&nbsp;page&nbsp;en&nbsp;fran&ccedil;ais',
  99.                 'it' => 'Tradurre&nbsp;questa&nbsp;pagina&nbsp;in&nbsp;italiano',
  100.                 'pt' => 'Traduza&nbsp;esta&nbsp;p&aacute;gina&nbsp;em&nbsp;portugu&ecirc;ses',
  101.                 'zh' => '&#x7ffb;&#x8bd1;&#x8fd9;&#x9875;&#x6210;&#x6c49;&#x8bed;&nbsp;(CN)',
  102.                 'ja' => '&#x65e5;&#x672c;&#x8a9e;&#x306b;&#x3053;&#x306e;&#x30da;&#x30fc;&#x30b8;&#x3092;&#x7ffb;&#x8a33;&#x3057;&#x306a;&#x3055;&#x3044;&nbsp;(Nihongo)',
  103.                 'ko' => '&#xd55c;&#xad6d;&#xc778;&#xc73c;&#xb85c;&nbsp;&#xc774;&nbsp;&#xd398;&#xc774;&#xc9c0;&#xb97c;&nbsp;&#xbc88;&#xc5ed;&#xd558;&#xc2ed;&#xc2dc;&#xc694;&nbsp;(Hangul)',
  104.             ),
  105.             'fr' => array(    # French
  106.                 'de' => '&Uuml;bersetzen&nbsp;Sie&nbsp;diese&nbsp;Seite&nbsp;in&nbsp;Deutschen',
  107.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  108.             ),
  109.             'de' => array(    # German
  110.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  111.                 'fr' => 'Traduisez&nbsp;cette&nbsp;page&nbsp;en&nbsp;fran&ccedil;ais',
  112.             ),
  113.             'it' => array(    # Italian
  114.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  115.             ),
  116.             'es' => array(    # Spanish
  117.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  118.             ),
  119.             'pt' => array(    # Portugese
  120.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  121.             ),
  122.             'ru' => array(    # Russian
  123.                 'en' => 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;English',
  124.             ),
  125.         );
  126.  
  127.         // \todo Use phpsniff or PEAR's Net_UserAgent_Detect to detect the browser type
  128.         // as Netscape 4.x and possibly others displays '&#xabcd;' literally
  129. //        if (preg_match('/(mozilla\/4)/i', $_SERVER['HTTP_USER_AGENT'])) {
  130. //            $fishes['en']['zh'] = 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;Chinese&nbsp;(CN)';
  131. //            $fishes['en']['ja'] = 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;Japenese&nbsp;(Nihongo)';
  132. //            $fishes['en']['ko'] = 'Translate&nbsp;this&nbsp;page&nbsp;into&nbsp;Korean&nbsp;(Hangul)';
  133. //        }
  134.  
  135.         // If we have already translated this page (babelfish=en_fr), then don't display the strings again
  136.         if (!isset($fishes[$lang_from]|| isset($_GET['babelfish'])) {
  137.             return array();
  138.         }
  139.  
  140.         $a array();
  141.         foreach ($fishes[$lang_fromas $lang_to => $msg{
  142.             $a[array('target' => $lang_to,
  143.                          'href'   => Babelfish::url($lang_from$lang_to),
  144.                          'msg'    => $msg);
  145.         }
  146.  
  147.         return $a;
  148.     }
  149.  
  150.     /**
  151.      *    Return javascript code to display babelfish logo
  152.      *    
  153.      *    \static
  154.      */
  155.     function logo($lang 'en'{
  156.         static $s "<script language=\"JavaScript1.2\" src=\"http://www.altavista.com/r?%str\"></script>";
  157.  
  158.         $lang strtolower($lang);
  159.  
  160.         switch ($lang{
  161.             case 'en':
  162.             case 'de':
  163.             case 'fr':
  164.             case 'it':
  165.                 return sprintf($s$lang);
  166.             case 'es':
  167.                 return sprintf($s'esp');
  168.             case 'pt':
  169.                 return sprintf($s'port');
  170.         }
  171.  
  172.         return '';
  173.     }
  174.  
  175. }
  176.  
  177. ?>

Documentation generated on Wed, 29 Jul 2015 13:55:36 +0000 by phpDocumentor 1.5.0-lsces