2 /************************************************************************
3 * MXChange v0.2.1 Start: 08/25/2003 *
4 * =============== Last change: 11/29/2005 *
6 * -------------------------------------------------------------------- *
7 * File : language-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Language functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sprachfunktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // "Getter" for language strings
45 // @TODO Rewrite all language constants to this function.
46 function getMessage ($messageId) {
47 // Default is not found!
48 $return = '!' . $messageId . '!';
50 // Is the language string found?
51 if (isMessageIdValid($messageId)) {
52 // Language array element found in small_letters
53 $return = $GLOBALS['messages'][$messageId];
55 // Missing language constant
56 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Missing message string %s detected.", $messageId));
64 function initMessages () {
65 $GLOBALS['messages'] = array();
69 function addMessages ($messages) {
71 $GLOBALS['messages'] = merge_array($GLOBALS['messages'], $messages);
74 // Checks wether given message id is valid
75 function isMessageIdValid ($messageId) {
76 return (isset($GLOBALS['messages'][$messageId]));
79 // "Getter for current language
80 function getCurrentLanguage () {
81 return $GLOBALS['language'];
84 // "Getter" for language
85 function getLanguage () {
86 // Set default return value to default language from config
87 $ret = getConfig('DEFAULT_LANG');
92 // Is the variable set
93 if (isGetRequestElementSet('mx_lang')) {
94 // Accept only first 2 chars
95 $lang = substr(getRequestElement('mx_lang'), 0, 2);
96 } elseif (isset($GLOBALS['language'])) {
98 $ret = getCurrentLanguage();
99 } elseif (!empty($lang)) {
100 // Check if main language file does exist
101 if (isIncludeReadable('inc/language/' . $lang . '.php')) {
102 // Okay found, so let's update cookies
105 } elseif (isSessionVariableSet('mx_lang')) {
106 // Return stored value from cookie
107 $ret = getSession('mx_lang');
109 // Fixes a warning before the session has the mx_lang constant
110 if (empty($ret)) $ret = getConfig('DEFAULT_LANG');
114 $GLOBALS['language'] = $ret;
120 // "Setter" for language
121 function setLanguage ($lang) {
122 // Accept only first 2 chars!
123 $lang = substr(SQL_ESCAPE(secureString($lang)), 0, 2);
126 setSession('mx_lang', $lang);
129 // Checks wether a language file is there for optional extension
130 function isLanguageIncludeReadable ($ext_name = 'none') {
131 // Do we have array element?
132 if (!isset($GLOBALS['lang_inc'][$ext_name])) {
134 if ($ext_name == 'none') {
136 $languageInclude = sprintf("inc/language/%s.php", getLanguage());
138 // Extension's language file
139 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
142 // Look for file if no extension name is provided
143 $GLOBALS['lang_inc'][$ext_name] = isIncludeReadable($languageInclude);
144 //* DEBUG: */ print __FUNCTION__.':'.$ext_name.'='.$languageInclude.'='.intval(isIncludeReadable($languageInclude)).'<br />';
148 return $GLOBALS['lang_inc'][$ext_name];
151 // Load the current language file or fixes it to 'de'
152 // If ext_name is 'none', load general language support, else load extension's
153 // language file. In installation phase load the install language file.
154 function loadLanguageFile ($ext_name = 'none') {
155 // Try to get language from session
156 $currLanguage = getLanguage();
158 // Set default language if it is not (yet) set
159 if (is_null($currLanguage)) {
160 // Get it from config
161 $currLanguage = getConfig('DEFAULT_LANG');
163 // And save it in session
164 setLanguage($currLanguage);
167 // Do we have the language file NOT?
168 if (!isLanguageIncludeReadable($ext_name)) {
169 // Switch to default (DO NOT CHANGE!!!)
172 // And set it temporarily
173 setConfigEntry('DEFAULT_LANG', 'de');
176 // Is the file there?
177 if (isLanguageIncludeReadable($ext_name)) {
178 // Load language file
179 loadLanguageInclude($ext_name);
180 } elseif ((isDebugModeEnabled()) && (getOutputMode() == 0) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
181 // No language file is not so good...
182 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s, mode=%s",
189 // Check for installation mode
190 if ((isInstallationPhase()) || (!isAdminRegistered())) {
191 // Load language file
192 loadLanguageInclude('install');
196 // Loads the language file
197 function loadLanguageInclude ($ext_name = 'none') {
199 if ($ext_name == 'none') {
201 $languageInclude = sprintf("inc/language/%s.php", getLanguage());
203 // Extension's language file
204 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
207 // Check it before loading
208 if (isLanguageIncludeReadable($ext_name)) {
210 loadIncludeOnce($languageInclude);
213 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Language file %s not found or readable.", $languageInclude));