BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: Temar on January 25, 2009, 05:49:39 pm

Title: Language Support
Post by: Temar on January 25, 2009, 05:49:39 pm
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
Code: [Select]
<?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

Code: [Select]
<?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
Title: Re: Language Support
Post by: chek on June 19, 2009, 09:52:09 pm
Tell me pls what dirrectory?
Title: Re: Language Support
Post by: Temar on June 22, 2009, 04:00:38 am
this isnt complete it is still in the works
altho i havnt worked on it in awhile
SimplePortal 2.3.7 © 2008-2024, SimplePortal