Use gettext filter to modify fronted text

This commit is contained in:
Brian Miyaji
2014-06-13 23:21:59 +10:00
parent 89ce3ee84e
commit 5ba33fd629
21 changed files with 90 additions and 124 deletions

View File

@@ -43,14 +43,16 @@ class SP_Settings_Text extends SP_Settings_Page {
);
$strings = sp_get_text_options();
$options = get_option( 'sportspress_text' );
foreach ( $strings as $key => $value ):
foreach ( $strings as $string ):
$settings[] = array(
'title' => $value,
'id' => 'sportspress_' . $key . '_text',
'default' => '',
'placeholder' => $value,
'type' => 'text',
'title' => $string,
'id' => 'sportspress_text[' . $string . ']',
'default' => '',
'placeholder' => $string,
'value' => sp_array_value( $options, $string, null ),
'type' => 'text',
);
endforeach;
@@ -58,6 +60,14 @@ class SP_Settings_Text extends SP_Settings_Page {
return apply_filters( 'sportspress_text_settings', $settings ); // End event settings
}
/**
* Save settings
*/
public function save() {
if ( isset( $_POST['sportspress_text'] ) )
update_option( 'sportspress_text', $_POST['sportspress_text'] );
}
}
endif;

View File

@@ -316,7 +316,7 @@ class SP_League_Table extends SP_Custom_Post{
unset( $columns[ $key ] );
endif;
endforeach;
$labels = array_merge( array( 'name' => SP()->text->string('Team') ), $columns );
$labels = array_merge( array( 'name' => __( 'Team', 'sportspress' ) ), $columns );
$merged[0] = $labels;
return $merged;
endif;

View File

@@ -358,7 +358,7 @@ class SP_Player_List extends SP_Custom_Post {
endif;
endforeach;
$labels = array( 'name' => SP()->text->string('Player') );
$labels = array( 'name' => __( 'Player', 'sportspress' ) );
if ( in_array( 'team', $this->columns ) )
$labels['team'] = __( 'Team', 'sportspress' );

View File

@@ -316,7 +316,7 @@ class SP_Player extends SP_Custom_Post {
unset( $columns[ $key ] );
endif;
endforeach;
$labels = array_merge( array( 'name' => SP()->text->string('Season'), 'team' => SP()->text->string('Team') ), $columns );
$labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ) ), $columns );
$merged[0] = $labels;
return $merged;
endif;

View File

@@ -252,7 +252,7 @@ class SP_Team extends SP_Custom_Post {
if ( $admin ):
return array( $columns, $data, $placeholders, $merged, $leagues_seasons );
else:
$labels = array_merge( array( 'name' => SP()->text->string('Season') ), $columns );
$labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns );
$merged[0] = $labels;
return $merged;
endif;

View File

@@ -1,49 +0,0 @@
<?php
/**
* SportsPress text
*
* The SportsPress text class stores editable strings.
*
* @class SP_Text
* @version 0.8
* @package SportsPress/Classes
* @category Class
* @author ThemeBoy
*/
class SP_Text {
/** @var array Array of text */
public $data;
/**
* Constructor for the text class - defines all editable strings.
*
* @access public
* @return void
*/
public function __construct() {
$this->data = sp_get_text_options();
}
public function __get( $key ) {
return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
}
public function __set( $key, $value ){
$this->data[ $key ] = $value;
}
public function string( $string ){
if ( is_admin() )
return $string;
$key = str_replace( '-', '_', sanitize_title( $string ) );
if ( array_key_exists( $key, $this->data ) ):
$string = get_option( 'sportspress_' . $key . '_text' );
return ( empty( $string ) ? $this->data[ $key ] : $string );
else:
return $string;
endif;
}
}

View File

@@ -2387,35 +2387,35 @@ function sp_get_sport_presets() {
*/
function sp_get_text_options() {
$strings = apply_filters( 'sportspress_text', array(
'article' => __( 'Article', 'sportspress' ),
'current_team' => __( 'Current Team', 'sportspress' ),
'date' => __( 'Date', 'sportspress' ),
'details' => __( 'Details', 'sportspress' ),
'event' => __( 'Event', 'sportspress' ),
'league' => __( 'League', 'sportspress' ),
'nationality' => __( 'Nationality', 'sportspress' ),
'outcome' => __( 'Outcome', 'sportspress' ),
'past_teams' => __( 'Past Teams', 'sportspress' ),
'played' => __( 'Played', 'sportspress' ),
'player' => __( 'Player', 'sportspress' ),
'pos' => __( 'Pos', 'sportspress' ),
'position' => __( 'Position', 'sportspress' ),
'preview' => __( 'Preview', 'sportspress' ),
'rank' => __( 'Rank', 'sportspress' ),
'recap' => __( 'Recap', 'sportspress' ),
'team_results' => __( 'Team Results', 'sportspress' ),
'season' => __( 'Season', 'sportspress' ),
'staff' => __( 'Staff', 'sportspress' ),
'substitutes' => __( 'Substitutes', 'sportspress' ),
'team' => __( 'Team', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ),
'time' => __( 'Time', 'sportspress' ),
'timeresults' => __( 'Time/Results', 'sportspress' ),
'total' => __( 'Total', 'sportspress' ),
'venue' => __( 'Venue', 'sportspress' ),
'view_all_events' => __( 'View all events', 'sportspress' ),
'view_all_players' => __( 'View all players', 'sportspress' ),
'view_full_table' => __( 'View full table', 'sportspress' ),
__( 'Article', 'sportspress' ),
__( 'Current Team', 'sportspress' ),
__( 'Date', 'sportspress' ),
__( 'Details', 'sportspress' ),
__( 'Event', 'sportspress' ),
__( 'League', 'sportspress' ),
__( 'Nationality', 'sportspress' ),
__( 'Outcome', 'sportspress' ),
__( 'Past Teams', 'sportspress' ),
__( 'Played', 'sportspress' ),
__( 'Player', 'sportspress' ),
__( 'Pos', 'sportspress' ),
__( 'Position', 'sportspress' ),
__( 'Preview', 'sportspress' ),
__( 'Rank', 'sportspress' ),
__( 'Recap', 'sportspress' ),
__( 'Team Results', 'sportspress' ),
__( 'Season', 'sportspress' ),
__( 'Staff', 'sportspress' ),
__( 'Substitutes', 'sportspress' ),
__( 'Team', 'sportspress' ),
__( 'Teams', 'sportspress' ),
__( 'Time', 'sportspress' ),
__( 'Time/Results', 'sportspress' ),
__( 'Total', 'sportspress' ),
__( 'Venue', 'sportspress' ),
__( 'View all events', 'sportspress' ),
__( 'View all players', 'sportspress' ),
__( 'View full table', 'sportspress' ),
));
asort( $strings );
return $strings;

View File

@@ -190,7 +190,11 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
endswitch;
endif;
else:
if ( ! current_theme_supports( 'sportspress' ) && $untranslated_text == 'Archives' && is_tax( 'sp_venue' ) ):
if ( $domain == 'sportspress' ):
if ( ! empty( SP()->text[ $untranslated_text ] ) ):
$translated_text = SP()->text[ $untranslated_text ];
endif;
elseif ( ! current_theme_supports( 'sportspress' ) && $untranslated_text == 'Archives' && is_tax( 'sp_venue' ) ):
$slug = get_query_var( 'sp_venue' );
if ( $slug ):
$venue = get_term_by( 'slug', $slug, 'sp_venue' );