2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class dbLanguage extends dbJSON
|
|
|
|
{
|
2015-06-26 06:31:53 +02:00
|
|
|
public $en_US;
|
2015-06-29 04:51:48 +02:00
|
|
|
private $data;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
function __construct($language)
|
|
|
|
{
|
2015-06-29 04:51:48 +02:00
|
|
|
$this->data = array();
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-06-29 04:51:48 +02:00
|
|
|
// Default language en_US
|
|
|
|
$filename = PATH_LANGUAGES.'en_US.json';
|
|
|
|
if(file_exists($filename))
|
|
|
|
{
|
|
|
|
parent::__construct($filename, false);
|
|
|
|
$this->en_US = $this->db;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User language
|
|
|
|
$filename = PATH_LANGUAGES.$language.'.json';
|
|
|
|
if(file_exists($filename))
|
|
|
|
{
|
|
|
|
parent::__construct($filename, false);
|
|
|
|
$this->data = $this->db['language-data'];
|
|
|
|
}
|
2015-07-03 22:44:26 +02:00
|
|
|
|
|
|
|
unset($this->db['language-data']);
|
2015-06-29 04:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getLanguageList()
|
|
|
|
{
|
|
|
|
$files = glob(PATH_LANGUAGES.'*.json');
|
|
|
|
|
|
|
|
$tmp = array();
|
|
|
|
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
|
|
|
$t = new dbJSON($file, false);
|
|
|
|
$native = $t->db['language-data']['native'];
|
|
|
|
$locale = basename($file, '.json');
|
|
|
|
$tmp[$locale] = $native;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tmp;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the translation, if the translation does'n exist then return the English translation.
|
|
|
|
public function get($text)
|
|
|
|
{
|
2015-05-31 03:06:55 +02:00
|
|
|
$key = Text::lowercase($text);
|
|
|
|
$key = Text::replace(' ', '-', $key);
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
if(isset($this->db[$key]))
|
|
|
|
return $this->db[$key];
|
|
|
|
|
|
|
|
// If the key is not translated then return the English translation.
|
2015-06-26 06:31:53 +02:00
|
|
|
return $this->en_US[$key];
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print the translation.
|
|
|
|
public function p($text)
|
|
|
|
{
|
|
|
|
echo $this->get($text);
|
|
|
|
}
|
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
public function add($array)
|
|
|
|
{
|
|
|
|
$this->db[] = $array;
|
|
|
|
}
|
|
|
|
|
2015-05-31 03:06:55 +02:00
|
|
|
}
|