包装的元素$search
和$replace
阵列到__()
函数获取已翻译的字符串:
function search_replace_search() {
$search_term = esc_attr( apply_filters( \'the_search_query\', get_search_query( false ) ) ); // Get search term
$search = array(
__(\'word1\'),
__(\'word2\')
);
$replace = array(
__(\'something 1\'),
__(\'something 2\')
);
$replacePairs = array_combine($search, $replace);
echo strtr($search_term, $replacePairs);
}
echo search_replace_search();
如果你用你自己的
textdomain
:
$search = array(
__(\'word1\', \'my_textdomain\'),
__(\'word2\', \'my_textdomain\')
);
$replace = array(
__(\'something 1\', \'my_textdomain\'),
__(\'something 2\', \'my_textdomain\')
);
更多信息: