• Hi,

    I modified the code to allow translation (and edited french translation)

    You can apply following patch to allow translations in your code.

    Thanx in advance for new release with this patch ??

    diff –git a/safe-report-comments.php b/safe-report-comments.php
    index 82fc30d..e6070b3 100644
    — a/safe-report-comments.php
    +++ b/safe-report-comments.php
    @@ -10,10 +10,16 @@ Author: Thorsten Ott, Daniel Bachhuber, Automattic
    Author URI: https://automattic.com
    */

    +add_action( ‘init’, ‘safe_report_comments_load_textdomain’ );
    +function safe_report_comments_load_textdomain() {
    + load_plugin_textdomain( ‘safe-report-comments’, false, dirname( plugin_basename( __FILE__ ) ) . ‘/lang’ );
    +}
    +
    if ( !class_exists( “Safe_Report_Comments” ) ) {

    class Safe_Report_Comments {

    + private $_domain_name = ‘safe-report-comments’;
    private $_plugin_prefix = ‘srcmnt’;
    private $_admin_notices = array();
    private $_nonce_key = ‘flag_comment_nonce’;
    @@ -70,13 +76,13 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    public function backend_init() {
    do_action( ‘safe_report_comments_backend_init’ );

    – add_settings_field( $this->_plugin_prefix . ‘_enabled’, __( ‘Allow comment flagging’ ), array( $this, ‘comment_flag_enable’ ), ‘discussion’, ‘default’ );
    + add_settings_field( $this->_plugin_prefix . ‘_enabled’, __( ‘Allow comment flagging’, $this->_domain_name ), array( $this, ‘comment_flag_enable’ ), ‘discussion’, ‘default’ );
    register_setting( ‘discussion’, $this->_plugin_prefix . ‘_enabled’ );

    if ( ! $this->is_enabled() )
    return;

    – add_settings_field( $this->_plugin_prefix . ‘_threshold’, __( ‘Flagging threshold’ ), array( $this, ‘comment_flag_threshold’ ), ‘discussion’, ‘default’ );
    + add_settings_field( $this->_plugin_prefix . ‘_threshold’, __( ‘Flagging threshold’, $this->_domain_name ), array( $this, ‘comment_flag_threshold’ ), ‘discussion’, ‘default’ );
    register_setting( ‘discussion’, $this->_plugin_prefix . ‘_threshold’, array( $this, ‘check_threshold’ ) );
    add_filter(‘manage_edit-comments_columns’, array( $this, ‘add_comment_reported_column’ ) );
    add_action(‘manage_comments_custom_column’, array( $this, ‘manage_comment_reported_column’ ), 10, 2);
    @@ -185,7 +191,7 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    ?>
    <label for=”<?php echo $this->_plugin_prefix; ?>_enabled”>
    <input name=”<?php echo $this->_plugin_prefix; ?>_enabled” id=”<?php echo $this->_plugin_prefix; ?>_enabled” type=”checkbox” value=”1″ <?php if ( $enabled === true ) echo ‘ checked=”checked”‘; ?> />
    – <?php _e( “Allow your visitors to flag a comment as inappropriate.” ); ?>
    + <?php _e( “Allow your visitors to flag a comment as inappropriate.”, $this->_domain_name ); ?>
    </label>
    <?php
    }
    @@ -198,7 +204,7 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    ?>
    <label for=”<?php echo $this->_plugin_prefix; ?>_threshold”>
    <input size=”2″ name=”<?php echo $this->_plugin_prefix; ?>_threshold” id=”<?php echo $this->_plugin_prefix; ?>_threshold” type=”text” value=”<?php echo $threshold; ?>” />
    – <?php _e( “Amount of user reports needed to send a comment to moderation?” ); ?>
    + <?php _e( “Amount of user reports needed to send a comment to moderation?”, $this->_domain_name ); ?>
    </label>
    <?php
    }
    @@ -353,9 +359,9 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    */
    private function cond_die( $message ) {
    if ( isset( $_REQUEST[‘no_js’] ) && true == (boolean) $_REQUEST[‘no_js’] )
    – wp_die( __( $message ), “Safe Report Comments Notice”, array(‘response’ => 200 ) );
    + wp_die( $message, __( “Safe Report Comments Notice”, $this->_domain_name ), array(‘response’ => 200 ) );
    else
    – die( __( $message ) );
    + die( $message );
    }

    /*
    @@ -363,34 +369,38 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    */
    public function flag_comment() {
    if ( (int) $_REQUEST[ ‘comment_id’ ] != $_REQUEST[ ‘comment_id’ ] || empty( $_REQUEST[ ‘comment_id’ ] ) )
    – $this->cond_die( __( $this->invalid_values_message ) );
    + //$this->cond_die( __( $this->invalid_values_message ) );
    + $this->cond_die( __( ‘Cheating huh? <!– invalid values –>’, $this->_domain_name ) );

    $comment_id = (int) $_REQUEST[ ‘comment_id’ ];
    if ( $this->already_flagged( $comment_id ) )
    – $this->cond_die( __( $this->already_flagged_message ) );
    + //$this->cond_die( __( $this->already_flagged_message ) );
    + $this->cond_die( __( ‘It seems you already reported this comment. <!– already flagged –>’, $this->_domain_name ) );

    $nonce = $_REQUEST[ ‘sc_nonce’ ];
    // checking if nonces help
    if ( ! wp_verify_nonce( $nonce, $this->_plugin_prefix . ‘_’ . $this->_nonce_key ) )
    – $this->cond_die( __( $this->invalid_nonce_message ) );
    + //$this->cond_die( __( $this->invalid_nonce_message ) );
    + $this->cond_die( __( ‘It seems you already reported this comment. <!– nonce invalid –>’, $this->_domain_name ) );
    else {
    $this->mark_flagged( $comment_id );
    – $this->cond_die( __( $this->thank_you_message ) );
    + //$this->cond_die( __( $this->thank_you_message ) );
    + $this->cond_die( __( ‘Thank you for your feedback. We will look into it.’, $this->_domain_name ) );
    }

    }

    – public function print_flagging_link( $comment_id=”, $result_id=”, $text=’Report comment’ ) {
    – echo $this->get_flagging_link( $comment_id=”, $result_id=”, $text=’Report comment’ );
    + public function print_flagging_link( $comment_id, $result_id ) {
    + echo $this->get_flagging_link( $comment_id, $result_id );
    }

    /*
    * Output Link to report a comment
    */
    – public function get_flagging_link( $comment_id=”, $result_id=”, $text=’Report comment’ ) {
    + public function get_flagging_link( $comment_id=”, $result_id=” ) {
    global $in_comment_loop;
    if ( empty( $comment_id ) && !$in_comment_loop ) {
    – return __( ‘Wrong usage of print_flagging_link().’ );
    + return __( ‘Wrong usage of print_flagging_link().’, $this->_domain_name );
    }
    if ( empty( $comment_id ) ) {
    $comment_id = get_comment_ID();
    @@ -398,14 +408,15 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    else {
    $comment_id = (int) $comment_id;
    if ( !get_comment( $comment_id ) ) {
    – return __( ‘This comment does not exist.’ );
    + return __( ‘This comment does not exist.’, $this->_domain_name );
    }
    }
    if ( empty( $result_id ) )
    $result_id = ‘safe-comments-result-‘ . $comment_id;

    $result_id = apply_filters( ‘safe_report_comments_result_id’, $result_id );
    – $text = apply_filters( ‘safe_report_comments_flagging_link_text’, $text );
    + // use default translations to modify flagging_link_text, not a filter !
    + //$text = apply_filters( ‘safe_report_comments_flagging_link_text’, $text );

    $nonce = wp_create_nonce( $this->_plugin_prefix . ‘_’ . $this->_nonce_key );
    $params = array(
    @@ -417,10 +428,11 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    );

    if ( $this->already_flagged( $comment_id ) )
    – return __( $this->already_flagged_note );
    + return __( ‘<!– already flagged –>’, $this->_domain_name );
    + //return __( $this->already_flagged_note );

    return apply_filters( ‘safe_report_comments_flagging_link’, ‘
    – <span id=”‘ . $result_id . ‘”>‘ . __( $text ) . ‘</span>’ );
    + <span id=”‘ . $result_id . ‘”>_domain_name ) . ‘” onclick=”safe_report_comments_flag_comment( \” . $comment_id . ‘\’, \” . $nonce . ‘\’, \” . $result_id . ‘\’);”>’ . __( ‘Report comment’, $this->_domain_name ) . ‘</span>’ );

    }
    @@ -442,7 +454,7 @@ if ( !class_exists( “Safe_Report_Comments” ) ) {
    * Callback function to add the report counter to comments screen. Remove action manage_edit-comments_columns if not desired
    */
    public function add_comment_reported_column( $comment_columns ) {
    – $comment_columns[‘comment_reported’] = _x(‘Reported’, ‘column name’);
    + $comment_columns[‘comment_reported’] = _x(‘Reported’, ‘column name’, $this->_domain_name);
    return $comment_columns;
    }

Viewing 1 replies (of 1 total)
  • Thread Starter syjust

    (@syjust)

    Excuse me, I don’t where publish this patch.

    You can find the code view of patch bellow

    diff --git a/safe-report-comments.php b/safe-report-comments.php
    index 82fc30d..e6070b3 100644
    --- a/safe-report-comments.php
    +++ b/safe-report-comments.php
    @@ -10,10 +10,16 @@ Author: Thorsten Ott, Daniel Bachhuber, Automattic
     Author URI: https://automattic.com
     */
     
    +add_action( 'init', 'safe_report_comments_load_textdomain' );
    +function safe_report_comments_load_textdomain() {
    +	load_plugin_textdomain( 'safe-report-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
    +}
    +
     if ( !class_exists( "Safe_Report_Comments" ) ) {
     
     	class Safe_Report_Comments {
     
    +    private $_domain_name = 'safe-report-comments';
     		private $_plugin_prefix = 'srcmnt';
     		private $_admin_notices = array();
     		private $_nonce_key = 'flag_comment_nonce';
    @@ -70,13 +76,13 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     		public function backend_init() {
     			do_action( 'safe_report_comments_backend_init' );
     
    -			add_settings_field( $this->_plugin_prefix . '_enabled', __( 'Allow comment flagging' ), array( $this, 'comment_flag_enable' ), 'discussion', 'default' );
    +			add_settings_field( $this->_plugin_prefix . '_enabled', __( 'Allow comment flagging', $this->_domain_name ), array( $this, 'comment_flag_enable' ), 'discussion', 'default' );
     			register_setting( 'discussion', $this->_plugin_prefix . '_enabled' );
     
     			if ( ! $this->is_enabled() )
     				return;
     
    -			add_settings_field( $this->_plugin_prefix . '_threshold', __( 'Flagging threshold' ), array( $this, 'comment_flag_threshold' ), 'discussion', 'default' );
    +			add_settings_field( $this->_plugin_prefix . '_threshold', __( 'Flagging threshold', $this->_domain_name ), array( $this, 'comment_flag_threshold' ), 'discussion', 'default' );
     			register_setting( 'discussion', $this->_plugin_prefix . '_threshold', array( $this, 'check_threshold' ) );
     			add_filter('manage_edit-comments_columns', array( $this, 'add_comment_reported_column' ) );
     			add_action('manage_comments_custom_column', array( $this, 'manage_comment_reported_column' ), 10, 2);
    @@ -185,7 +191,7 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     			?>
     			<label for="<?php echo $this->_plugin_prefix; ?>_enabled">
     				<input name="<?php echo $this->_plugin_prefix; ?>_enabled" id="<?php echo $this->_plugin_prefix; ?>_enabled" type="checkbox" value="1" <?php if ( $enabled === true ) echo ' checked="checked"'; ?> />   
    -				<?php _e( "Allow your visitors to flag a comment as inappropriate." ); ?>
    +				<?php _e( "Allow your visitors to flag a comment as inappropriate.", $this->_domain_name ); ?>
     			</label>
     			<?php
     		}
    @@ -198,7 +204,7 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     			?>
     			<label for="<?php echo $this->_plugin_prefix; ?>_threshold">
     				<input size="2" name="<?php echo $this->_plugin_prefix; ?>_threshold" id="<?php echo $this->_plugin_prefix; ?>_threshold" type="text" value="<?php echo $threshold; ?>" />   
    -				<?php _e( "Amount of user reports needed to send a comment to moderation?" ); ?>
    +				<?php _e( "Amount of user reports needed to send a comment to moderation?", $this->_domain_name ); ?>
     			</label>
     			<?php
     		}
    @@ -353,9 +359,9 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     		 */
     		private function cond_die( $message ) {
     			if ( isset( $_REQUEST['no_js'] ) && true == (boolean) $_REQUEST['no_js'] )
    -				wp_die( __( $message ), "Safe Report Comments Notice", array('response' => 200 ) );
    +				wp_die( $message, __( "Safe Report Comments Notice", $this->_domain_name ), array('response' => 200 ) );
     			else
    -				die( __( $message ) );
    +				die( $message );
     		}
     		
     		/* 
    @@ -363,34 +369,38 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     		 */
     		public function flag_comment() {		
     			if ( (int) $_REQUEST[ 'comment_id' ] != $_REQUEST[ 'comment_id' ] || empty( $_REQUEST[ 'comment_id' ] ) )
    -				$this->cond_die( __( $this->invalid_values_message ) );
    +				//$this->cond_die( __( $this->invalid_values_message ) );
    +				$this->cond_die( __( 'Cheating huh? <!-- invalid values -->', $this->_domain_name ) );
     			
     			$comment_id = (int) $_REQUEST[ 'comment_id' ];
     			if ( $this->already_flagged( $comment_id ) )
    -				$this->cond_die( __( $this->already_flagged_message ) );
    +				//$this->cond_die( __( $this->already_flagged_message ) );
    +				$this->cond_die( __( 'It seems you already reported this comment. <!-- already flagged -->', $this->_domain_name ) );
     				
     			$nonce = $_REQUEST[ 'sc_nonce' ];
     			// checking if nonces help
     			if ( ! wp_verify_nonce( $nonce, $this->_plugin_prefix . '_' . $this->_nonce_key ) ) 
    -				$this->cond_die( __( $this->invalid_nonce_message ) );
    +				//$this->cond_die( __( $this->invalid_nonce_message ) );
    +				$this->cond_die( __( 'It seems you already reported this comment. <!-- nonce invalid -->', $this->_domain_name ) );
     			else {
     				$this->mark_flagged( $comment_id );
    -				$this->cond_die( __( $this->thank_you_message ) );
    +				//$this->cond_die( __( $this->thank_you_message ) );
    +				$this->cond_die( __( 'Thank you for your feedback. We will look into it.', $this->_domain_name ) );
     			}
     			
     		}
     		
    -		public function print_flagging_link( $comment_id='', $result_id='', $text='Report comment' ) {
    -			echo $this->get_flagging_link( $comment_id='', $result_id='', $text='Report comment' );
    +		public function print_flagging_link( $comment_id, $result_id ) {
    +			echo $this->get_flagging_link( $comment_id, $result_id );
     		}
     		
     		/* 
     		 * Output Link to report a comment
     		 */
    -		public function get_flagging_link( $comment_id='', $result_id='', $text='Report comment' ) {
    +		public function get_flagging_link( $comment_id='', $result_id='' ) {
     			global $in_comment_loop;
     			if ( empty( $comment_id ) && !$in_comment_loop ) {
    -				return __( 'Wrong usage of print_flagging_link().' );
    +				return __( 'Wrong usage of print_flagging_link().', $this->_domain_name );
     			}
     			if ( empty( $comment_id ) ) {
     				$comment_id = get_comment_ID();
    @@ -398,14 +408,15 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     			else {
     				$comment_id = (int) $comment_id;
     				if ( !get_comment( $comment_id ) ) {
    -					return __( 'This comment does not exist.' );
    +					return __( 'This comment does not exist.', $this->_domain_name );
     				}
     			}
     			if ( empty( $result_id ) )
     				$result_id = 'safe-comments-result-' . $comment_id;
     				
     			$result_id = apply_filters( 'safe_report_comments_result_id', $result_id );
    -			$text = apply_filters( 'safe_report_comments_flagging_link_text', $text );
    +      // use default translations to modify flagging_link_text, not a filter !
    +			//$text = apply_filters( 'safe_report_comments_flagging_link_text', $text );
     			
     			$nonce = wp_create_nonce( $this->_plugin_prefix . '_' . $this->_nonce_key );
     			$params = array( 
    @@ -417,10 +428,11 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     			);
     			
     			if ( $this->already_flagged( $comment_id ) )
    -				return __( $this->already_flagged_note );
    +				return __( '<!-- already flagged -->', $this->_domain_name );
    +				//return __( $this->already_flagged_note );
     			
     			return apply_filters( 'safe_report_comments_flagging_link', '
    -			<span id="' . $result_id . '"><a class="hide-if-no-js" href="javascript:void(0);" onclick="safe_report_comments_flag_comment( \'' . $comment_id . '\', \'' . $nonce . '\', \'' . $result_id . '\');">' . __( $text ) . '</a></span>' );
    +			<span id="' . $result_id . '"><a class="hide-if-no-js" href="javascript:void(0);" title="'.__( 'Report comment as inappropriate', $this->_domain_name ) . '" onclick="safe_report_comments_flag_comment( \'' . $comment_id . '\', \'' . $nonce . '\', \'' . $result_id . '\');">' . __( 'Report comment', $this->_domain_name ) . '</a></span>' );
     			
     			
     		}
    @@ -442,7 +454,7 @@ if ( !class_exists( "Safe_Report_Comments" ) ) {
     		 * Callback function to add the report counter to comments screen. Remove action manage_edit-comments_columns if not desired
     		 */
     		public function add_comment_reported_column( $comment_columns ) {
    -			$comment_columns['comment_reported'] = _x('Reported', 'column name');
    +			$comment_columns['comment_reported'] = _x('Reported', 'column name', $this->_domain_name);
     			return $comment_columns;
     		}
     		
    -- 
Viewing 1 replies (of 1 total)
  • The topic ‘translation patch’ is closed to new replies.