• Resolved CarlosDev

    (@producciones-20)


    Hi there!
    I’m using WP-Multilang plugin to translate my website (https://www.ads-software.com/plugins/wp-multilang/), I did create a custom login button and embedded it in the header.php but now I need to translate it to English and I have no clue where or how to do it.
    Any help in this regard will be much appreciated. Thanks!

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi @producciones-20,

    Please follow this codex link https://codex.www.ads-software.com/I18n_for_WordPress_Developers

    All the strings should be in translation functions, then you can use any plugin for the transalation.

    Thanks

    Thread Starter CarlosDev

    (@producciones-20)

    Hi @prashantvatsh, thanks for replying, I’m afraid I don’t understand what you mean, I’m already using a plugin called WP-Multilang and I would like to know if there is any option to translate header.php with this plugin. Is this what you meant?, If so, then sorry, I’m not expert with the codex. Thanks!

    If you want to translate just that login button string, you can place this code in your child theme’s functions.php file:

    add_filter( 'gettext', 'ps_change_login_string', 20, 3 );
    function ps_change_login_string( $translated_text, $text, $domain ) {
    
            switch ( $translated_text ) {
    
                case 'your string here' :
    
                    $translated_text = __( 'translated string', 'theme_text_domain' );
                    break;
    
            }
    
        return $translated_text;
    }

    Replace the string with your text.

    Thread Starter CarlosDev

    (@producciones-20)

    Didn’t work, maybe am I doing something wrong?

    Here’s the code I added in my functions.php:

    add_filter( ‘gettext’, ‘ps_change_login_string’, 20, 3 );
    function ps_change_login_string( $translated_text, $text, $domain ) {

    switch ( $translated_text ) {

    case ‘Client Login’ :

    $translated_text = __( ‘Client Login’, ‘theme_text_domain’ );
    break;

    }

    return $translated_text;
    }

    Did I correctly replace the string?

    You have placed the same string at both the places.

    $translated_text = __( ‘Client Login’, ‘theme_text_domain’ );

    Here you need to paste the string that you want to show that means translated string.

    Thread Starter CarlosDev

    (@producciones-20)

    Oh I see, I did change it but still not working:

    add_filter( ‘gettext’, ‘ps_change_login_string’, 20, 3 );
    function ps_change_login_string( $translated_text, $text, $domain ) {

    switch ( $translated_text ) {

    case ‘Ingreso Cliente’ :

    $translated_text = __( ‘Client Login’, ‘theme_text_domain’ );
    break;

    }

    return $translated_text;
    }

    Then, I think you need to check your HTML. You must have written the text Ingreso Cliente static instead of writing this like <?php _e(‘Ingreso Cliente’, ‘text-domain’);?> that’s why it is not getting translated.

    Thread Starter CarlosDev

    (@producciones-20)

    Hi, I fixed my html and added <?php _e(‘Ingreso Cliente’, ‘text-domain’);?> but now both buttons are in english.

    • This reply was modified 6 years, 8 months ago by CarlosDev.
    Thread Starter CarlosDev

    (@producciones-20)

    This is my html code, maybe something’s wrong here?

    <div class=”botonclientes”>
    <button type=”button” class=”clientes”> <span class=”dashicons dashicons-arrow-right-alt2″></span><?php _e(‘Ingreso Cliente’, ‘text-domain’);?>
    </button>
    </div>

    Please change text-domain to your theme’s text domain and also remove the code I have given to you.

    Thread Starter CarlosDev

    (@producciones-20)

    Thanks for your answer @prashantvatsh
    I’m afraid I don’t understand, you’re asking me to remove the code you gave me but change the theme’s text domain?
    What code should I remove, the one I added in html or the one I added in functions.php? Where should I change the text-domain?

    • This reply was modified 6 years, 8 months ago by CarlosDev.

    The ‘text-domain’ in HTML needs to be changed to theme’s text domain. You can find that in the style.css file of your theme and it will be written as Text Domain: my-theme

    Just copy the value after the colon(:) and paste it in place of ‘text-domain’ in your HTML and then remove the code I have given and I think you have pasted that in functions.php. Then check back if the translation is working fine or not.

    Thread Starter CarlosDev

    (@producciones-20)

    I got it!
    Thank you very much for your time @prashantvatsh I really appreciate it ??

    Glad that it worked for you. Please mark this resolved.

    Thread Starter CarlosDev

    (@producciones-20)

    Ok, thanks.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Translating Theme’s Core Files’ is closed to new replies.