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

Source for file File.php

Documentation is available at File.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Naoki Shima <naoki@avantexchange.com>                       |
  17. // |                                                                      |
  18. // +----------------------------------------------------------------------+
  19. //
  20. //  $Id:
  21. //
  22. require_once 'Common.php';
  23.  
  24. /**
  25. * Get message, and charset from php file, and return corresponding message
  26. * when get() is called.
  27. *
  28. * Full path to the file may look like this:
  29. *   /usr/local/apache/htdocs/lang/ja/general.php
  30. *   In this case, you can use I18N_Messages_File as follows:
  31. *     your script:
  32. *       $domain = 'general';
  33. *       $lang   = 'ja';
  34. *       $dir    = '/usr/local/apache/htdocs/lang/';
  35. *       require_once 'I18N/Messages/File.php';
  36. *       $i18n =& I18N_Messages_File($lang,$domain,$dir);
  37. *       $i18n->_('hello');
  38. *
  39. *     /usr/local/apache/htdocs/lang/ja/general.php:
  40. *       $this->setCharset('euc-jp'); // Set charset of this file
  41. *       $messages = array('hello' => 'Kon nichiwa'); // you can put more than one message in this.
  42. *       $this->set($messages); // or $this->set('Hello', 'Kon nichiwa');
  43. */
  44. {
  45.  
  46.     // {{ properties
  47.  
  48.     /**
  49.     * Holds directory information
  50.     *
  51.     * @type  : string        Directory name
  52.     * @access: private
  53.     */
  54.     var $_dir;
  55.  
  56.     // }}
  57.     // {{ constructor
  58.  
  59.     /**
  60.     * Save Lanuguage and the directory name where language file resides.
  61.     * Then load the file.
  62.     *
  63.     * @param string          Lanuguage Code
  64.     * @param string          Directory Name
  65.     *
  66.     * @return: void
  67.     * @access: public
  68.     */
  69.     function __construct($lang 'en'$domain '',$dir './')
  70.     {
  71.         parent::__construct();
  72.         $this->setDir($dir);
  73.         $this->bindLanguage($lang);
  74.         $this->bindDomain($domain);
  75.         $this->_load();
  76.     }
  77.  
  78.     // }}
  79.     // {{ I18N_Messages_File()
  80.  
  81.     /**
  82.     * For pre-Zend2 compatibility. Call actual constructor
  83.     *
  84.     * @param string          Lanuguage Code
  85.     * @param string          Directory Name
  86.     *
  87.     * @return: void
  88.     * @access: public
  89.     */
  90.     function I18N_Messages_File($lang 'en'$domain ''$dir './')
  91.     {
  92.         $this->__construct($lang,$domain,$dir);
  93.     }
  94.     
  95.     /**
  96.     * Load the lanuguage file
  97.     *
  98.     * @param string      Language code
  99.     *
  100.     * @return: void
  101.     * @access: private
  102.     */
  103.     function _load()
  104.     {
  105.         include_once $this->getDir().$this->bindLanguage().'/'.$this->bindDomain().'.php';
  106.     }
  107.  
  108.     /**
  109.     * Set directory
  110.     *
  111.     * @return: string     Directory name
  112.     * @access: public
  113.     */
  114.     function setDir($dir)
  115.     {
  116.         $this->_dir $dir;
  117.     }
  118.  
  119.     /**
  120.     * Return directory name
  121.     *
  122.     * @return: string     Directory name
  123.     * @access: public
  124.     */
  125.     function getDir()
  126.     {
  127.         return $this->_dir;
  128.     }
  129.  
  130.     function get($messageID)
  131.     {
  132.         // make sure it's loaded. for just after bindDomain() or bindLanuguage() method is called.
  133.         $this->_load();
  134.         return ($messageID !== "" && is_array($this->_message&& in_array($messageIDarray_keys($this->_message))) $this->_message[$messageID:$messageID;
  135.     }
  136. }
  137. ?>

Documentation generated on Mon, 11 Mar 2019 15:36:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.