Wrap the elements of $search
and $replace
arrays into __()
function to get the translated strings:
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();
If you use your own textdomain
:
$search = array(
__('word1', 'my_textdomain'),
__('word2', 'my_textdomain')
);
$replace = array(
__('something 1', 'my_textdomain'),
__('something 2', 'my_textdomain')
);
More information: