Fixes for new l10n

This commit is contained in:
torkel104 2016-11-07 20:58:26 +01:00
parent c65193aa42
commit fddf121032
3 changed files with 23 additions and 17 deletions

View File

@ -25,8 +25,10 @@ class Plugin {
// (dbLanguage) Plugin's localisation.
public $language;
function __construct($locale)
function __construct()
{
global $Site;
$this->dbFields = array();
$reflector = new ReflectionClass(get_class($this));
@ -43,9 +45,15 @@ class Plugin {
// Init empty database
$this->db = $this->dbFields;
// Load localisation
$tmp = new dbLanguage($locale, PATH_PLUGINS.$this->directoryName.DS.'languages'.DS);
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php';
// --- Metadata ---
$this->filenameMetadata = PATH_PLUGINS.$this->directoryName().DS.'metadata.json';
$metadataString = file_get_contents($this->filenameMetadata);
$this->metadata = json_decode($metadataString, true);
// Load localisation
$tmp = new dbLanguage($Site->locale(), PATH_PLUGINS.$this->directoryName.DS.'languages'.DS);
// Set name and description from the language file.
$this->setMetadata('name',$tmp->db['plugin-data']['name']);
$this->setMetadata('description',$tmp->db['plugin-data']['description']);
@ -54,13 +62,6 @@ class Plugin {
unset($tmp->db['plugin-data']);
$this->language = $tmp;
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php';
// --- Metadata ---
$this->filenameMetadata = PATH_PLUGINS.$this->directoryName().DS.'metadata.json';
$metadataString = file_get_contents($this->filenameMetadata);
$this->metadata = json_decode($metadataString, true);
// If the plugin is installed then get the database.
if($this->installed())
{

View File

@ -75,7 +75,7 @@ function buildPlugins()
foreach($pluginsDeclaredClasess as $pluginClass)
{
$Plugin = new $pluginClass($Site->locale());
$Plugin = new $pluginClass();
// Deprecated
// // Check if the plugin is translated.

17
bl-kernel/dblanguage.class.php Normal file → Executable file
View File

@ -6,22 +6,24 @@ class dbLanguage extends dbJSON
public $db;
public $currentLocale;
function __construct($locale)
function __construct( $locale, $path = null )
{
$path = $path ? $path : PATH_LANGUAGES;
$this->data = array();
$this->db = array();
$this->currentLocale = 'en_US';
// Default language en_US
$filename = PATH_LANGUAGES.'en_US.json';
$filename = $path.'en_US.json';
if( Sanitize::pathFile($filename) )
{
$Tmp = new dbJSON($filename, false);
$this->db = array_merge($this->db, $Tmp->db);
$this->db = $Tmp->db;
}
// User language
$filename = PATH_LANGUAGES.$locale.'.json';
$filename = $path.$locale.'.json';
if( Sanitize::pathFile($filename) && ($locale!=="en_US") )
{
$this->currentLocale = $locale;
@ -29,8 +31,11 @@ class dbLanguage extends dbJSON
$this->db = array_merge($this->db, $Tmp->db);
}
$this->data = $this->db['language-data'];
unset($this->db['language-data']);
if ( $this->data )
{
$this->data = $this->db['language-data'];
unset($this->db['language-data']);
}
}
public function getCurrentLocale()