2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 // Default is 'de'. DO NOT CHANGE THIS!!!
89 // Set default return value to default language from config
90 if (isConfigEntrySet('DEFAULT_LANG')) $ret = getConfig('DEFAULT_LANG');
95 // Is the variable set
96 if (isGetRequestElementSet('mx_lang')) {
97 // Accept only first 2 chars
98 $lang = substr(getRequestElement('mx_lang'), 0, 2);
99 } elseif (isset($GLOBALS['language'])) {
101 $ret = getCurrentLanguage();
102 } elseif (!empty($lang)) {
103 // Check if main language file does exist
104 if (isIncludeReadable('inc/language/' . $lang . '.php')) {
105 // Okay found, so let's update cookies
108 } elseif (isSessionVariableSet('mx_lang')) {
109 // Return stored value from cookie
110 $ret = getSession('mx_lang');
112 // Fixes a warning before the session has the mx_lang constant
113 if (empty($ret)) $ret = getConfig('DEFAULT_LANG');
117 $GLOBALS['language'] = $ret;
123 // "Setter" for language
124 function setLanguage ($lang) {
125 // Accept only first 2 chars and still secure them
126 $lang = substr(secureString($lang), 0, 2);
129 setSession('mx_lang', $lang);
132 // Checks wether a language file is there for optional extension
133 function isLanguageIncludeReadable ($ext_name = 'none') {
134 // Do we have array element?
135 if (!isset($GLOBALS['lang_inc'][$ext_name])) {
137 if ($ext_name == 'none') {
139 $languageInclude = sprintf("inc/language/%s.php", getLanguage());
141 // Extension's language file
142 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
145 // Look for file if no extension name is provided
146 $GLOBALS['lang_inc'][$ext_name] = isIncludeReadable($languageInclude);
147 //* DEBUG: */ print __FUNCTION__.':'.$ext_name.'='.$languageInclude.'='.intval(isIncludeReadable($languageInclude)).'<br />';
151 return $GLOBALS['lang_inc'][$ext_name];
154 // Load the current language file or fixes it to 'de'
155 // If ext_name is 'none', load general language support, else load extension's
156 // language file. In installation phase load the install language file.
157 function loadLanguageFile ($ext_name = 'none') {
158 // Try to get language from session
159 $currLanguage = getLanguage();
161 // Set default language if it is not (yet) set
162 if (is_null($currLanguage)) {
163 // Get it from config
164 $currLanguage = getConfig('DEFAULT_LANG');
166 // And save it in session
167 setLanguage($currLanguage);
170 // Do we have the language file NOT?
171 if (!isLanguageIncludeReadable($ext_name)) {
172 // Switch to default (DO NOT CHANGE!!!)
175 // And set it temporarily
176 setConfigEntry('DEFAULT_LANG', 'de');
179 // Is the file there?
180 if (isLanguageIncludeReadable($ext_name)) {
181 // Load language file
182 loadLanguageInclude($ext_name);
183 } elseif ((isDebugModeEnabled()) && (getOutputMode() == '0') && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
184 // No language file is not so good...
185 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s, mode=%s",
192 // Check for installation mode
193 if ((isInstallationPhase()) || (!isAdminRegistered())) {
194 // Load language file
195 loadLanguageInclude('install');
199 // Loads the language file
200 function loadLanguageInclude ($ext_name = 'none') {
202 if ($ext_name == 'none') {
204 $languageInclude = sprintf("inc/language/%s.php", getLanguage());
206 // Extension's language file
207 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
210 // Check it before loading
211 if (isLanguageIncludeReadable($ext_name)) {
213 loadIncludeOnce($languageInclude);
216 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Language file %s not found or readable.", $languageInclude));