Skip to content

3 Ways to translate Strings in the WordPress Backend

kalhh / Pixabay

When rebranding the Backend it is often very impotrant to reduce it to the minimum. Sometimes Plugin auzthors are very creative with picking names for their plugins. Even more some to add their company names to the bakcned menus. I really hate that behavior and it is not very nice.

Fortunately there are a couple of ways to change strings, texts and menu items in the backend. Even in pure text areas. Just try the following snippets. The one that works for you depends on what you want to change or translae. I prefer the gettext approach which is version 3 or 4.

Ways 1

//===================================================
//TRANSLATE STUFF WITH JQUERY
//===================================================

/*
function enym_admin_translate() {
    ? >
<script type="text/javascript">
    jQuery(document).ready(function($) {
        var replaced = $("body").html().replace(/SEO MASTER!/g,'SEO');
		$("body").html(replaced);
    });
</script>
    < ?php
}
add_action('admin_head', 'enym_admin_translate');
*/

Ways 2

//===================================================
//TRANSLATIONS: FORMINATOR, WP, THEME
//===================================================
//http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

function my_text_strings( $translated_text, $text, $domain ) {

	switch ( $translated_text ) {
		case 'Choose File' :
			$translated_text = __( 'Durchsuchen', 'forminator' );
			break;
		case 'No file chosen' :
			$translated_text = __( '', 'forminator' );
			break;
		case 'This field is required. Please upload a file' :
			$translated_text = __( 'Bitte fügen Sie eine Datei an', 'forminator' );
			break;
		case 'This field is required. Please input your name' :
			$translated_text = __( 'Dies ist ein Pflichtfeld, bitte geben Sie einen Namen ein', 'forminator' );
			break;	
		case 'This field is required. Please enter text' :
			$translated_text = __( 'Dies ist ein Pflichtfeld. Bitte geben Sie einen Text ein.', 'forminator' );
			break;	
		case 'This field is required. Please input a valid email' :
			$translated_text = __( 'Dies ist ein Pflichtfeld. Bitte geben Sie eine E-Mail-Adresse ein.', 'forminator' );
			break;	
		case 'This field is required. Please input a phone number' :
			$translated_text = __( 'Dies ist ein Pflichtfeld. Bitte geben Sie eine Telefonnummer ein.', 'forminator' );
			break;	
		case 'This field is required. Please check it.' :
			$translated_text = __( 'Dies ist ein Pflichtfeld. Bitte bestätigen Sie dieses Feld.', 'forminator' );
			break;	
		case 'Search' :
			$translated_text = __( 'Suchen', 'total' );
			break;		
		case 'Rank Math SEO' :
			$translated_text = __( 'Rank Math NEW', 'rankmath' );
			break;	
		case 'Rank Math' :
			$translated_text = __( 'Rank Math NEW 2', 'rankmath' );
			break;	
		case 'Search Meter' :
			$translated_text = __( 'Suchanfragen', 'forminator' );
			break;	
		case 'Search Results' :
			$translated_text = __( 'Suchergebnisse', 'total' );
			break;
	}
	return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );
//add_filter( 'ngettext', 'my_text_strings' );

Ways 3

//FORCED REPLACE NON GETTEXT STUFFS
function gv_admin_featured_image_tweaks() {
?>
<script type="text/javascript">
	jQuery(document).ready(function($) {
		var replaced = $("body").html().replace(/Rank Math/g,'SEO');
		$("body").html(replaced);
	});
</script>
<?php
}

Ways 4

Best version tihs really does the Trick! 🙂

add_filter(  'gettext',  'wps_translate_words_array'  );
add_filter(  'ngettext',  'wps_translate_words_array'  );

function wps_translate_words_array( $translated ) {

	$words = array(
		'Rank Math SEO' => 'SEO',
		'Rank Math' => 'SEO',
		'Search Meter' => 'Suchanfragen',
	);

	$translated = str_ireplace(  array_keys($words),  $words,  $translated );
	return $translated;
}  

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

An den Anfang scrollen