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);