3 * The language sub-system for handling language strings being used in the
4 * application and whole framework
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage {
26 * The full-qualified base path for the language include files
28 private $basePath = "";
31 * The 2-char language code
33 private $langCode = "xx"; // This will later be overwritten!
36 * The array-object for all language strings
38 private $langStrings = null;
41 * An instance of this class
43 private static $thisInstance = null;
50 private final function __construct () {
51 // Call parent constructor
52 parent::constructor(__CLASS__);
54 // Set part description
55 $this->setPartDescr("Sprachsystem");
57 // Create unique ID number
58 $this->createUniqueID();
61 $this->removeNumberFormaters();
62 $this->removeSystemArray();
66 * Creates an instance of the class LanguageSystem and prepares it for usage
68 * @param $basePath The local base path for all language strings
69 * @return $langInstance An instance of LanguageSystem
70 * @throws LanguagePathIsEmptyException If the provided $basePath is empty
71 * @throws InvalidLanguagePathStringException If $basePath is no string
72 * @throws LanguagePathIsNoDirectoryException If $basePath is no
73 * directory or not found
74 * @throws LanguagePathReadProtectedException If $basePath is
77 public final static function createLanguageSystem ($basePath) {
79 $langInstance = new LanguageSystem();
81 // Is the base path valid?
82 if (empty($basePath)) {
83 // Language path is empty
84 throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
85 } elseif (!is_string($basePath)) {
87 throw new InvalidLanguagePathStringException(array($langInstance, $basePath), self::EXCEPTION_INVALID_STRING);
88 } elseif (!is_dir($basePath)) {
90 throw new LanguagePathIsNoDirectoryException(array($langInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
91 } elseif (!is_readable($basePath)) {
93 throw new LanguagePathReadProtectedException(array($langInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
97 $langInstance->setBasePath($basePath);
99 // Initialize the variable stack
100 $langInstance->initLanguageStrings();
102 // Set language code from default config
103 $langInstance->setLanguageCode($langInstance->getConfigInstance()->readConfig("default_lang"));
105 // Remember this instance
106 self::$thisInstance = $langInstance;
108 // Return the prepared instance
109 return $langInstance;
113 * Singleton getter for this instance
115 * @return $thisInstance An instance of this class
117 public final static function getInstance () {
118 return self::$thisInstance;
122 * Initialize the array-object for all later language strings
126 public function initLanguageStrings () {
127 $this->langStrings = new FrameworkArrayObject();
131 * Setter for base path
133 * @param $basePath The local base path for all templates
136 public final function setBasePath ($basePath) {
138 $basePath = (string) $basePath;
141 $this->basePath = $basePath;
145 * Getter for language code
147 * @return $langCode The language code for the current application
149 public final function getLanguageCode () {
150 return $this->langCode;
154 * Setter for language code
156 * @param $langCode The language code for the current application
159 public final function setLanguageCode ($langCode) {
161 $langCode = (string) $langCode;
163 // And set it (only 2 chars)
164 $this->langCode = substr($langCode, 0, 2);