Home › Toolset Professional Support › [Resolved] WPML, separate Repeatable Field Groups and Layout
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Related documentation:
This topic contains 18 replies, has 2 voices.
Last updated by Nigel 5 years, 12 months ago.
Assisted by: Nigel.
I am trying to have separate Repeatable Field Groups for each language with a different layout as well.
I have a CPT on a multilingual website.
In it, a Repeatable Field Groups where users upload files.
This ends in a Layout that shows the uploaded files.
When I create a translation with WPML of one of these CTPs I can only translate the existing RFG (and I almost failed at it as well) but not able to have a separate RFG for the second language (French).
I also would like to use a separate Toolset Layout for French, is this even possible at all? I don't want to translate the layout, just use another one. The translation process via WPML strings and management is overly complicated and not effective for my scenario.
So to summarize.
One CPT, two languages, two RFG and two layouts.
When I create a translation of a CPT it uses RFG2 and Layout2.
Thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
Unfortunately, the internal architecture of Types relationships combined with WPML doesn't allow for what you are aiming for, if I've understood correctly.
You may be aware that repeatable field groups are built with a child post type, so for every group of repeatable fields added to a custom post, a child custom post is created to act as container for that group of fields.
With translations of post relationships, the translation connections are all managed through the default language.
So instead of
post_EN --------- post_ES --------- post_DE | | | | | | child_EN child_ES child_DE
the translations are actually managed like
post_EN --------- post_ES --------- post_DE | | child_EN -------- child_ES -------- child_DE
In your case the child posts are RFGs, but the RFGs in secondary languages can only exist as translations of the default language RFG, which I think is the root of your problem.
As for using different Layouts for different translations of posts, you would effectively make a Layout for each language, assign the Layout for the default language to the post type, meaning it will be set to be used for all languages. You can then manually assign a different Layout when editing the translation of a post, which is likely not practicable, and so you would want to write some code to programmatically achieve the same when a translated post is published.
I could help with that, but given the limitations with the RFGs, I don't know if it is something you still require.
I see... this is tricky indeed.
I came up, in the meantime, with a workaround, which I don't like very much so maybe you can give me a few suggestions.
I created two RFGs, one is RFG-EN, the other RFG-FR.
They are both visible in my CPT but one is for french files and the other for English.
Now, instead of using two layouts (which I wasn't able to do anyway), I tweaked my current layout and thanks to the following WMPL shortcode:
[wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]content[/wpv-conditional]
I make it conditional, based on the language.
Inside my RFG View Loop item (which is only ONE for both RFGs) I used this to display different content (just a sample, nothing fancy).
<h2 class="entry-title">[wpv-post-link class="entry-title-link"]</h2> <div class="entry-content"> [wpv-post-excerpt length="100"]</div> [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]<a href="[wpv-post-url]" class="more-link">Read More</a>[/wpv-conditional] [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'fr' )"]<a href="[wpv-post-url]" class="more-link">Lire la suite</a>[/wpv-conditional]
Now, this works... BUT I have the following problem (of course).
In order to be able to have both RFGs active and editable in my CPTs, I need to have my CPT Translation setting as: "Translatable - use translation if available or fallback to default language". Instead of the more correct: "Translatable - only show translated items".
Inside my website, I have several views that filter my CPT based on taxonomies etc. And of course with different content/language.
So with the fallback on, I can use RFGs, but in my other view, I get results of CPT of my other language if they are not translated.
With the fallback off, I don't get CPTs wrongly, but I am not able to use RFGs in my CPTs.
I know it's a bit confusing, I understand. But I thought there was an easier solution for this actually... not sure what to try next. Happy to give you real examples if that helps!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, I understand your workaround, and I understand the limitation which WPML imposes on the translation setting for the RFG.
Let me clarify what happens next with your other Views.
"I have several views that filter my CPT based on taxonomies etc."
These are Views to display the parent CPT? Not Views to display the RFGs (which are child posts of the CPT they belong to)?
I can see the problem if the Views are to display the RFGs, but not if the Views are to display the parent CPT, which I would expect to work normally.
Could you confirm that?
Yes, that is correct.
I have a page called 'Scotland' with a view:
[wpv-view id="1685" wpvlocation="scotland"]
And this simply shows CPTs with a term 'scotland'.
this view added to the page translation (called 'Ecosse'), will be
[wpv-view id="1685" wpvlocation="ecosse"]
so same view, translated taxonomy term.
Each CTP has inside a Layout with the RFG condition I posted.
Currently, if the CTPs don't have a French translation, the system shows the English CPTs under the page Ecosse, with the second shortcode above. If I change the wpml Fallback off for these CPTs they work but, again, no editable RFGs 🙁
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Understood.
Sorry, I've run out of time today. I don't have a quick solution for you, I need to do some testing and possibly check with my colleagues. I'll do that in the morning and get back to you.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
My reply was lost. Let me try again.
I'm not sure there actually is an issue with the last part here.
I changed the translation setting for the main post type on my test site to "Translatable - use translation if available or fallback to default language" so that I could use RFGs with it.
I created a View similar to what you describe, where I pass the location taxonony term like so when I add the View to an English page:
[wpv-view name="projects-of-a-location" wpvlocation="scotland"]
English is the default language, Spanish the second.
When I translate the page to Spanish, I insert the View... exactly the same way. I *don't* change the term to the translation of scotland, because WPML handles this automatically.
I then see the results I'm expecting on both the English and Spanish pages.
Am I missing something?
No problem 🙂
Ok so yes, that is my situation. I followed your suggestion and translated back the view term in the shortcode to the default one, on the translated page. Still, I see mixed content.
If one CPT doesn't have the equivalent in French, the English one is shown, with mixed results (see screenshot).
Also, the following crazy thing happens:
EnglishPost --> FrenchPost
EnglishNewPost --> No French translation
Now in the screenshot, EnglishNewPost is displayed on my French side but, when I click on it, the url is the one with /fr/ at the beginning! So I am viewing a non translated English post, on my French side, with the French url! Is this correct?? Because sounds very weird.
also, since it was the main thing, any chance to change the behavior of the RFG in the future to be more multilingual friendly?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Leonardo
Sorry, I missed a step in my tests, and you are right that if I show a list of posts in the second language, where there is no post in the second language, the English default is shown in its place (with the URL structure you describe).
Regarding the URL structure, I think that is just how it has been implemented, it might appear a little strange, but I can understand that it would be set up that way.
And regarding showing the English post when no second language version exists, well that is of course expected because of the translation setting we are obliged to use for the post type to be able to use RFGs (or other post relationships) with it.
Now, as a workaround for your problem, you might be able to adopt a similar strategy, whereby you use a conditional shortcode that tests for the language of the post. In a single View you might be able to compare the language of the page where the View is inserted (say we are looking at the French page and want to see French results) with the language of the current post in the loop, so only French posts would be output, English-only posts that were being returned because of the WPML translation settings would fail the test. (I think. I haven't tested it.)
You could try implementing that as a workaround.
As for fixing the original issue, the developers are aware of it—I think something similar has come up with two other clients in the past 6 months or so—but it would take quite an effort from both WPML and Types to change how this was implemented, so I'm not sure we can expect such changes any time soon.
You could push for it here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Hi, ok, the workaround makes sense, but I'm not sure where to put the conditional.
Should I add it to the view loop?
Because I already have two conditions in the template, but these two read the language of the page where the view is put (the same I already posted):
[wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]<a href="[wpv-post-url]" class="more-link">Read More</a>[/wpv-conditional] [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'fr' )"]<a href="[wpv-post-url]" class="more-link">Lire la suite</a>[/wpv-conditional]
Also, the post in English wrongly fetched, has the url of the French posts (/fr) so not really sure where I can 'ask for its real language'.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I think we are nearly there.
I don't know where your get_wpml_language_code_value shortcode comes from, I guess you wrote a custom shortcode to get the language details of the current post?
I did something similar, registering the following shortcode ("post-language"):
add_shortcode('post-language', function () { $language = apply_filters('wpml_post_language_details'); // Return just the language code return $language['language_code']; });
Now, in the loop output section of my View I simply insert that shortcode so that I can see what language WPML/Views think the posts are in.
If you look in the screenshot at the results of a View in the secondary language which is including English results where there is no Spanish version of a post, WPML knows that the post is English, it doesn't think it is Spanish.
In fact, the array returned by that WPML filter is really helpful in this case, because it includes a flag for whether the language of the post is the same as the current language for the page.
I'm looking at the Spanish version of the page, and the Spanish posts in the View loop output return this:
[08-Feb-2019 11:16:10 UTC] language: Array ( [language_code] => es [locale] => es_ES [text_direction] => [display_name] => Español [native_name] => Español [different_language] => )
But the English posts that are included because of the translation setting return this:
[08-Feb-2019 11:16:10 UTC] language: Array ( [language_code] => en [locale] => en_US [text_direction] => [display_name] => Inglés [native_name] => English [different_language] => 1 )
So all we need for our shortcode to use in the wpv-conditional test is to return the different_language element and compare it to 1:
add_shortcode('different-language', function () { $language = apply_filters('wpml_post_language_details', null, null); return $language['different_language']; });
which we use like this:
<wpv-loop> [wpv-conditional if="( '[different-language]' eq '1' )" evaluate="false"] <h3>[wpv-post-link]</h3> <p>[wpv-post-taxonomy type="location" format="name"]</p> [/wpv-conditional] </wpv-loop>
That successfully only outputs anything for the posts in the intended language.
I wasn't looking at your RFG workaround here, but it's no problem using nested wpv-conditional shortcodes, so you should be able to work your solution inside this.
Ok, this is a great solution I think, but I wasn't able to reproduce it so allow me to explain what I have and where.
First of all, I am not really sure where to put the [post-language] shortcode to see the output.
then
this is the code I have that creates my conditional based on language (happy to tweak it if you think):
add_shortcode('get_wpml_language_code_value', 'func_wpml_language_code_value_func'); function func_wpml_language_code_value_func() { $return = ICL_LANGUAGE_CODE; return $return; }
then, in my View loop I have
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <wpv-loop wrap="2" pad="true"> [wpv-conditional if="( '[different-language]' eq '1' )" evaluate="false"] [wpv-item index=1] <div class="row rowflexo"> <div class="col-sm-6 colonneelapse">[wpv-post-body view_template="loop-item-in-view-for-courses"]</div>[wpv-item index=other] <div class="col-sm-6 colonneelapse">[wpv-post-body view_template="loop-item-in-view-for-courses"]</div>[wpv-item index=2] <div class="col-sm-6 colonneelapse">[wpv-post-body view_template="loop-item-in-view-for-courses"]</div> </div> [wpv-item index=pad]<div class="col-sm-6"></div> [wpv-item index=pad-last]<div class="col-sm-6"></div> </div> [/wpv-conditional] </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>[/wpv-conditional] [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'fr' )"]<strong>[wpml-string context="wpv-views"]Aucun élément trouvé[/wpml-string]</strong>[/wpv-conditional] [/wpv-no-items-found] [wpv-layout-end]
and my template
<h2 class="entry-title">[wpv-post-link class="entry-title-link"]</h2> <div class="entry-content"> [wpv-post-excerpt length="100"]</div> [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'en' )"]<a href="[wpv-post-url]" class="more-link">Read More</a>[/wpv-conditional] [wpv-conditional if="( '[get_wpml_language_code_value]' eq 'fr' )"]<a href="[wpv-post-url]" class="more-link">Lire la suite</a>[/wpv-conditional]
Of course I registered the two new shortcodes you suggested with Toolset, still nothing.
If I put your conditional just after the <loop> tag it does nothing.
If I put the [post-language] in the loop or in the template everything breaks (blank page).
So clearly now the problem is me not really understanding the where! 🙂
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
The post-language shortcode was just to demonstrate outputting the language of the current post in the loop, as used for my screenshot, it is not part of the required solution.
Forget that shortcode, and make sure you register the different-language shortcode.
If something is not working I suggest that before using it in the conditional shortcodes you simply output it (just after the wpv-loop tag). You should see nothing for posts that are in the same language as the current language, i.e. most of the posts, and '1' when the language of the post is different to the current language (where it is being shown because no translation exists).
If that works, then it really should be working in the wpv-conditional shortcode.
Did you remember to register the shortcode in Toolset > Settings > Front-end Content?
Yes I know it was just to demonstrate the thing, I just wanted to see it working in my view as well.
Yes, as I wrote, I registered the shortcodes with Toolset.
Still nothing, I placed the condition after the loop as well, and it evaluates false even with CPT without translation 🙁
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I'm not sure what you have done, but let me share a copy of the site I have been working on so that you can see it in action for yourself to see if you can spot what is missing on your site.
I created a sandbox site which you can log in to with this link: hidden link
Check the page hidden link.
That is the English version of a page to show Scotland projects, and lists two English posts that have the Scotland location taxonomy term.
Use the language-switcher to see the Spanish version of the same page. You—correctly—see just two posts, which are both in Spanish.
You only see two because of the conditional shortcode in the View output that uses the custom shortcode registered at Toolset > Settings > Custom Code.
If you remove the conditional shortcode you will see that 3 posts show, 2 Spanish plus one English which is showing because of the WPML settings for the Projects post type.
It is a simple example, can you study it to verify how it works and see if it illuminates why yours does not?