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 need to amend the labels for name and email fields in the comments form in my localized (Czech) Wordpress this way:

Emailová adresa    =>  Email
Webová stránka     =>  Web

What I did is that I've opened wp-content\languages\cs_CZ.po in poEdit, located the strings and compiled the new version of cs_CZ.mo. It worked well.

However, I imagine that when a new version of Wordpress comes out and the localization team releases new version of localization files, my changes will be overwritten, right?

So the question is, how to change the localized strings in a future-proof way?

I was thinking that maybe the comments mechanism provides some hooks to replace these two labels so I could create *.po and *.mo files in my theme directory but that doesn't seem to be generally applicable. What would be better would be to create a file like cs_CZ-custom.mo which would be able to override values already defined in the main language file but I'm not sure WordPress supports that.

Any suggestions?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

i think you need the gettext filter. lifted directly from the codex, here is an example:

add_filter( 'gettext', 'theme_change_comment_field_names', 20, 3 );
/**
 * Change comment form default field names.
 *
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function theme_change_comment_field_names( $translated_text, $text, $domain ) {

    if ( is_singular() ) {

        switch ( $translated_text ) {

            case 'Name' :

                $translated_text = __( 'First Name', 'theme_text_domain' );
                break;

            case 'Email' :

                $translated_text = __( 'Email Address', 'theme_text_domain' );
                break;
        }

    }

    return $translated_text;
}

http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext#Change_the_Comment_Form

share|improve this answer
    
Great answer, thanks. –  Borek Mar 16 '12 at 14:18

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.