2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class dbLanguage extends dbJSON
|
|
|
|
{
|
2015-07-14 06:41:32 +02:00
|
|
|
public $data;
|
|
|
|
public $db;
|
2015-08-17 02:24:22 +02:00
|
|
|
public $currentLocale;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2016-11-07 20:58:26 +01:00
|
|
|
function __construct( $locale, $path = null )
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2016-11-07 20:58:26 +01:00
|
|
|
$path = $path ? $path : PATH_LANGUAGES;
|
|
|
|
|
2015-06-29 04:51:48 +02:00
|
|
|
$this->data = array();
|
2015-07-14 06:41:32 +02:00
|
|
|
$this->db = array();
|
2015-08-17 02:24:22 +02:00
|
|
|
$this->currentLocale = 'en_US';
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-06-29 04:51:48 +02:00
|
|
|
// Default language en_US
|
2016-11-07 20:58:26 +01:00
|
|
|
$filename = $path.'en_US.json';
|
2015-08-17 02:24:22 +02:00
|
|
|
if( Sanitize::pathFile($filename) )
|
2015-06-29 04:51:48 +02:00
|
|
|
{
|
2015-07-14 06:41:32 +02:00
|
|
|
$Tmp = new dbJSON($filename, false);
|
2016-11-07 20:58:26 +01:00
|
|
|
$this->db = $Tmp->db;
|
2015-06-29 04:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// User language
|
2016-11-07 20:58:26 +01:00
|
|
|
$filename = $path.$locale.'.json';
|
2015-08-17 02:24:22 +02:00
|
|
|
if( Sanitize::pathFile($filename) && ($locale!=="en_US") )
|
2015-06-29 04:51:48 +02:00
|
|
|
{
|
2015-08-17 02:24:22 +02:00
|
|
|
$this->currentLocale = $locale;
|
2015-07-14 06:41:32 +02:00
|
|
|
$Tmp = new dbJSON($filename, false);
|
2015-07-16 03:34:16 +02:00
|
|
|
$this->db = array_merge($this->db, $Tmp->db);
|
2015-06-29 04:51:48 +02:00
|
|
|
}
|
2015-07-03 22:44:26 +02:00
|
|
|
|
2016-11-07 20:58:26 +01:00
|
|
|
if ( $this->data )
|
|
|
|
{
|
|
|
|
$this->data = $this->db['language-data'];
|
|
|
|
unset($this->db['language-data']);
|
|
|
|
}
|
2015-06-29 04:51:48 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:24:22 +02:00
|
|
|
public function getCurrentLocale()
|
|
|
|
{
|
|
|
|
return $this->currentLocale;
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// Return the translation, if the translation does'n exist then return the English translation.
|
2015-07-04 00:36:37 +02:00
|
|
|
public function get($string)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-07-04 00:36:37 +02:00
|
|
|
$key = Text::lowercase($string);
|
2015-05-31 03:06:55 +02:00
|
|
|
$key = Text::replace(' ', '-', $key);
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
if(isset($this->db[$key])) {
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->db[$key];
|
2015-07-14 06:41:32 +02:00
|
|
|
}
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2016-03-27 21:01:23 +02:00
|
|
|
return $string;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
// Returns translation.
|
2015-07-04 00:36:37 +02:00
|
|
|
public function g($string)
|
|
|
|
{
|
|
|
|
return $this->get($string);
|
|
|
|
}
|
|
|
|
|
2015-07-24 05:28:25 +02:00
|
|
|
// Print translation.
|
|
|
|
public function printMe($string)
|
|
|
|
{
|
|
|
|
echo $this->get($string);
|
|
|
|
}
|
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
// Print translation.
|
2015-07-04 00:36:37 +02:00
|
|
|
public function p($string)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-07-04 00:56:24 +02:00
|
|
|
echo $this->get($string);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
public function add($array)
|
|
|
|
{
|
2016-06-06 04:24:15 +02:00
|
|
|
$this->db = array_merge($array, $this->db);
|
2015-07-03 22:44:26 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
// Returns the item from plugin-data.
|
|
|
|
public function getData($key)
|
|
|
|
{
|
|
|
|
if(isset($this->data[$key])) {
|
|
|
|
return $this->data[$key];
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:24:22 +02:00
|
|
|
return '';
|
2015-07-14 06:41:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an array with all dictionaries.
|
|
|
|
public function getLanguageList()
|
|
|
|
{
|
2015-09-15 01:07:15 +02:00
|
|
|
$files = Filesystem::listFiles(PATH_LANGUAGES, '*', 'json');
|
2015-07-14 06:41:32 +02:00
|
|
|
|
|
|
|
$tmp = array();
|
|
|
|
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
|
|
|
$t = new dbJSON($file, false);
|
2015-11-20 04:21:39 +01:00
|
|
|
|
|
|
|
// Check if the JSON is complete.
|
|
|
|
if(isset($t->db['language-data']['native']))
|
|
|
|
{
|
|
|
|
$native = $t->db['language-data']['native'];
|
|
|
|
$locale = basename($file, '.json');
|
|
|
|
$tmp[$locale] = $native;
|
|
|
|
}
|
2015-07-14 06:41:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $tmp;
|
|
|
|
}
|
2015-11-28 15:47:03 +01:00
|
|
|
}
|