Compartmentalize plugin localisation
This commit is contained in:
parent
9f35bfbd69
commit
af47e845b5
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue