这些电子邮件中的大部分文本都是可翻译的,这意味着我们可以利用WP的gettext 滤器我在网上找到了以下实现翻译的方法,但找不到原始源代码。
首先定义过滤器挂钩:
add_filter(\'gettext\', [new AddAction(), \'gqa_text_strings\'], 20, 3);
然后您的翻译功能:
/**
* Change a few text strings related to the login/registration process
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*
* @param $translated_text
* @param $text
* @param $domain
*
* @return string
*/
function gqa_text_strings($translated_text, $text, $domain)
{
switch ( $translated_text ) {
case \'Get your own %s account in seconds\' :
$translated_text = __(\'Request access to %s\', \'gqa\');
break;
case \'We send your registration email to this address. (Double-check your email address before continuing.)\' :
$translated_text = __(\'\', \'gqa\');
break;
case \'But, before you can start using your new username, <strong>you must activate it</strong>.\' :
$translated_text = __(\'An email with login instructions has been sent to the address you provided.\', \'gqa\');
break;
case "Check your inbox at %s and click the link given." :
$translated_text = __(\'Check your inbox at %s.\', \'gqa\');
break;
case \'If you do not activate your username within two days, you will have to sign up again.\' :
$translated_text = __(\'\', \'gqa\');
break;
// Subject line for new user registration email
case \'New %1$s User: %2$s\' :
$translated_text = __(\'Your account information\');
break;
// Error message when registering a new account with an already used username.
case \'That username is currently reserved but may be available in a couple of days.\' :
$translated_text = __(\'A user with that username already exists. Do you already have an account? Please contact site administrators or try again.\');
break;
// Error message when registering a new account with an already used email address.
case \'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.\' :
$translated_text = __(\'That email address has already been assigned to an account. Do you already have an account? Please contact site administrators or try again\');
break;
}
return $translated_text;
}
如果字符串包含在
__() function. 因此,在您的情况下,您可以添加以下内容:
case \'Hi, You\\\'ve been invited to join \\\'%1$s\\\' at
%2$s as a %3$s. If you do not want to join this site please ignore
this email. This invitation will expire in a few days. Please click the following link to activate your user account: %%s\' :
$translated_text = __(\'Whatever you want the email to say\', \'gqa\');
break;