Making Bebot Support Other Languages
this is a module for TWC which i will be improving on for use by BeBot
i have added comments to it for planned changes
<?php
$languages = new languages($twc);
class languages
{
function __construct($twc)
{
$this -> twc = $twc;
$this -> twc -> register_module("lang", $this);
// load english now to make sure everything has output
$this -> load("english"); // Load all required languages
}
function load($lang)
{
if(defined("ROOT"))
$root = ROOT;
if(file_exists($root."languages/".$lang.".php"))
{
Require($root."languages/".$lang.".php");
$this -> langs[$lang] = $txt;
}
}
function get($txt, $rep1=FALSE)
{
$user = $this -> twc -> prefs["lang"]; // this will only be for tells
$main = $this -> twc -> settings["lang"]; // this will be for gc
if($user != "default" && isset($this -> langs[$user][$txt]))
$return = $this -> langs[$user][$txt];
elseif(isset($this -> langs[$main][$txt]))
$return = $this -> langs[$main][$txt];
elseif(isset($this -> langs["english"][$txt]))
$return = $this -> langs["english"][$txt];// always fall back to english if cant find
else
$return = "Language text not found for \"$txt\""; // hopefully should better be called
if($rep1)
$return = str_ireplace("&rep1&", $rep1, $return);// this need to support multi replacement , $rep1 will be $rep and will be an array
Return $return;
}
}
?>
as for the language file i think this format will be suitable
english_core.php
english_irc.php
this being <language>_<module>.php
ofc the module is mainly a referance so u know wats were, and also to make files names unique and not all in 1 big file
inside it will be like this
<?php
$txt["reload ar"] = "Reload Page to See Access Request Form";
?>
the above should be stores as (if loaded from english_core.php)
$lang['english']['core']['reload ar'] = "Reload Page to See Access Request Form";
this can be called useing
$this -> lang('reload ar'); from a module that has defined it self as core
$this -> lang('reload ar', 'core'); from a module that has been definded as something else or not defined