Rename Lables


function learn_gettext( $translation, $text ) {
    $dirty = false;
    $strings_map = array(
        'group'     => 'class',
        'groups'    => 'classes',
        'Group'     => 'Class',
        'Groups'    => 'Classes',
        'course'     => 'lesson',
        'courses'    => 'lessons',
        'Course'     => 'Lesson',
        'Courses'    => 'Lessons',
        'assignment'     => 'tests',
        'assignments'    => 'tests',
        'Assignment'     => 'Test',
        'Assignments'    => 'Tests'
    );
    $text_words = explode( ' ', $text );
    // Try to find strings to be replaced and preserve the punctuation
    foreach ( $text_words as $k => $word ) {
        $w = trim( $word, '.,:!?-_()' );
        if ( isset( $strings_map[ $w ] ) ) {
            $text_words[ $k ] = str_replace( $w, $strings_map[ $w ], $word );
            $dirty = true;
        }
    }
    if ( $dirty ) {
        return implode( ' ', $text_words );
    }
    return $translation;
}
add_filter( 'gettext', 'learn_gettext', 10, 2 );
Advertisements

5 thoughts on “Rename Lables

  1. Hello Karthik,
    I’m as novice as novice can be to programming. Where do I place the code for it to work? Thanks for your help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s