Adding language support to plugins see #4557

skala
Julio Montoya 13 years ago
parent 0739035eb4
commit be9d1b8856
  1. 5
      main/inc/lib/plugin.class.php
  2. 52
      main/inc/lib/plugin.lib.php
  3. 15
      main/inc/lib/template.lib.php
  4. 23
      plugin/bbb/bbb.lib.php
  5. 6
      plugin/bbb/config.php
  6. 7
      plugin/bbb/index.php
  7. 18
      plugin/bbb/lang/english.php
  8. 2
      plugin/bbb/lang/spanish.php
  9. 13
      plugin/bbb/lib/bbb_plugin.class.php
  10. 8
      plugin/bbb/listing.php
  11. 8
      plugin/bbb/listing.tpl
  12. 24
      plugin/bbb/plugin.php
  13. 5
      plugin/bbb/uninstall.php
  14. 4
      plugin/hello_world/index.php
  15. 9
      plugin/hello_world/lang/english.php
  16. 3
      plugin/hello_world/lang/french.php
  17. 3
      plugin/hello_world/lang/spanish.php
  18. 3
      plugin/show_user_info/lang/english.php
  19. 3
      plugin/show_user_info/lang/spanish.php
  20. 2
      plugin/show_user_info/plugin.php
  21. 4
      plugin/show_user_info/template.tpl

@ -129,16 +129,15 @@ class Plugin {
global $language_interface;
$root = api_get_path(SYS_PLUGIN_PATH);
$plugin_name = $this->get_name();
$language = $language_interface;
$path = "$root/$plugin_name/lang/$language.php";
//1. Loading english if exists
$english_path = "$root/$plugin_name/lang/english.php";
$english_path = $root.$plugin_name."/lang/english.php";
if (is_readable($english_path)) {
include $english_path;
$this->strings = $strings;
}
$path = $root.$plugin_name."/lang/$language_interface.php";
//2. Loading the system language
if (is_readable($path)) {
include $path;

@ -28,16 +28,6 @@ class AppPlugin {
function __construct() {
}
/* For each of the possible plugin directories we check whether a file named "plugin.php" exists
(it contains all the needed information about this plugin).
This "plugin.php" file looks like:
$plugin_info['title'] = 'The title of the plugin';
$plugin_info['comment'] = 'Some comment about the plugin';
$plugin_info['location'] = array('loginpage_menu', 'campushomepage_menu', 'banner'); // The possible locations where the plugins can be used.
$plugin_info['version'] = '0.1 alpha'; // The version number of the plugin.
$plugin_info['author'] = 'Patrick Cool'; // The author of the plugin.
*/
function read_plugins_from_path() {
/* We scan the plugin directory. Each folder is a potential plugin. */
$pluginpath = api_get_path(SYS_PLUGIN_PATH);
@ -146,6 +136,40 @@ class AppPlugin {
return $content;
}
/**
* Loads the translation files inside a plugin if exists. It loads by default english see the hello world plugin
*
* @todo add caching
* @param string $plugin_name
*/
function load_plugin_lang_variables($plugin_name) {
global $language_interface;
$root = api_get_path(SYS_PLUGIN_PATH);
//1. Loading english if exists
$english_path = $root.$plugin_name."/lang/english.php";
if (is_readable($english_path)) {
include $english_path;
foreach ($strings as $key => $string) {
//$$key = $string;
$GLOBALS[$key] = $string;
}
}
//2. Loading the system language
$path = $root.$plugin_name."/lang/$language_interface.php";
if (is_readable($path)) {
include $path;
if (!empty($strings)) {
foreach ($strings as $key => $string) {
//$$key = $string;
$GLOBALS[$key] = $string;
}
}
}
}
/**
*
*
@ -163,17 +187,19 @@ class AppPlugin {
//The plugin_info variable is available inside the plugin index
$plugin_info = $this->get_plugin_info($plugin_name);
//We also where the plugin is
//We also know where the plugin is
$plugin_info['current_region'] = $region;
// Loading the plugin/XXX/index.php file
$plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php";
if (file_exists($plugin_file)) {
//Printing the plugin index.php file
require $plugin_file;
//Loading the lang variables of the plugin if exists
self::load_plugin_lang_variables($plugin_name);
//Printing the plugin index.php file
require $plugin_file;
//If the variable $_template is set we assign those values to be accesible in Twig
if (isset($_template)) {

@ -31,7 +31,6 @@ class Template {
var $params = array();
function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false) {
//parent::__construct();
//Twig settings
Twig_Autoloader::register();
@ -51,13 +50,11 @@ class Template {
//'optimizations' => 0 // turn on optimizations with -1
));
$debug = new Twig_Extension_Debug();
$this->twig->addExtension($debug);
$this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
$this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
$this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
$this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
$this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
/*
$lexer = new Twig_Lexer($this->twig, array(
@ -92,11 +89,21 @@ class Template {
//Chamilo plugins
if ($this->show_header) {
$this->plugin = new AppPlugin();
//1. Showing installed plugins in regions
$plugin_regions = $this->plugin->get_plugin_regions();
foreach ($plugin_regions as $region) {
$this->set_plugin_region($region);
}
//2. Loading the course plugin info
global $course_plugin;
if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
//Load plugin get_langs
$this->plugin->load_plugin_lang_variables($course_plugin);
}
}
}

@ -73,10 +73,10 @@ class bbb {
// ??
$voiceBridge = 0;
$metadata = array('maxParticipants' => $max);
return $this->protocol.BigBlueButtonBN::createMeetingAndGetJoinURL($this->user_complete_name, $meeting_name, $id, $welcome_msg, $moderator_password, $attende_password,
$this->salt, $this->url, $this->logout_url, $record, $duration, $voiceBridge, $metadata);
//$id = Database::update($this->table, array('created_at' => ''));
return $this->protocol.BigBlueButtonBN::createMeetingAndGetJoinURL(
$this->user_complete_name, $meeting_name, $id, $welcome_msg, $moderator_password, $attende_password,
$this->salt, $this->url, $this->logout_url, $record, $duration, $voiceBridge, $metadata
);
}
}
@ -144,27 +144,31 @@ class bbb {
$records = BigBlueButtonBN::getRecordingsArray($meeting['id'], $this->url, $this->salt);
//var_dump($meeting['id']);
if (!empty($records)) {
$count = 1;
foreach ($records as $record) {
if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
//Fix the bbb timestamp
$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
//$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
//$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
//.' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime'])
foreach ($record['playbacks'] as $item) {
$url = Display::url(get_lang('ViewRecord'), $item['url'], array('target' => '_blank')).' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime']);
$url = Display::url(get_lang('ViewRecord').' #'.$count, $item['url'], array('target' => '_blank'));
//$url .= Display::url(get_lang('DeleteRecord'), api_get_self().'?action=delete_record&'.$record['recordID']);
$url .= Display::url(get_lang('CopyToLinkTool'), api_get_self().'?action=copy_record_to_link_tool&id='.$meeting['id'].'&record_id='.$record['recordID']);
//$url .= api_get_self().'?action=publish&id='.$record['recordID'];
$count++;
$record_array[] = $url;
}
}
}
}
$item_meeting['show_links'] = implode('<br />', $record_array);
}
$item_meeting['created_at'] = api_get_local_time($item_meeting['created_at']);
$item_meeting['created_at'] = api_convert_and_format_date($item_meeting['created_at']);
//created_at
$item_meeting['publish_url'] = api_get_self().'?action=publish&id='.$meeting['id'];
@ -247,6 +251,9 @@ class bbb {
}
}
return false;
}
function is_server_running() {
return BigBlueButtonBN::isServerRunning($this->url);
}
}

@ -1,9 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/* bbb parameters that will be registered in the course settings */
$variables = array( 'big_blue_button_meeting_name',
'big_blue_button_attendee_password',
'big_blue_button_moderator_password',
'big_blue_button_welcome_message',
'big_blue_button_max_students_allowed',
'big_blue_button_max_students_allowed'
);

@ -1,6 +1,3 @@
<?php
/**
* Placeholder file
* Should contain the code to access the plugin from outside a course
* @package chamilo.plugin.bigbluebutton
*/
?>

@ -0,0 +1,18 @@
<?php
/**
*
* @copyright (c) 2012 University of Geneva
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
//Needed in order to show the plugin title
$strings['plugin_title'] = "BigBlueButton";
$strings['plugin_comment'] = "Open Source Videoconference tool";
$strings['Videoconference'] = "Videoconference";
$strings['MeetingOpened'] = "Meeting opened";
$strings['StartConference'] = "Start conference";
$strings['RecordList'] = "Record list";
$strings['ServerIsNotRunning'] = "Server Is Not Running";

@ -0,0 +1,13 @@
<?php
class BBBPlugin extends Plugin
{
static function create() {
static $result = null;
return $result ? $result : $result = new self();
}
protected function __construct() {
parent::__construct('2.0', 'Julio Montoya, Yannick Warnier');
}
}

@ -7,7 +7,7 @@
* Initialization
*/
$language_file = array('videoconf');
$course_plugin = 'bbb';
require_once '../../main/inc/global.inc.php';
require_once 'bbb.lib.php';
@ -16,6 +16,7 @@ require_once 'bbb_api.php';
$bbb = new bbb();
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
case 'copy_record_to_link_tool':
$result = $bbb->copy_record_to_link_tool($_GET['id'], $_GET['record_id']);
@ -42,8 +43,10 @@ switch ($action) {
$meetings = $bbb->get_course_meetings();
$users_online = $bbb->get_users_online_in_current_room();
$status = $bbb->is_server_running();
$status = false;
$tool_name = get_lang('OrganisationSVideoconference');
$tool_name = get_lang('Videoconference');
$tpl = new Template($tool_name);
@ -51,6 +54,7 @@ $tpl->assign('meetings', $meetings);
$conference_url = api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.api_get_cidreq();
$tpl->assign('conference_url', $conference_url);
$tpl->assign('users_online', $users_online);
$tpl->assign('bbb_status', $status);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);

@ -1,5 +1,7 @@
<div class ="row">
{% if bbb_status == true %}
<div class ="span12" style="text-align:center">
<a href="{{ conference_url }}" class="btn btn-primary btn-large">
{{ 'StartConference'|get_lang }}
@ -34,7 +36,6 @@
<!-- <a href="{{ meeting.publish_url}} "> Publish </a>
<a href="{{ meeting.unpublish_url}} "> UnPublish </a> -->
{% endif %}
<br />
{% if meeting.status == 1 %}
<span class="label label-success">{{'MeetingOpened'|get_lang}}</span>
@ -49,4 +50,9 @@
{% endfor %}
</table>
</div>
{% else %}
<div class ="span12" style="text-align:center">
{{ 'ServerIsNotRunning' | return_message('warning') }}
</div>
{% endif %}
</div>

@ -1,20 +1,6 @@
<?php
/**
* This script is a configuration file for the BigBlueButton plugin. You can use it as a master for other course plugins.
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
* @package chamilo.plugin
* @author Yannick Warnier <ywarnier@beeznest.org>
*/
/**
* Plugin details (must be present)
*/
//the plugin title
$plugin_info['title']='BigBlueButton';
//the comments that go with the plugin
$plugin_info['comment']="Open Source Videoconference tool";
//the locations where this plugin can be shown
$plugin_info['location']=array('course_tool_plugin');
//the plugin version
$plugin_info['version']='1.0';
//the plugin author
$plugin_info['author']='Julio Montoya & Yannick Warnier';
require_once api_get_path(LIBRARY_PATH) . '/plugin.class.php';
require_once dirname(__FILE__) . '/lib/bbb_plugin.class.php';
$plugin_info = BBBPlugin::create()->get_info();

@ -1,4 +1,5 @@
<?php
/**
* This script is included by main/admin/settings.lib.php when unselecting a plugin
* and is meant to remove things installed by the install.php script in both
@ -8,7 +9,6 @@
/**
* Queries
*/
require 'config.php';
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -30,13 +30,12 @@ $sql = "SELECT id, code FROM $t_courses ORDER BY id";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$t_course = Database::get_course_table(TABLE_COURSE_SETTING);
// $variables is loaded in the config.php file
foreach ($variables as $variable) {
$sql_course = "DELETE FROM $t_course WHERE c_id = " . $row['id'] . " AND variable = '$variable'";
$r = Database::query($sql_course);
}
$t_tool = Database::get_course_table(TABLE_TOOL_LIST);
$sql_course = "DELETE FROM $t_tool WHERE c_id = " . $row['id'] . " AND link = '../../plugin/bbb/start.php'";
$r = Database::query($sql_course);

@ -11,4 +11,8 @@ if (!empty($plugin_info['settings']['hello_world_show_type'])) {
} else {
echo "<h2>Hello world</h2>";
}
//Using get_lang inside a plugin
echo get_lang('HelloPlugin');
echo '</div>';

@ -0,0 +1,9 @@
<?php
/**
*
* @copyright (c) 2012 University of Geneva
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
$strings['HelloPlugin'] = "Hello!";

@ -0,0 +1,3 @@
<?php
$strings['HelloPlugin'] = "Salut!";

@ -0,0 +1,3 @@
<?php
$strings['HelloPlugin'] = "Hola chaval!";

@ -0,0 +1,3 @@
<?php
$strings['WelcomToChamiloUserX'] = "Welcome to Chamilo %s!";

@ -0,0 +1,3 @@
<?php
$strings['WelcomToChamiloUserX'] = "Bienvenido a Chamilo %s!";

@ -13,7 +13,7 @@
$plugin_info['title'] = 'Show user information';
//the comments that go with the plugin
$plugin_info['comment'] = "Shows a welcome message, (this is an example to uses smarty)";
$plugin_info['comment'] = "Shows a welcome message, (this is an example to uses the template system: Twig)";
//the plugin version
$plugin_info['version'] = '1.0';
//the plugin author

@ -25,8 +25,6 @@
{% if show_user_info.show_message is not null and _u.logged == 1 %}
<div class="well">
{{"Welcome"|get_lang}} {{show_user_info.user_info.complete_name}} ({{show_user_info.username}})
<br />
The administrator - {{"siteName"|get_setting}}
{{ "WelcomToChamiloUserX" | get_lang | format(show_user_info.user_info.complete_name) }}
</div>
{% endif %}
Loading…
Cancel
Save