Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Mit einem Update von Generate Press sind die alten GP Hooks durch die neuen GP Elements ersetzt worden.

Dia Hooks waren übersetzbar, aber die neuen Elements zeigen beide Sprachen an der gleichen Stelle und sind nicht übersetzbar.

Solution:
Mit diesem Filter kann man die Hooks der jeweiligen Sprache zuweisen.

- Der Beitragstyp 'Elements' muss übersetzbar sein.
- Dazu muss das benutzerdefinierte Feld "_generate_element_content" auf "übersetzen" gesetzt werden.
- Diese Felder sind auf "kopieren" gesetzt:
_generate_element_type
_generate_hook
_generate_element_user_conditions
_generate_hook_priority
_generate_element_display_conditions

Damit kann man auf Deutsch einen Hook definieren und ihn ins Englische übersetzen.

Mit einem zusätzlichen WPML Filter wird das dann in der richtigen Sprache auf der Seite angezeigt. Auf der Testseite habe ich diesen Code in die Datei functions.php des Themes eingefügt:

add_filter( 'generate_hook_element_display', 'wpml_generate_hook_element_display_filter', 10, 2 );
function wpml_generate_hook_element_display_filter( $display, $post_id ) {
    $current_language = apply_filters( 'wpml_current_language', null );
    $element_language = apply_filters( 'wpml_element_language_code', null, array(
            'element_id'   => $post_id,
            'element_type' => 'post_gp_elements'
        )
    );
    if ( $current_language != $element_language ) {
        $display = false;
    }
    return $display;
}

Relevant Documentation:

Der Code hierfür ist auch in Github hinterlegt, so dass Sie ihn hier jederzeit wieder herunterladen können.

https://gist.github.com/srdjan-jcc/00ee8d15afb3c6c1497af5ff92d32a8e

Dies ist das technische Support-Forum für WPML – das mehrsprachige WordPress-Plugin.

Mitlesen können alle, doch nur WPML-Kunden können hier Fragen veröffentlichen. Das WPML-Team antwortet im Forum an 6 Tagen pro Woche, 22 Stunden am Tag.

This topic contains 8 Antworten, has 2 Teilnehmer.

Last updated by Daniela vor 2 years, 1 month.

Assigned support staff: Cristina.

Author Artikel
August 23, 2018 um 12:04 pm

Daniela

I'm writing this post in English instead of German, so the theme author can read along, if he wants to 🙂
The theme I use, Generate Press, just had an update with some major changes in their additions. There used to be a function called GP hooks. With GP hooks I could place codes on certain areas of the page. The translation I did with WPML string translations admin_text_generate_hooks. Now GP Hooks was removed and Elements introduced instead. Unfortunately I’m now not able to translate the hooks anymore. According to the theme author the new elements are custom type post. See my support topic here: hidden link
When I now create a translation of the post, the translation does not only show on the second language it was translated to, but on both language sites, see bottom of screenshot attached.
I use this function in my shop (hidden link), but to be able to show you the “error” I created a staging site of another one of my website with no personal customer details. As you can see when you log in I also use an image where I just excluded the ID of pages to the code, but this is impossible in a shop with hundreds of products.
Do you have any idea what the problem could be?
Kind regards
Dani

August 23, 2018 um 3:30 pm #2670732

Cristina

Hello Daniela,

sorry to hear about the troubles with GeneratePress.

As this is a recent update and the theme was tested a few months ago as last time, this should be retested by our compatibility team. I have looked up our support data, but there is no similar problem reported until now.

Anyway, WPML also had some mayor changes in the last months, so there maybe some issues here with how things work.

Unfortunately, I can't log in to the site with the provided credentials, but I can access per FTP.
Could you check the login details for the site?

I would then see the problem and if you give your permission, I would create a snapshot and escalate this to our compatibility team to check.

As this is a compatible theme, the devs would get in contact with the GeneratePress people to solve the issue. If there is any quick workaround for this we can provide it to you as well.

I enable the private reply again for this.

Kind regards
Cristina

August 23, 2018 um 4:41 pm #2670898

Daniela

Hello Cristina,

can you please try again with the credentials I gave you? There was a typo mistake on my site with the username I gave you. It's now been corrected. I'm sorry.

Yes, you can of course take a snapshop, duplicate it, change things etc. It's only a staging site specially created to find a solution to the current problem between GeneratePress and WPML.

It's probably not been reported, because the GeneratePress update was only last week.

The theme author said, if he can be of any help to let him know and reach out to him at any time.

Thank you.

Kind regards

Dani

August 23, 2018 um 5:22 pm #2671021

Cristina

Hello Dani,

thanks, I could log in now and will check the issue and escalate it after checking the options.

Kind regards,
Cristina

August 23, 2018 um 7:06 pm #2671321

Cristina

Hello Daniela,

this is now escalated to the compatibility team, who will have a look into this and reach out to the theme authors.

I did not find any way to make that appear.

The only thing you could try here is to use different untranslated elements and define each page where they should appear using the display rules.

This way you could use independent hooks for german and english pages, but this would not work for pages like the front page, where only one hook shows at the same place.

There is no option to use a version that automatically shows up as translation on the second language and as original on the default language pages.

Kind regards,
Cristina

August 24, 2018 um 6:31 am #2672316

Daniela

Thank you Cristina. The display rules with pages won't really work, because in a shop that's just hundreds of pages and for example cart or checkout are like front page, so it won't work. The staging site is not a shop site I know, this was just to demonstrate the problem and a lot easier than to create a duplicate of my shop site 🙂
Maybe the compatibility team finds a solution. For now I stick to the old GeneratePress version in my shops.
Thanks for the fast replies! Much appreciated!
Saludos,
Daniela

August 24, 2018 um 10:03 am #2672677

Cristina

Hello Daniela,

sure, I too think that is not feasible for a big site.

Thanks a lot indeed for making this so easy to reproduce and check.

I hope it will work out somehow. There are more themes that use this comfortable hooks system, therefore I hope this is not a general issue coming but a GeneratePress thing.

As soon as I have some feedback I will report back.

Kind regards,
Cristina

August 29, 2018 um 1:57 pm #2686619

Cristina

Hallo Daniela,

die Kollegen haben einen Filter generiert, mit dem man die Hooks der jeweiligen Sprache zuweisen kann.

Ich habe auf der Testseite den Content für die Elements als übersetzbar definiert.

- Der Beitragstyp 'Elements' muss übersetzbar sein.

- Dazu muss das benutzerdefinierte Feld "_generate_element_content" auf "übersetzen" gesetzt werden.

- Diese Felder habe ich auf "kopieren" gesetzt:
_generate_element_type
_generate_hook
_generate_element_user_conditions
_generate_hook_priority
_generate_element_display_conditions

Damit kann man auf Deutsch einen Hook definieren und ihn ins Englische übersetzen.

Mit einem zusätzlichen WPML Filter wird das dann in der richtigen Sprache auf der Seite angezeigt. Auf der Testseite habe ich diesen Code in die Datei functions.php des Themes eingefügt:

add_filter( 'generate_hook_element_display', 'wpml_generate_hook_element_display_filter', 10, 2 );
function wpml_generate_hook_element_display_filter( $display, $post_id ) {
	$current_language = apply_filters( 'wpml_current_language', null );
	$element_language = apply_filters( 'wpml_element_language_code', null, array(
			'element_id'   => $post_id,
			'element_type' => 'post_gp_elements'
		)
	);
	if ( $current_language != $element_language ) {
		$display = false;
	}
	return $display;
}

Auf der Testseite habe ich den Code in die Datei functions.php des Themes eingefügt, man kann das aber auch auf Wunsch separat als Plugin hochladen.

Der Code hierfür ist auch in Github hinterlegt, so dass Sie ihn hier jederzeit wieder herunterladen können.

hidden link

Die Kollegen werden die Dokumentation des Themes hierfür aktualisieren.

MfG,
Cristina

September 2, 2018 um 8:07 am #2696641

Daniela

Hello Cristine,
entschuldige die späte Rückmeldung. Irgendwie hatte es bei mir zuerst nicht funktioniert. Wahrscheinlich lag es daran, dass ich noch die alte GP Hooks aktiviert hatte. Nachdem ich diese deaktiviert habe und nur Elements nutze, funktioniert es auch in meinem Shop! 🙂
Vielen Dank für die Hilfe.
Viele Grüße
Daniela