This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shekhar Bhandari 2 months, 3 weeks ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
July 12, 2019 at 2:56 pm #4200007

joshM-8

I am trying to:
I have a multisite install where the child sites query information from the parent site. If the child site is a Spanish site, I want to pull in Spanish translations from the parent site.

On the parent site for an ACF field "Heading" on the homepage for instance I have provided a Spanish translation of that heading. On the Spanish site when viewing in English all of the original post content that shows up on that page that I'm querying form the parent site shows up normal as expected. When I go to the Spanish language no content pulls over at all.

I would expect that for each ACF field IF a Spanish version existed that translated version would pull over, ELSE the original English content would continue to pull in.

Is something like this possible with the plugin? I'm aware it may not exist out of the box and I may have to do some custom logic and queries. I'm just looking for some sort of direction on where to begin looking, starting with if you know this to be possible.

And explanation of what happens when I switch languages would be helpful in determining where I need to start looking in your plugin files to begin understanding what happens and if I can modify that behavior at all.

I would be interested to know if the hook page in your documentation is truly all that is available or if perhaps there are more filters available so that I can really customize the behavior. The site I'm building is a little out of the ordinary, I'm aware, but so far I've been able to get everything to work and translations is the last major beast that needs slain.

Because I feel this may be a somewhat unique inquiry I'm not sure what else to say at this time until we've had further dialog. I hope that the description I've provided gives you understanding of what I'm hoping to accomplish enough that you can instruct me if the plugin even has the type of capability or if I'm wasting my time.

Thanks so much and I look forward to your response,
Nick

July 15, 2019 at 10:44 am #4209993

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Welcome to WPML support.

The feature you mentioned is not available with the plugin. I have not implemented something like this feature so I think you can start following the below steps:

- Create a function to retrieve the value of the field on the parent site, the function should extend get_field to get your preferred results along with language information passed which is the current language

- On the function, get the current language information from parameters and query the correct site

- Retrieve the results, and if the results don't exist, show the preferred results.

You can use the wpml_currect_language hook to get the current language https://wpml.org/wpml-hook/wpml_current_language/

Switch_to_blog to switch to another blog: https://codex.wordpress.org/Function_Reference/switch_to_blog

The following are the hooks that are currently available since we update hooks page as soon as we will have a new hook, we can say these are the only available once.
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Let me know if this helps.

Thanks

July 18, 2019 at 10:28 pm #4242493

joshM-8

I'm not sure I totally understand your response in particular "the function should extend get_field to get your preferred results along with language information passed which is the current language". Can you elaborate on how language information is passed?

For a little further context, on a sub site the WPML plugin is Network Activated but may or may not have any language information attributed to it. Most language information will only be stored on the main site however some localized content will exist too for countries that may have multiple languages that they speak.

For this reason I'm also going to have to build a custom language switcher to set the query string for a specified language, and in the template files read the query string making a custom query to try and retrieve field information in the query string language if it exists, else pull the original english field content.

So take for example we are on the "About" page of the Argentina site. Let's take a look at the main hero section for example. This heading, subheading, image, etc all pull from the original English site by default. I'll eventually have to add an exception to see if Argentina in fact has written it's own translations locally but for now lets say that a Spanish translation needs to come from the original site.

I'll eventually set the default query string for Argentina to be "?lang=es" and want to try and auto pull relevant translations first before falling back to English for fields without translations. For now lets say that "?lang=en" is the default selection and all English content is pulling through. A user clicks on the custom switcher dropdown and chooses Spanish which updates the url to /about/?lang=es. Now for each field on the page we need to check if the original English site has a translation value for the field but stored in Spanish. If it does pull that over, if it doesn't pull the original over.

To generate the custom switcher, since other country sites don't have "active" languages, I have already figured out that I had to write a custom db query to the wp_icl_languages table for each site to compile a list of all active languages on the entire network. This because at the time the original site is the only site that contains translations. So the preferred wpml_active_languages hook does not work on the Spanish site since it has no active languages. I tried using switch_to_blog but that hook does not seem to be budged by switch_to_blog and instead queries only the Spanish site for active languages. The information returned via wpml_active_languages and directly querying the wp_icl_languages table for each site are slightly different such as missing the 'url' value. Not sure if that will haunt me later or not.

Thanks in advance for the continued support on this matter and know that literally any tiny bit of advice is much appreciating.

Also, if you feel like what I've just described is way out of the bounds of the plugin please also alert me to that as I'm running out of time to complete this project. If WPML won't work I'm in a tight spot so I really hope we can make it work.

July 19, 2019 at 2:47 am #4243249

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

I was mentioning some code like this, it's just a suggestion so you can try and see if it helps.

function custom_function($current_language){
    if($current_language == 'en') {
        //switch to blog that is for this lang
        //retrive the results
    }
}

Providing a custom code solution is outside the scope of our support and the requests you are trying to achieve also falls outside the scope of our support as it needs custom programming work to accomplish the feature.

At this point, I would suggest you consider contacting one of our certified partners from this link: http://wpml.org/documentation/support/wpml-contractors/

Before doing so please have a look also here:
http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/

You will get the custom assistance you need to get on with your project.

Thanks