2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
13 die(_("Restricted access"));
14 include_once($path_to_root . "/lang/installed_languages.inc");
15 include_once($path_to_root . "/includes/lang/gettext.php");
20 var $code; // eg. ar_EG, en_GB
21 var $encoding; // eg. UTF-8, CP1256, ISO8859-1
22 var $dir; // Currently support for Left-to-Right (ltr) and
23 // Right-To-Left (rtl)
26 function language($name, $code, $encoding)
30 $this->encoding = $encoding;
34 function get_language_dir()
36 return "lang/" . $this->code;
40 function get_current_language_dir()
42 $lang = $_SESSION['language'];
43 return "lang/" . $lang->code;
46 function set_language($code)
48 global $comp_path, $path_to_root;
50 if (isset($_SESSION['languages'][$code]) &&
51 $_SESSION['language'] != $_SESSION['languages'][$code])
53 // flush cache as we can use several languages in one account
54 flush_dir($comp_path.'/'.user_company().'/js_cache');
55 $_SESSION['language'] = $_SESSION['languages'][$code];
56 $locale = $path_to_root . "/lang/" . $_SESSION['language']->code . "/locale.inc";
57 // check id file exists only once for session
58 $_SESSION['language']->is_locale_file = file_exists($locale);
63 * This method loads an array of language objects into a session variable
64 * called $_SESSIONS['languages']. Only supported languages are added.
66 function load_languages()
68 global $installed_languages, $dflt_lang;
70 $_SESSION['languages'] = array();
72 foreach ($installed_languages as $lang)
74 $l = new language($lang['name'],$lang['code'],$lang['encoding']);
75 if (isset($lang['rtl']))
77 $_SESSION['languages'][$l->code] = $l;
80 if (!isset($_SESSION['language']))
81 $_SESSION['language'] = $_SESSION['languages'][$dflt_lang];
86 Test if named function is defined in locale.inc file.
88 function has_locale($fun=null)
92 if ($_SESSION['language']->is_locale_file)
95 include_once($path_to_root . "/lang/" .
96 $_SESSION['language']->code . "/locale.inc");
98 if (!isset($fun) || function_exists($fun))
104 function _set($key,$value)
106 get_text::set_var($key,$value);
109 function reload_page($msg)
112 // header("Location: $_SERVER['PHP_SELF']."");
116 echo "<title>Changing Languages</title>";
117 echo '<meta http-equiv="refresh" content="0;url=' . $_SERVER['PHP_SELF'] . '">';
122 echo $msg . " " . $_SERVER['PHP_SELF'];
126 $Ajax->redirect($_SERVER['PHP_SELF']);
129 if (!function_exists("_"))
133 $retVal = get_text::gettext($text);