在事件管理器插件中,语言文件位于“events-manager\includes\langs”路径中。
https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
我使用了事件管理器插件中使用的一些文本。
尝试
add_filter( 'gettext', 'change_event_manager_text', 20, 3 );
/*
* Ref: https://stackoverflow.com/questions/44450192/how-to-replace-string-with-another-string-and-keep-case-in-php-and-mysql
*/
function replaceWithCase($source, $replacement, $string, $pos = 0) {
while (($pos = strpos(strtolower($string), strtolower($source), $pos))!== false) {
$substr = mb_substr($string, $pos, strlen($source));
$remaining = mb_substr($string, $pos + strlen($source));
if (ctype_upper($substr)) {
$string = substr_replace($string,strtoupper($replacement),$pos,strlen($source));
continue;
}
$substrParts = preg_split('//u', $substr, null, PREG_SPLIT_NO_EMPTY);
$replaceParts = preg_split('//u', $replacement, null, PREG_SPLIT_NO_EMPTY);
$newWord = '';
foreach ($replaceParts as $k => $rp) {
if (array_key_exists($k,$substrParts))
$newWord .= ctype_upper($substrParts[$k]) ? mb_strtoupper($rp) : mb_strtolower($rp);
else
$newWord .= $rp;
}
$string = substr_replace($string,$newWord,$pos,strlen($source));
$pos = $pos + strlen($source);
}
return $string;
}
function change_event_manager_text( $translated_text, $text, $domain ) {
if( $domain === "events-manager" ) {
// some translated_text in event manager
// see includes\langs\
$event_manager_texts = array(
"Event",
"View/Edit Event",
"event",
"Recurring Event",
"Edit Event",
"Add Event",
"Displaying Event",
"Published Event",
"Add New Event",
"New Event",
"View Event",
"Parent Event",
"Add Recurring Event",
"Add New Recurring Event",
"Edit Recurring Event",
"New Recurring Event",
"Search Recurring Events",
"No Recurring Events Found",
"No Recurring Events Found in Trash",
"Parent Recurring Event",
"Duplicate this event",
"Enable registration for this event",
"Not a Group Event"
);
if( in_array( $translated_text , $event_manager_texts) ) {
return replaceWithCase('event', 'conversation', $translated_text );
}
}
return $translated_text;
}