Skip to content

Commit

Permalink
Replace plugin_lang_get with new gettext approach (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis committed Feb 4, 2013
1 parent 5bf9b2e commit 52c646c
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 151 deletions.
45 changes: 6 additions & 39 deletions core/plugin_api.php
Expand Up @@ -33,7 +33,6 @@
* @uses event_api.php
* @uses helper_api.php
* @uses history_api.php
* @uses lang_api.php
*/

require_api( 'access_api.php' );
Expand All @@ -43,7 +42,6 @@
require_api( 'event_api.php' );
require_api( 'helper_api.php' );
require_api( 'history_api.php' );
require_api( 'lang_api.php' );

# Cache variables #####

Expand Down Expand Up @@ -240,25 +238,6 @@ function plugin_config_defaults( $p_options ) {
}
}

/**
* Get a language string for the plugin.
* Automatically prepends plugin_<basename> to the string requested.
* @param string $p_name Language string name
* @param string $p_basename Plugin basename
* @return string Language string
*/
function plugin_lang_get( $p_name, $p_basename = null ) {
if( is_null( $p_basename ) ) {
$t_basename = plugin_get_current();
} else {
$t_basename = $p_basename;
}

$t_name = 'plugin_' . $t_basename . '_' . $p_name;

return lang_get( $t_name );
}

/**
* log history event from plugin
* @param int $p_bug_id bug id
Expand All @@ -280,24 +259,6 @@ function plugin_history_log( $p_bug_id, $p_field_name, $p_old_value, $p_new_valu
history_log_event_direct( $p_bug_id, $t_field_name, $p_old_value, $p_new_value, $p_user_id, PLUGIN_HISTORY );
}

/**
* Trigger a plugin-specific error with the given name and type.
* @param string $p_error_name Error name
* @param int $p_error_type Error type
* @param string $p_basename Plugin basename
*/
function plugin_error( $p_error_name, $p_error_type = ERROR, $p_basename = null ) {
if( is_null( $p_basename ) ) {
$t_basename = plugin_get_current();
} else {
$t_basename = $p_basename;
}

$t_error_code = "plugin_${t_basename}_${p_error_name}";

trigger_error( $t_error_code, $p_error_type );
}

/**
* Hook a plugin's callback function to an event.
* @param string $p_name Event name
Expand Down Expand Up @@ -751,6 +712,7 @@ function plugin_include( $p_basename, $p_child = null ) {
* @return mixed
*/
function plugin_register( $p_basename, $p_return = false, $p_child = null ) {
global $localeManager;
global $g_plugin_cache;

$t_basename = is_null( $p_child ) ? $p_basename : $p_child;
Expand All @@ -772,6 +734,11 @@ function plugin_register( $p_basename, $p_return = false, $p_child = null ) {
if( class_exists( $t_classname ) && is_subclass_of( $t_classname, 'MantisPlugin' ) ) {
plugin_push_current( is_null( $p_child ) ? $p_basename : $p_child );

# Load the plugin's default text domain
$t_locale_path = config_get( 'plugin_path' );
$t_locale_path .= $p_basename . '/locale/';
$localeManager->addTextDomain('plugin_' . $p_basename, $t_locale_path);

$t_plugin = new $t_classname( is_null( $p_child ) ? $p_basename : $p_child );

plugin_pop_current();
Expand Down
6 changes: 3 additions & 3 deletions plugins/MantisCoreFormatting/MantisCoreFormatting.php
Expand Up @@ -27,11 +27,11 @@ class MantisCoreFormattingPlugin extends MantisFormattingPlugin {
* A method that populates the plugin information and minimum requirements.
*/
function register( ) {
$this->name = lang_get( 'plugin_format_title' );
$this->description = lang_get( 'plugin_format_description' );
$this->name = d___('plugin_MantisCoreFormatting', 'MantisBT Formatting');
$this->description = d___('plugin_MantisCoreFormatting', 'Official text processing and formatting plugin.');
$this->page = 'config';

$this->version = '1.0a';
$this->version = '2.0.0';
$this->requires = array(
'MantisCore' => '2.0.0',
);
Expand Down
24 changes: 12 additions & 12 deletions plugins/MantisCoreFormatting/pages/config.php
Expand Up @@ -25,7 +25,7 @@
auth_reauthenticate( );
access_ensure_global_level( config_get( 'manage_plugin_threshold' ) );

html_page_top( lang_get( 'plugin_format_title' ) );
html_page_top( d___('plugin_MantisCoreFormatting', 'MantisBT Formatting') );

print_manage_menu( );

Expand All @@ -45,50 +45,50 @@

<tr>
<td class="form-title" colspan="3">
<?php echo lang_get( 'plugin_format_title' ) . ': ' . lang_get( 'plugin_format_config' )?>
<?php echo d___('plugin_MantisCoreFormatting', 'MantisBT Formatting Configuration') ?>
</td>
</tr>

<tr>
<td class="category">
<?php echo lang_get( 'plugin_format_process_text' )?>
<br /><span class="small"><?php echo lang_get( 'plugin_format_process_text_warning_notice' )?></span>
<?php echo d___('plugin_MantisCoreFormatting', 'Text Processing') ?>
<br /><span class="small"><?php echo d___('plugin_MantisCoreFormatting', 'Do not turn off unless you really know what you\'re doing. In the off state, cross site scripting (XSS) attacks are possible.') ?></span>
</td>
<td class="center">
<label><input type="radio" name="process_text" value="1" <?php echo( ON == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_enabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'On') ?></label>
</td>
<td class="center">
<label><input type="radio" name="process_text" value="0" <?php echo( OFF == plugin_config_get( 'process_text' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_disabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'Off') ?></label>
</td>
</tr>

<tr>
<th class="category">
<?php echo lang_get( 'plugin_format_process_urls' )?>
<?php echo d___('plugin_MantisCoreFormatting', 'URL Processing') ?>
</th>
<td class="center">
<label><input type="radio" name="process_urls" value="1" <?php echo( ON == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_enabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'On') ?></label>
</td>
<td class="center">
<label><input type="radio" name="process_urls" value="0" <?php echo( OFF == plugin_config_get( 'process_urls' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_disabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'Off') ?></label>
</td>
</tr>

<tr>
<th class="category">
<?php echo lang_get( 'plugin_format_process_buglinks' )?>
<?php echo d___('plugin_MantisCoreFormatting', 'MantisBT Links ( Issue/Issuenote )') ?>
</th>
<td class="center">
<label><input type="radio" name="process_buglinks" value="1" <?php echo( ON == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_enabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'On') ?></label>
</td>
<td class="center">
<label><input type="radio" name="process_buglinks" value="0" <?php echo( OFF == plugin_config_get( 'process_buglinks' ) ) ? 'checked="checked" ' : ''?>/>
<?php echo lang_get( 'plugin_format_disabled' )?></label>
<?php echo d___('plugin_MantisCoreFormatting', 'Off') ?></label>
</td>
</tr>

Expand Down
22 changes: 11 additions & 11 deletions plugins/MantisGraph/MantisGraph.php
Expand Up @@ -26,11 +26,11 @@ class MantisGraphPlugin extends MantisPlugin {
* A method that populates the plugin information and minimum requirements.
*/
function register( ) {
$this->name = lang_get( 'plugin_graph_title' );
$this->description = lang_get( 'plugin_graph_description' );
$this->name = d___('plugin_MantisGraph', 'Mantis Graphs');
$this->description = d___('plugin_MantisGraph', 'Official graph plugin.');
$this->page = 'config';

$this->version = '1.0';
$this->version = '2.0.0';
$this->requires = array(
'MantisCore' => '2.0.0',
);
Expand Down Expand Up @@ -94,26 +94,26 @@ function hooks( ) {
* generate summary menu
*/
function summary_menu( ) {
return array( '<a href="' . plugin_page( 'summary_jpgraph_page' ) . '">' . plugin_lang_get( 'menu_advanced_summary' ) . '</a>', );
return array( '<a href="' . plugin_page( 'summary_jpgraph_page' ) . '">' . d___('plugin_MantisGraph', 'Advanced Summary') . '</a>', );
}

/**
* generate graph filter menu
*/
function graph_filter_menu( ) {
return array( '<a href="' . plugin_page( 'bug_graph_page.php' ) . '">' . plugin_lang_get( 'graph_bug_page_link' ) . '</a>', );
return array( '<a href="' . plugin_page( 'bug_graph_page.php' ) . '">' . d___('plugin_MantisGraph', 'Graph') . '</a>', );
}

/**
* generate summary submenu
*/
function summary_submenu( ) {
return array( '<a href="' . helper_mantis_url( 'summary_page.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthese.png' ) . '" alt="" />' . plugin_lang_get( 'synthesis_link' ) . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_status.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthgraph.png' ) . '" alt="" />' . plugin_lang_get( 'status_link' ) . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_priority.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthgraph.png' ) . '" alt="" />' . plugin_lang_get( 'priority_link' ) . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_severity.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthgraph.png' ) . '" alt="" />' . plugin_lang_get( 'severity_link' ) . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_category.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthgraph.png' ) . '" alt="" />' . plugin_lang_get( 'category_link' ) . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_resolution.php' ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/synthgraph.png' ) . '" alt="" />' . plugin_lang_get( 'resolution_link' ) . '</a>',
return array( '<a href="' . helper_mantis_url( 'summary_page.php' ) . '"><img src="' . $t_icon_path . 'synthese.gif" alt="" />' . d___('plugin_MantisGraph', 'Synthesis') . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_status.php' ) . '"><img src="' . $t_icon_path . 'synthgraph.gif" alt="" />' . d___('plugin_MantisGraph', 'Per state') . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_priority.php' ) . '"><img src="' . $t_icon_path . 'synthgraph.gif" alt="" />' . d___('plugin_MantisGraph', 'Per priority') . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_severity.php' ) . '"><img src="' . $t_icon_path . 'synthgraph.gif" alt="" />' . d___('plugin_MantisGraph', 'Per severity') . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_category.php' ) . '"><img src="' . $t_icon_path . 'synthgraph.gif" alt="" />' . d___('plugin_MantisGraph', 'Per category') . '</a>',
'<a href="' . plugin_page( 'summary_graph_imp_resolution.php' ) . '"><img src="' . $t_icon_path . 'synthgraph.gif" alt="" />' . d___('plugin_MantisGraph', 'Per resolution') . '</a>',
);
}
}
22 changes: 11 additions & 11 deletions plugins/MantisGraph/core/Period.php
Expand Up @@ -256,17 +256,17 @@ function get_elapsed_days() {
*/
function period_selector( $p_control_name ) {
$t_periods = array(
0 => plugin_lang_get( 'period_none' ),
7 => plugin_lang_get( 'period_this_week' ),
8 => plugin_lang_get( 'period_last_week' ),
9 => plugin_lang_get( 'period_two_weeks' ),
1 => plugin_lang_get( 'period_this_month' ),
2 => plugin_lang_get( 'period_last_month' ),
3 => plugin_lang_get( 'period_this_quarter' ),
4 => plugin_lang_get( 'period_last_quarter' ),
5 => plugin_lang_get( 'period_year_to_date' ),
6 => plugin_lang_get( 'period_last_year' ),
10 => plugin_lang_get( 'period_select' ),
0 => d___('plugin_MantisGraph', 'None'),
7 => d___('plugin_MantisGraph', 'This Week'),
8 => d___('plugin_MantisGraph', 'Last Week'),
9 => d___('plugin_MantisGraph', 'Last Two Weeks'),
1 => d___('plugin_MantisGraph', 'This Month'),
2 => d___('plugin_MantisGraph', 'Last Month'),
3 => d___('plugin_MantisGraph', 'This Quarter'),
4 => d___('plugin_MantisGraph', 'Last Quarter'),
5 => d___('plugin_MantisGraph', 'Year to Date'),
6 => d___('plugin_MantisGraph', 'Last Year'),
10 => d___('plugin_MantisGraph', 'Arbitrary Dates'),
);
$t_default = gpc_get_int( $p_control_name, 0 );
$t_formatted_start = $this->get_start_formatted();
Expand Down
28 changes: 14 additions & 14 deletions plugins/MantisGraph/core/graph_api.php
Expand Up @@ -272,23 +272,23 @@ function graph_group( $p_metrics, $p_title = '', $p_graph_width = 350, $p_graph_
$tot = new BarPlot( array_values( $total ) );
$tot->SetFillColor( 'lightblue' );
$tot->SetWidth( 0.7 );
$tot->SetLegend( plugin_lang_get( 'legend_total' ) );
$tot->SetLegend( d___('plugin_MantisGraph', 'Total') );
$graph->Add( $tot );

$p1 = new BarPlot( array_values( $p_metrics['open'] ) );
$p1->SetFillColor( 'yellow' );
$p1->SetWidth( 1 );
$p1->SetLegend( plugin_lang_get( 'legend_opened' ) );
$p1->SetLegend( d___('plugin_MantisGraph', 'Opened') );

$p2 = new BarPlot( array_values( $p_metrics['closed'] ) );
$p2->SetFillColor( 'blue' );
$p2->SetWidth( 1 );
$p2->SetLegend( plugin_lang_get( 'legend_closed' ) );
$p2->SetLegend( d___('plugin_MantisGraph', 'Closed') );

$p3 = new BarPlot( array_values( $p_metrics['resolved'] ) );
$p3->SetFillColor( 'red' );
$p3->SetWidth( 1 );
$p3->SetLegend( plugin_lang_get( 'legend_resolved' ) );
$p3->SetLegend( d___('plugin_MantisGraph', 'Resolved') );

$gbplot = new GroupBarPlot( array( $p1, $p3, $p2 ) );
$graph->Add( $gbplot );
Expand Down Expand Up @@ -389,7 +389,7 @@ function graph_pie( $p_metrics, $p_title = '', $p_graph_width = 500, $p_graph_he
function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_height = 380 ) {

$t_graph_font = graph_get_font();
error_check( is_array( $p_metrics ) ? count( $p_metrics ) : 0, plugin_lang_get( 'cumulative' ) . ' ' . _( 'By Date (days)' ) );
error_check( is_array( $p_metrics ) ? count( $p_metrics ) : 0, d___('plugin_MantisGraph', 'Cumulative by date (days)') );

if ( plugin_config_get( 'eczlibrary' ) == ON ) {
$graph = new ezcGraphLineChart();
Expand All @@ -402,15 +402,15 @@ function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_hei
$graph->xAxis = new ezcGraphChartElementNumericAxis();

$graph->data[0] = new ezcGraphArrayDataSet( $p_metrics[0] );
$graph->data[0]->label = plugin_lang_get( 'legend_reported' );
$graph->data[0]->label = d___('plugin_MantisGraph', 'Reported');
$graph->data[0]->color = '#FF0000';

$graph->data[1] = new ezcGraphArrayDataSet( $p_metrics[1] );
$graph->data[1]->label = plugin_lang_get( 'legend_resolved' );
$graph->data[1]->label = d___('plugin_MantisGraph', 'Resolved');
$graph->data[1]->color = '#0000FF';

$graph->data[2] = new ezcGraphArrayDataSet( $p_metrics[2] );
$graph->data[2]->label = plugin_lang_get( 'legend_still_open' );
$graph->data[2]->label = d___('plugin_MantisGraph', 'Still Open');
$graph->data[2]->color = '#000000';

$graph->additionalAxis[2] = $nAxis = new ezcGraphChartElementNumericAxis();
Expand All @@ -433,7 +433,7 @@ function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_hei
$graph->driver->options->jpegQuality = 100;
$graph->driver->options->imageFormat = IMG_JPEG;

$graph->title = plugin_lang_get( 'cumulative' ) . ' ' . _( 'By Date (days)' );
$graph->title = d___('plugin_MantisGraph', 'Cumulative by date (days)');
$graph->options->font = $t_graph_font ;

$graph->renderToOutput( $p_graph_width, $p_graph_height);
Expand All @@ -457,7 +457,7 @@ function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_hei
$graph->SetY2Scale("lin");
$graph->SetMarginColor( 'white' );
$graph->SetFrame( false );
$graph->title->Set( plugin_lang_get( 'cumulative' ) . ' ' . _( 'By Date (days)' ) );
$graph->title->Set( d___('plugin_MantisGraph', 'Cumulative by date (days)') );
$graph->title->SetFont( $t_graph_font, FS_BOLD );

$graph->legend->Pos( 0.05, 0.9, 'right', 'bottom' );
Expand All @@ -482,19 +482,19 @@ function graph_cumulative_bydate( $p_metrics, $p_graph_width = 300, $p_graph_hei
$p1 = new LinePlot( $reported_plot, $plot_date );
$p1->SetColor( 'blue' );
$p1->SetCenter();
$p1->SetLegend( plugin_lang_get( 'legend_reported' ) );
$p1->SetLegend( d___('plugin_MantisGraph', 'Reported') );
$graph->AddY2( $p1 );

$p3 = new LinePlot( $still_open_plot, $plot_date );
$p3->SetColor( 'red' );
$p3->SetCenter();
$p3->SetLegend( plugin_lang_get( 'legend_still_open' ) );
$p3->SetLegend( d___('plugin_MantisGraph', 'Still Open') );
$graph->Add( $p3 );

$p2 = new LinePlot( $resolved_plot, $plot_date );
$p2->SetColor( 'black' );
$p2->SetCenter();
$p2->SetLegend( plugin_lang_get( 'legend_resolved' ) );
$p2->SetLegend( d___('plugin_MantisGraph', 'Resolved') );
$graph->AddY2( $p2 );

if( helper_show_query_count() ) {
Expand Down Expand Up @@ -932,7 +932,7 @@ function error_check( $p_bug_count, $p_title ) {
if( 0 == $p_bug_count ) {
$t_graph_font = graph_get_font();

error_text( $p_title, plugin_lang_get( 'not_enough_data' ) );
error_text( $title, d___('plugin_MantisGraph', 'Not enough data to create graph') );
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/MantisGraph/pages/bug_graph_bystatus.php
Expand Up @@ -149,7 +149,7 @@
ksort($t_view_status);
/* @todo - these should probably be separate strings, but in the summary page context,
the string is used as the title for all columns */
$t_label_string = lang_get( 'orct' ); //use the (open/resolved/closed/total) label
$t_label_string = d___('plugin_MantisGraph', '(open/resolved/closed/total)');
$t_label_strings = explode('/', mb_substr($t_label_string, 1, strlen($t_label_string)-2));

// add headers for table
Expand Down

0 comments on commit 52c646c

Please sign in to comment.