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 - 2008 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 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
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 (isset($GLOBALS['msg'][strtolower($messageId)])) {
52 // Language array element found in small_letters
53 $return = $GLOBALS['msg'][$messageId];
54 } elseif (isset($GLOBALS['msg'][strtoupper($messageId)])) {
55 // @DEPRECATED Language array element found in BIG_LETTERS
56 $return = $GLOBALS['msg'][$messageId];
57 } elseif (defined($messageId)) {
58 // @DEPRECATED Deprecated constant found
59 $return = constant($messageId);
61 // Missing language constant
62 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Missing message string %s detected.", $messageId));
69 // "Getter" for language
70 function getLanguage () {
71 // Set default return value to default language from config
72 $ret = getConfig('DEFAULT_LANG');
77 // Is the variable set
78 if (REQUEST_ISSET_GET('mx_lang')) {
79 // Accept only first 2 chars
80 $lang = substr(REQUEST_GET('mx_lang'), 0, 2);
81 } elseif (isset($GLOBALS['cache_array']['language'])) {
83 $ret = $GLOBALS['cache_array']['language'];
84 } elseif (!empty($lang)) {
85 // Check if main language file does exist
86 if (isFileReadable(constant('PATH') . 'inc/language/' . $lang . '.php')) {
87 // Okay found, so let's update cookies
90 } elseif (isSessionVariableSet('mx_lang')) {
91 // Return stored value from cookie
92 $ret = getSession('mx_lang');
94 // Fixes a warning before the session has the mx_lang constant
95 if (empty($ret)) $ret = getConfig('DEFAULT_LANG');
99 $GLOBALS['cache_array']['language'] = $ret;
105 // "Setter" for language
106 function setLanguage ($lang) {
107 // Accept only first 2 chars!
108 $lang = substr(SQL_ESCAPE(strip_tags($lang)), 0, 2);
111 setSession('mx_lang', $lang);
114 // Load the current language file or fixes it to 'de'
115 // If ext_name is empty, load general language support, else load extension's
117 function loadLanguageFile ($ext_name = '') {
118 // Try to get language from session
119 $mx_lang = getSession('mx_lang');
121 // Set default language if it is not (yet) set
122 if (is_null($mx_lang)) $mx_lang = getConfig('DEFAULT_LANG');
125 if (empty($ext_name)) {
127 $languageInclude = sprintf("inc/language/%s.php", SQL_ESCAPE($mx_lang));
129 // Extension's language file
130 $languageInclude = sprintf("inc/language/%s_%s.php", $ext_name, getLanguage());
133 // Look for file if no extension name is provided
134 if ((empty($ext_name)) && (isIncludeReadable($languageInclude) === false)) {
135 // Switch to default (DO NOT CHANGE!!!)
137 $languageInclude = 'inc/language/de.php';
139 // And set it temporarily
140 setConfigEntry('DEFAULT_LANG', 'de');
143 // Is the file there?
144 if (isIncludeReadable($languageInclude)) {
145 // Load language file
146 loadIncludeOnce($languageInclude);
147 } elseif ((isDebugModeEnabled()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme')) {
148 // No language file is not so good...
149 DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no language file or we cannot read from it. lang=%s",
150 $ext_name, getLanguage()
154 // Check for installation mode
155 if ((isInstalling()) || (!isInstalled()) || (!isAdminRegistered())) {
156 // Load matching language file
157 loadInclude('inc/language/install_' . getSession('mx_lang') . '.php');