- This topic has 12 replies, 2 voices, and was last updated 4 years, 4 months ago by
Tom.
-
AuthorPosts
-
January 19, 2019 at 4:09 am #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!
January 19, 2019 at 4:32 am #786148Kilian
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?
January 19, 2019 at 7:36 am #786343Kilian
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.
January 19, 2019 at 9:21 am #786414Tom
Lead DeveloperLead DeveloperI 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/
January 21, 2019 at 1:11 am #787592Kilian
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: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!
January 21, 2019 at 1:26 am #787596Kilian
Do I need to downloand “code snippets” plugin?
January 21, 2019 at 9:37 am #788131Tom
Lead DeveloperLead DeveloperYes, 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.January 22, 2019 at 2:14 am #788721Kilian
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!January 22, 2019 at 8:40 am #789120Tom
Lead DeveloperLead DeveloperWhen 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
January 22, 2019 at 10:34 am #789252Kilian
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?
January 22, 2019 at 3:24 pm #789474Tom
Lead DeveloperLead DeveloperHi 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 🙂
January 23, 2019 at 12:27 am #789685Kilian
Yeeey!! 🙂 That made it! Thanks for your patience, Tom!
January 23, 2019 at 7:52 am #790116Tom
Lead DeveloperLead DeveloperNo problem! Glad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.