要澄清“plugin/functions.php”问题,请参阅:Where do I put the code snippets I found here or somewhere else on the web?
您可以使用以下修改版本toscho\'s Retranslate Plugin. 我改变了post_type
对于pagenow
. 在最终数组中配置翻译。
<?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\' )
)
);
另一种选择是使用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
}
这两个示例都在管理页面概要文件和用户编辑中运行。