I don't know what's wrong. I had this script before, but without classes, and just regular good old PHP style. And it worked fine with my language system.
Basicly, it's just including a language file depending on the value in the cookie set...
The language file itself includes a basic array:
english.php
PHP Code:
$lang[error1] = 'Something in english';
swedish.php
PHP Code:
$lang[error1] = 'Something in swedish';
You get the idea. But after I changed the script to OOP, the language system isn't working anymore.
PHP Code:
// Checks the path for available languages and puts them in an array.
public function getLanguages($path) {
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
$file = substr($file, 0, -4);
$this->languages[] = $file;
}
}
closedir($handle);
}
}
// Fetches the current value of $_GET['setlang'] if it's set, otherwise checks cookie if it's set and sets the current language.
// If not, the standard language is set as the current language.
public function getLanguage($path) {
if($_GET['setlang']) {
$language = $_GET['setlang'];
$check = array_search($language, $this->languages);
if($check !== false) {
if($language == $this->standardLang) {
setcookie('lang', '', time()-3600);
}
else {
setcookie('lang', $language, time()+3600);
}
$this->currentLang = $language;
include($path .$this->currentLang. '.php');
return true;
}
else {
$this->currentLang = 'english';
include($path .$this->currentLang.'.php');
return false;
}
}
else {
if(isset($_COOKIE['lang'])) {
$this->currentLang = $_COOKIE['lang'];
}
else {
$this->currentLang = $this->standardLang;
}
include($path .$this->currentLang. '.php');
return true;
}
}
And when I use the language, I just use the variable name of the array inside the language files.
For example:
PHP Code:
echo '<a href="'.$_SERVER['PHPSELF'].'?folder='.$this->currentFolder.'&page='.$this->firstPage.'">
' .$lang[first_page]. '</a> .. ';
As you see:
PHP Code:
$lang[first_page]
That would be the value of that key in the array, in the current language file included.
But it's not working, does anyone have any idea how to make a better system perhaps, or how to fix the problem?