Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I’d like to make a tiny change in one of my custom taxonomy admin panels: rename the label "Description" to "Title".

share|improve this question

2 Answers 2

Checking the file /wp-admin/edit-tags.php, we see that it's using the function _ex() to translate the string Description.

Following _ex path, we find that it finally uses the filter gettext_with_context to translate the text. So, it is possible to hook into this and modify the desired string.

The following code is a simplified version of @toscho's Retranslate plugin. Please, check the original for a much more versatile code.

Use as a plugin or simply copy the code into your theme's functions.php file.
In this example, we have an extra context and replacement.
To solve the OP Question, remove the second array item from both.

Configuration values in $params_71992:

  • context of the string, as seen in /wp-admin/edit-tags.php
  • replacements, strings for original and desired translation
  • taxonomy, name of the taxonomy, category, post_tags or custom-taxonomy
<?php
/*
Plugin Name:    Translate Taxonomy Admin Strings
Plugin URI:     http://wordpress.stackexchange.com/q/71992/12615
Description:    Translate specific strings in admin screens Edit Tag
Version:        0.1
Author:         Rodolfo Buaiz
License:        GPL v2
*/


/** 
    Configuration 
    @params_71992['context']        as defined in /wp-admin/edit-tags.php
    @params_71992['replacements']   original text and translation
    @params_71992['taxonomy']       name of the taxonomy (category, post_tag, custom_taxonomy)
 */
$params_71992 = array (
        'context'       => array (
                'Taxonomy Description'
            ,   'Taxonomy Name'
        )
    ,   'replacements'  => array ( 
                'Description'   => 'Title'
            ,   'Name'          => 'The Name'
        )
    ,   'taxonomy'      => 'category'
);

// Run only in Edit Tags screens
add_action( 'admin_head-edit-tags.php', 'wpse_71992_register_filter' );

function wpse_71992_register_filter() 
{
    add_filter( 'gettext_with_context', 'wpse_71992_translate', 10, 4 );
}

function wpse_71992_translate( $translated, $original, $context, $domain ) 
{
    global $params_71992;

    // If not our taxonomy, exit early
    if( $params_71992['taxonomy'] !== $_GET['taxonomy'] )
        return $translated;

    // Text is not from WordPress, exit early
    if ( 'default' !== $domain ) 
        return $translated;

    // Check desired contexts
    if( !in_array( $context, $params_71992['context'] ) )
        return $translated;

    // Finally replace
    return strtr( $original, $params_71992['replacements'] );
}
share|improve this answer
    
Thank you very much for the code and the detailed description—works perfectly! Is it also possible to change the annotation beneath the textarea or the head in the table on the right? –  user1706680 Nov 9 '12 at 13:19
    
@user1706680 - Those use the function __(), which this plugin doesn't target. For that, use the plugin Retranslate linked in the Answer, and check the exact strings inside /wp-admin/edit-tags.php. –  brasofilo Nov 9 '12 at 16:24
function my_gettext_with_context($translated, $text, $context, $domain) {
    if (is_admin() AND $text == "Description" AND $context == "Taxonomy Description") {
        return __("Title");
    }

    return $translated;
}
add_filter('gettext_with_context', 'my_gettext_with_context', 20, 3);
share|improve this answer
    
Thanks for that but in the menu bar left under "Posts" it lets "Add New", "Categories" and "Tags" disappear. –  user1706680 Nov 9 '12 at 0:20
    
@toscho fixed the bug that was probably causing those things to disappear. (thanks @toscho!) –  totels Nov 9 '12 at 12:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.