1<?php 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 13if (isset($_GET['path_to_root']) || isset($_POST['path_to_root'])) 14 die("Restricted access"); 15@include_once($path_to_root . "/lang/installed_languages.inc"); 16include_once($path_to_root . "/includes/lang/gettext.php"); 17 18class language 19{ 20 var $name; 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 26 var $is_locale_file; 27 28 function language($name, $code, $encoding, $dir = 'ltr') 29 { 30 global $dflt_lang; 31 32 $this->name = $name; 33 $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C'); 34 $this->encoding = $encoding; 35 $this->dir = $dir; 36 } 37 38 function get_language_dir() 39 { 40 return "lang/" . $this->code; 41 } 42 43 function get_current_language_dir() 44 { 45 $lang = $_SESSION['language']; 46 return "lang/" . $lang->code; 47 } 48 49 function set_language($code) 50 { 51 global $path_to_root, $installed_languages, $GetText; 52 53 $lang = array_search_value($code, $installed_languages, 'code'); 54 $changed = $this->code != $code || $this->version != @$lang['version']; 55 56 if ($lang && $changed) 57 { 58 // flush cache as we can use several languages in one account 59 flush_dir(company_path().'/js_cache'); 60 61 $this->name = $lang['name']; 62 $this->code = $lang['code']; 63 $this->encoding = $lang['encoding']; 64 $this->version = @$lang['version']; 65 $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr'; 66 $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc"; 67 $this->is_locale_file = file_exists($locale); 68 } 69 70 $GetText->set_language($this->code, $this->encoding); 71 $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version); 72 73 // Necessary for ajax calls. Due to bug in php 4.3.10 for this 74 // version set globally in php.ini 75 ini_set('default_charset', $this->encoding); 76 77 if (isset($_SESSION['App']) && $changed) 78 $_SESSION['App']->init(); // refresh menu 79 } 80} 81 82if (!function_exists("_")) 83{ 84 function _($text) 85 { 86 global $GetText; 87 if (!isset($GetText)) // Don't allow using gettext if not is net. 88 return $text; 89 90 $retVal = $GetText->gettext($text); 91 if ($retVal == "") 92 return $text; 93 return $retVal; 94 } 95} 96?>