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 // Prevent register_globals vulnerability
13 if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
14 die("Restricted access");
15 @include_once($path_to_root . "/lang/installed_languages.inc");
16 include_once($path_to_root . "/includes/lang/gettext.inc");
21 var $code; // eg. ar_EG, en_GB
22 var $encoding; // eg. UTF-8, CP1256, ISO8859-1
23 var $dir; // Currently support for Left-to-Right (ltr) and
24 // Right-To-Left (rtl)
25 var $version; // lang package version
28 function __construct($name, $code, $encoding, $dir = 'ltr')
33 $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C');
34 $this->encoding = $encoding;
38 function get_language_dir()
40 return "lang/" . $this->code;
43 function get_current_language_dir()
45 $lang = $_SESSION['language'];
46 return "lang/" . $lang->code;
49 function set_language($code)
51 global $path_to_root, $installed_languages, $GetText;
53 $lang = array_search_value($code, $installed_languages, 'code');
54 $changed = $this->code != $code || $this->version != @$lang['version'];
56 if ($lang && $changed)
58 $this->name = $lang['name'];
59 $this->code = $lang['code'];
60 $this->encoding = $lang['encoding'];
61 $this->version = @$lang['version'];
62 $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr';
63 $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
64 $this->is_locale_file = file_exists($locale);
67 $GetText->set_language($this->code, $this->encoding);
68 $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
70 // Necessary for ajax calls. Due to bug in php 4.3.10 for this
71 // version set globally in php.ini
72 ini_set('default_charset', $this->encoding);
74 if (isset($_SESSION['wa_current_user']) && $_SESSION['wa_current_user']->logged_in() && isset($_SESSION['App']) && $changed)
75 $_SESSION['App']->init(); // refresh menu
79 if (!function_exists("_"))
84 if (!isset($GetText)) // Don't allow using gettext if not is net.
87 $retVal = $GetText->gettext($text);