To clarify the “plugin/functions.php” issue, see: Where do I put the code snippets I found here or somewhere else on the web?
You can use the following modified version from toscho’s Retranslate Plugin. I changed post_type
for pagenow
. Configure the translations in the final array.
<?php
/*
Plugin Name: Retranslate Profile Page
Description: Adds translations.
Version: 0.1b
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL v2
*/
class Toscho_Retrans {
// store the options
protected $params;
/**
* Set up basic information
*
* @param array $options
* @return void
*/
public function __construct( array $options ) {
$defaults = array (
'domain' => 'default'
, 'context' => 'backend'
, 'replacements' => array()
, 'pagenow' => array()
);
$this->params = array_merge( $defaults, $options );
// When to add the filter
$hook = 'backend' == $this->params['context']
? 'admin_head' : 'template_redirect';
add_action( $hook, array ( $this, 'register_filter' ) );
}
/**
* Conatiner for add_filter()
* @return void
*/
public function register_filter() {
add_filter( 'gettext', array ( $this, 'translate' ), 10, 3 );
}
/**
* The real working code.
*
* @param string $translated
* @param string $original
* @param string $domain
* @return string
*/
public function translate( $translated, $original, $domain ) {
// exit early
if ( 'backend' == $this->params['context'] ) {
global $pagenow;
if ( ! empty ( $pagenow )
&& ! in_array( $pagenow, $this->params['pagenow'] ) )
{
return $translated;
}
}
if ( $this->params['domain'] !== $domain ) {
return $translated;
}
// Finally replace
return strtr( $original, $this->params['replacements'] );
}
}
// Sample code
// Replace 'Name' and 'Personal Options' on the profile page
$Toscho_Retrans = new Toscho_Retrans(
array (
'replacements' => array (
'Name' => 'The Name'
, 'Personal Options' => 'The Options'
, 'Something Else' => 'Lorem Ipsum'
)
, 'pagenow' => array ( 'profile.php', 'edit-user.php' )
)
);
Another option is to use jQuery:
add_action( 'admin_print_footer_scripts', 'rename_profile_h3' );
function rename_profile_h3()
{
global $pagenow;
if( !in_array( $pagenow, array('profile.php', 'edit-user.php') ) )
return;
?>
<script>
jQuery(document).ready(function($){
$("#your-profile").find("h3:contains('Name')").text('The Name');
$("#your-profile").find("h3:contains('Personal Options')").text('The Options');
});
</script>
<?php
}
Both examples are running in the admin pages Profile and User Edit.