[Resolved] Polylang translate texts in pages / elements / media….

Home Forums Support [Resolved] Polylang translate texts in pages / elements / media….

Home Forums Support Polylang translate texts in pages / elements / media….

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #786136
    Kilian

    Hi, there, I need to translate my website into 4 languages. I have just started the process by using Polylang, but want to know if I’m doing it the right way, or if there is an easier way of doing it.

    As per my knowledge, I have to duplicate all pages and change the texts. Lets say, for example, having 4 “home” pages, 4 “galleries” pages, 4 “contact” pages, etc.

    And to change the text in Appearence > Elements, I have to duplicate all the “home hero”, “site hero”…

    But it seems tons of work to do it this way.

    Is there any other way I can translate the texts without duplicating all the pages 4 times? I guess if I do it this way, the website will be really heavy since I will have the same images and context multiplied by 4.

    Thanks in advance for your help!

    #786148
    Kilian

    By the way, I have tried creating two “home hero” in order to change the text of the header in my front page, but I’m not able to link one home hero to a specific language… How can I translate the text header to different languages?

    #786343
    Kilian

    Actually, to translate the text of my homepage header (where it says “3D rendering and architectural visualization”) is the only problem at the moment. I can’t figure out how to change that into different languages.

    #786414
    Tom
    Lead Developer
    Lead Developer

    I believe that’s how plugins like Polylang and WPML work. Each page needs to be written in a different language, and then the plugin switches which pages are displayed depending on the language chosen. Elements themselves are just another post type, so the same thing applies to them as regular pages/posts.

    There is an issue when doing this with Elements on the front page, currently. We’re looking into a solution. For now, this topic might help: https://generatepress.com/forums/topic/how-change-page-hero-elements-text-for-pages-with-different-languages/

    #787592
    Kilian

    Hi Tom,

    I have been reading the support links you’ve sent me, but it is a bit hard for me to understand where to place all these codes and where to find the right key words I have to replace.
    As per I have read, I should use something similar to the next code:

    https://generatepress.com/forums/topic/bug-elements-and-display-rules-and-wpml-wpml-global-locations-bug-ongoing/#post-662746

    But I don’t know which ID represents each language code (I have 4 languages). I am using English (as standard language), French, Spanish and Catalan.

    I am a bit lost. Could you please help me to create the right filter, with the right key names, and tell me where to place it?

    I am not sure where should I copy and paste all this! (in customizing>additional CSS? Where all the info concerning h1 page header is?… or in Dashboard > Appearance>Elements>Home Hero? I would appreciate if you could guide me a little bit.

    Thanks in advance!

    #787596
    Kilian

    Do I need to downloand “code snippets” plugin?

    #788131
    Tom
    Lead Developer
    Lead Developer

    Yes, you’d need the Code Snippets plugin in order to add the code.

    Your code would look something like this:

    add_filter( 'generate_header_element_display', function( $display, $element_id ) {
        if ( is_front_page() ) {
            // Target our French Header Element with the ID: 10
            if ( 10 === $element_id ) {
                if ( 'fr_FR' === get_locale() ) {
                    return true;
                } else {
                    return false;
                }
            }
    
            // Target our Spanish Header Element with the ID: 20
            if ( 20 === $element_id ) {
                if ( 'es_ES' === get_locale() ) {
                    return true;
                } else {
                    return false;
                }
            }
    
            // Target our Catalan Header Element with the ID: 30
            if ( 30 === $element_id ) {
                if ( 'ca' === get_locale() ) {
                    return true;
                } else {
                    return false;
                }
            }
    
            // Target our English Header Element with the ID: 30
            if ( 40 === $element_id ) {
                if ( 'en_US' === get_locale() ) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    
        return $display;
    }, 10, 2 );

    So the only things in the above you would need to change are the $element_id values. Each Element you make will have a unique ID – you need to replace the example IDs I made above with the real ones.

    #788721
    Kilian

    Hi Tom.
    How can I know / where can I find the ID of each element?

    For example, I’ve created a new Element named Home Hero Español.
    Should I then need to replace: $element_id
    with: ‘Home Hero Español’ ?
    Is the ID the name of the page?

    I’m a bit lost.
    Thanks in advance!

    #789120
    Tom
    Lead Developer
    Lead Developer

    When you open the Element to edit it, you can see the ID in the URL: https://www.screencast.com/t/alQ9oq2D

    So the ID of the example above is: 647181

    #789252
    Kilian

    Ok, I understand what the ID is now. Thanks for that.

    I’ve tried it, but still doesn’t work. It doesn’t change the language of the header when changing the lenguage of the website.

    I have one question concerning the code you wrote. I just want to check if it’s right, but you put for catalan ID:30 and for english also ID:30.

    I tried it like this and also changing the english ID to 40, but nothing happends in either cases.

    My actual code looks like this:

    add_filter( ‘generate_header_element_display’, function( $display, $element_id ) {
    if ( is_front_page() ) {
    // Target our French Header Element with the ID: 10
    if ( 10 === 3575 ) {
    if ( ‘fr_FR’ === get_locale() ) {
    return true;
    } else {
    return false;
    }
    }

    // Target our Spanish Header Element with the ID: 20
    if ( 20 === 3573 ) {
    if ( ‘es_ES’ === get_locale() ) {
    return true;
    } else {
    return false;
    }
    }

    // Target our Catalan Header Element with the ID: 30
    if ( 30 === 3574 ) {
    if ( ‘ca’ === get_locale() ) {
    return true;
    } else {
    return false;
    }
    }

    // Target our English Header Element with the ID: 30
    if ( 40 === 2760 ) {
    if ( ‘en_US’ === get_locale() ) {
    return true;
    } else {
    return false;
    }
    }
    }

    return $display;
    }, 10, 2 );

    Maybe I’m doing something wrong?

    #789474
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Your if conditionals should look like this:

    if ( 3575 === $element_id ) {

    So $element_id should remain untouched. Only the numeric values should be updated with the real IDs.

    Let me know if that fixes it 🙂

    #789685
    Kilian

    Yeeey!! 🙂 That made it! Thanks for your patience, Tom!

    #790116
    Tom
    Lead Developer
    Lead Developer

    No problem! Glad I could help 🙂

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.