Compartmentalize plugin localisation
This commit is contained in:
parent
9f35bfbd69
commit
af47e845b5
|
@ -22,7 +22,10 @@ class Plugin {
|
||||||
// (array) Plugin's information.
|
// (array) Plugin's information.
|
||||||
public $metadata;
|
public $metadata;
|
||||||
|
|
||||||
function __construct()
|
// (array) Plugin's localisation.
|
||||||
|
public $language;
|
||||||
|
|
||||||
|
function __construct($locale)
|
||||||
{
|
{
|
||||||
$this->dbFields = array();
|
$this->dbFields = array();
|
||||||
|
|
||||||
|
@ -40,6 +43,17 @@ class Plugin {
|
||||||
// Init empty database
|
// Init empty database
|
||||||
$this->db = $this->dbFields;
|
$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';
|
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php';
|
||||||
|
|
||||||
// --- Metadata ---
|
// --- Metadata ---
|
||||||
|
@ -218,8 +232,12 @@ class Plugin {
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
// This method is used on childre classes.
|
// This method is used on child classes.
|
||||||
// The user can define your own dbFields.
|
// The user can define their own dbFields.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function L($key)
|
||||||
|
{
|
||||||
|
return $this->language->get($key);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -75,26 +75,27 @@ function buildPlugins()
|
||||||
|
|
||||||
foreach($pluginsDeclaredClasess as $pluginClass)
|
foreach($pluginsDeclaredClasess as $pluginClass)
|
||||||
{
|
{
|
||||||
$Plugin = new $pluginClass;
|
$Plugin = new $pluginClass($Site->locale());
|
||||||
|
|
||||||
// Check if the plugin is translated.
|
// Deprecated
|
||||||
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
|
// // Check if the plugin is translated.
|
||||||
if( !Sanitize::pathFile($languageFilename) ) {
|
// $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
|
||||||
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
|
// if( !Sanitize::pathFile($languageFilename) ) {
|
||||||
}
|
// $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
|
||||||
|
// }
|
||||||
|
|
||||||
$database = file_get_contents($languageFilename);
|
// $database = file_get_contents($languageFilename);
|
||||||
$database = json_decode($database, true);
|
// $database = json_decode($database, true);
|
||||||
|
|
||||||
// Set name and description from the language file.
|
// // Set name and description from the language file.
|
||||||
$Plugin->setMetadata('name',$database['plugin-data']['name']);
|
// $Plugin->setMetadata('name',$database['plugin-data']['name']);
|
||||||
$Plugin->setMetadata('description',$database['plugin-data']['description']);
|
// $Plugin->setMetadata('description',$database['plugin-data']['description']);
|
||||||
|
|
||||||
// Remove name and description, and add new words if there are.
|
// // Remove name and description, and add new words if there are.
|
||||||
unset($database['plugin-data']);
|
// unset($database['plugin-data']);
|
||||||
if(!empty($database)) {
|
// if(!empty($database)) {
|
||||||
$Language->add($database);
|
// $Language->add($database);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Push Plugin to array all plugins installed and not installed.
|
// Push Plugin to array all plugins installed and not installed.
|
||||||
$plugins['all'][$pluginClass] = $Plugin;
|
$plugins['all'][$pluginClass] = $Plugin;
|
||||||
|
|
Loading…
Reference in New Issue