/**
* Set the language for an area.
*
* @param string The language to use.
* @param string The area to set the language for.
*/
function set_language($language="english", $area="user")
{
global $mybb;
$language = preg_replace("#[^a-z0-9\-_]#i", "", $language);
// Default language is English.
if($language == "")
{
$language = "english";
}
// Check if the language exists.
if(!$this->language_exists($language))
{
die("Language $language ($this->path/$language) is not installed");
}
$this->language = $language;
require $this->path."/".$language.".php";
$this->settings = $langinfo;
// Load the admin language files as well, if needed.
if($area == "admin")
{
if(!is_dir($this->path."/".$language."/{$area}"))
{
if(!is_dir($this->path."/".$mybb->settings['cplanguage']."/{$area}"))
{
if(!is_dir($this->path."/english/{$area}"))
{
die("Your forum does not contain an Administration set. Please reupload the english language administration pack.");
}
else
{
$language = "english";
}
}
else
{
$language = $mybb->settings['cplanguage'];
}
}
$this->language = $language."/{$area}";
}
}
/**
* Load the language variables for a section.
*
* @param string The section name.
* @param boolean Is this a datahandler?
* @param boolean supress the error if the file doesn't exist?
*/
function load($section, $isdatahandler=false, $supress_error=false)
{
// Assign language variables.
// Datahandlers are never in admin lang directory.
if($isdatahandler === true)
{
$this->language = str_replace('/admin', '', $this->language);
}
$lfile = $this->path."/".$this->language."/".$section.".lang.php";
if(file_exists($lfile))
{
require_once $lfile;
}
elseif(file_exists($this->path."/english/".$section.".lang.php"))
{
require_once $this->path."/english/".$section.".lang.php";
}
else
{
if($supress_error != true)
{
die("$lfile does not exist");
}
}
// We must unite and protect our language variables!
$lang_keys_ignore = array('language', 'path', 'settings');
if(is_array($l))
{
foreach($l as $key => $val)
{
if((empty($this->$key) || $this->$key != $val) && !in_array($key, $lang_keys_ignore))
{
$this->$key = $val;
}
}
}
}