Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
class I18N_Messages_File extends I18N_Messages_Common
45
{
46
 
47
    // {{ properties
48
 
49
    /**
50
    * Holds directory information
51
    *
52
    * @type  : string        Directory name
53
    * @access: private
54
    */
55
    var $_dir;
56
 
57
    // }}
58
    // {{ constructor
59
 
60
    /**
61
    * Save Lanuguage and the directory name where language file resides.
62
    * Then load the file.
63
    *
64
    * @param : string          Lanuguage Code
65
    * @param : string          Directory Name
66
    *
67
    * @return: void
68
    * @access: public
69
    */
70
    function __construct($lang = 'en', $domain = '',$dir = './')
71
    {
72
        parent::__construct();
73
        $this->setDir($dir);
74
        $this->bindLanguage($lang);
75
        $this->bindDomain($domain);
76
        $this->_load();
77
    }
78
 
79
    // }}
80
    // {{ I18N_Messages_File()
81
 
82
    /**
83
    * For pre-Zend2 compatibility. Call actual constructor
84
    *
85
    * @param : string          Lanuguage Code
86
    * @param : string          Directory Name
87
    *
88
    * @return: void
89
    * @access: public
90
    */
91
    function I18N_Messages_File($lang = 'en', $domain = '', $dir = './')
92
    {
93
        $this->__construct($lang,$domain,$dir);
94
    }
95
 
96
    /**
97
    * Load the lanuguage file
98
    *
99
    * @param : string      Language code
100
    *
101
    * @return: void
102
    * @access: private
103
    */
104
    function _load()
105
    {
106
        include_once $this->getDir().$this->bindLanguage().'/'.$this->bindDomain().'.php';
107
    }
108
 
109
    /**
110
    * Set directory
111
    *
112
    * @return: string     Directory name
113
    * @access: public
114
    */
115
    function setDir($dir)
116
    {
117
        $this->_dir = $dir;
118
    }
119
 
120
    /**
121
    * Return directory name
122
    *
123
    * @return: string     Directory name
124
    * @access: public
125
    */
126
    function getDir()
127
    {
128
        return $this->_dir;
129
    }
130
 
131
    function get($messageID)
132
    {
133
        // make sure it's loaded. for just after bindDomain() or bindLanuguage() method is called.
134
        $this->_load();
135
        return ($messageID !== "" && is_array($this->_message) && in_array($messageID, array_keys($this->_message))) ? $this->_message[$messageID] :$messageID;
136
    }
137
}
138
?>