Compartmentalize plugin localisation

This commit is contained in:
torkel104 2016-11-07 20:07:42 +01:00
parent 9f35bfbd69
commit af47e845b5
2 changed files with 38 additions and 19 deletions

24
bl-kernel/abstract/plugin.class.php Normal file → Executable file
View File

@ -21,8 +21,11 @@ class Plugin {
// (array) Plugin's information.
public $metadata;
// (array) Plugin's localisation.
public $language;
function __construct()
function __construct($locale)
{
$this->dbFields = array();
@ -40,6 +43,17 @@ class Plugin {
// Init empty database
$this->db = $this->dbFields;
// Load localisation
$tmp = new dbLanguage($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']);
// Remove name and description
unset($tmp->db['plugin-data']);
$this->language = $tmp;
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php';
// --- Metadata ---
@ -218,8 +232,12 @@ class Plugin {
public function init()
{
// This method is used on childre classes.
// The user can define your own dbFields.
// This method is used on child classes.
// The user can define their own dbFields.
}
public function L($key)
{
return $this->language->get($key);
}
}

33
bl-kernel/boot/rules/60.plugins.php Normal file → Executable file
View File

@ -75,26 +75,27 @@ function buildPlugins()
foreach($pluginsDeclaredClasess as $pluginClass)
{
$Plugin = new $pluginClass;
$Plugin = new $pluginClass($Site->locale());
// Check if the plugin is translated.
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
}
// Deprecated
// // Check if the plugin is translated.
// $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
// if( !Sanitize::pathFile($languageFilename) ) {
// $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
// }
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
// $database = file_get_contents($languageFilename);
// $database = json_decode($database, true);
// Set name and description from the language file.
$Plugin->setMetadata('name',$database['plugin-data']['name']);
$Plugin->setMetadata('description',$database['plugin-data']['description']);
// // Set name and description from the language file.
// $Plugin->setMetadata('name',$database['plugin-data']['name']);
// $Plugin->setMetadata('description',$database['plugin-data']['description']);
// Remove name and description, and add new words if there are.
unset($database['plugin-data']);
if(!empty($database)) {
$Language->add($database);
}
// // Remove name and description, and add new words if there are.
// unset($database['plugin-data']);
// if(!empty($database)) {
// $Language->add($database);
// }
// Push Plugin to array all plugins installed and not installed.
$plugins['all'][$pluginClass] = $Plugin;