Source for file Ethna_I18N.php

Documentation is available at Ethna_I18N.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_I18N.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: Ethna_I18N.php 298 2006-07-19 05:22:39Z fujimoto $
  10.  */
  11.  
  12. // {{{ Ethna_I18N
  13. /**
  14.  *  i18n関連の処理を行うクラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. class Ethna_I18N
  21. {
  22.     /**#@+
  23.      *  @access private
  24.      */
  25.  
  26.     /** @var    bool    gettextフラグ */
  27.     var $have_gettext;
  28.  
  29.     /** @var    string  ロケールディレクトリ */
  30.     var $locale_dir;
  31.  
  32.     /** @var    string  アプリケーションID */
  33.     var $appid;
  34.  
  35.     /** @var    string  システム側エンコーディング */
  36.     var $systemencoding;
  37.  
  38.     /** @var    string  クライアント側エンコーディング */
  39.     var $clientencoding;
  40.  
  41.     /**#@-*/
  42.  
  43.     /**
  44.      *  Ethna_I18Nクラスのコンストラクタ
  45.      *
  46.      *  @access public
  47.      *  @param  string  $locale_dir ロケールディレクトリ
  48.      *  @param  string  $appid      アプリケーションID
  49.      */
  50.     function Ethna_I18N($locale_dir$appid)
  51.     {
  52.         $this->locale_dir $locale_dir;
  53.         $this->appid strtoupper($appid);
  54.         $this->have_gettext extension_loaded("gettext"true false;
  55.  
  56.         $this->setLanguage(LANG_JA);
  57.     }
  58.  
  59.     /**
  60.      *  ロケールを設定する
  61.      *
  62.      *  @access public
  63.      *  @param  string  $language       言語定義
  64.      *  @param  string  $systemencoding システムエンコーディング名
  65.      *  @param  string  $clientencoding クライアントエンコーディング名
  66.      *  @return string  言語に対応して設定されたロケール名
  67.      */
  68.     function setLanguage($language$systemencoding null$clientencoding null)
  69.     {
  70.         switch ($language{
  71.         case LANG_EN:
  72.             $locale "en_US";
  73.             break;
  74.         case LANG_JA:
  75.             $locale "ja_JP";
  76.             break;
  77.         default:
  78.             $locale "ja_JP";
  79.             break;
  80.         }
  81.         setlocale(LC_ALL$locale);
  82.         if ($this->have_gettext{
  83.             bindtextdomain($this->appid$this->locale_dir);
  84.             textdomain($this->appid);
  85.         }
  86.  
  87.         $this->systemencoding $systemencoding;
  88.         $this->clientencoding $clientencoding;
  89.  
  90.         return $locale;
  91.     }
  92.  
  93.     /**
  94.      *  メッセージカタログからロケールに適合するメッセージを取得する
  95.      *
  96.      *  @access public
  97.      *  @param  string  $message    メッセージ
  98.      *  @return string  ロケールに適合するメッセージ
  99.      */
  100.     function get($message)
  101.     {
  102.         if ($this->have_gettext{
  103.             return gettext($message);
  104.         else {
  105.             return $message;
  106.         }
  107.     }
  108. }
  109. // }}}
  110. ?>

Documentation generated on Thu, 08 May 2008 00:14:51 +0900 by phpDocumentor 1.4.2