Condition based on URL structure

Hi there - I’ve got GTranslate installed and can toggle between languages nicely.
However the search functionality only works in English (because the content isn’t actually translated and searchable) - that’s find and understood.

But I want to hide, using the conditions, the search box when a language is being viewed. Each language has /pl/ or /es/ etc in the URL structure - any way of doing that?

Site in question to see: https://healthinhampshire-com.rubberduckers.agency/

Hey @RubberDuckers,

Thanks for writing in! Regretfully what you want is not possible with the conditions. You might need to contact the creators of the Gtranslate plugin, They might be able to help you with what you are trying to accomplish.

Best Regards.

Hey Rue, so ignore that it’s the plugin. I’m trying to use the conditional settings and the URL segment in Cornerstone - using the likes of /pl/, /ru/ etc after the main domain part of the URL - is that not possible?
Kory had mentioned something about archives and index=1 for detecting a part of the URL.

What I’m trying to achieve is when /pl/ or /de/ or whatever is after the first slash domain.com/pl/ then the condition kicks in and doesn’t show an element.

Hey @RubberDuckers,

Depending on the 3rd party translation plugin that you are using, it may be using a URL parameter with something like this: https://example.com/?lang=de. And if this is the case, you can use the String condition making use of the {{dc:url:param key="lang"}} dynamic content.

Hope this helps.

Thanks @ruenel - though as I said, the domain structure is domain.com/pl/ or domain.com/de/ where the language code comes after the first / - is there a way of targeting that in a similar way that you suggest?

Hey @RubberDuckers,

Regretfully, no. The URL Parameter is the only way to detect the language.

Can something like @kory’s discussion here not work: Dynamic Content Archive Slug? but targeting index=0 (if that is a thing?) to get the /pl/ /de/ etc etc?

Hello @RubberDuckers,

You can use the URL Parameter or a URL segment {{dc:url:segment index="{n}"}} as long as the URL provide something. Normally, having to have a domain.com/pl/ or domain.com/de/ translate to a {root-directory/folder-name/} structure. Unless your original URL is https://domain.com/?lang=pl or https://domain.com/?lang=de and with the help of the WordPress Permalink Rewrite rules it became https://domain.com/pl/ or https://domain.com/de /, then using the URL or URL segment {{dc:url:segment index="0"}} maybe possible.

It is best that you go to Settings > Permalinks and set it to “Plain” so that you can see your original URLs with the parameters or segments in it. This way, we can see if the above suggestion or from @Kory’s discussion is possible or not.

Hope this makes sense. Thanks.

I switched to the plain permalink and it stays the same /pl/ /de/ etc - the plugin is the paid version of GTranslate for info which adds the /pl/ etc.
There is an option to make it add a subdomain instead, would this be targetable by the dc:url string any better?

Thanks!

I’ve been in touch with the plugin developers and they can’t/don’t do “?lang=” so we’re just stuck with either the /pl/ or a subdomain pl.domain.com if that’s any better for this scenario?

Hey @RubberDuckers,

I’ve consulted with Alex, our core developer and he pointed me that you can use {{dc:url:segment}}. Not specifying an index will get the first directory. When I answered previously, I was testing with Index that’s why nothing works.

For example, you could test de from example.com/de/page/another-page-child. That means the element will display if the language is de.

image

I’ve tested the setup out and it works.

Hope that helps.

Thanks @christian - @alexander to the rescue!

Though this still doesn’t work for me :confused: I’ve added a secure note so you can see yourselves. There’s a search bar on the home page that has the condition. I’ve just done ‘pl’ for now to test.

Hi @RubberDuckers,

Unfortunately, the given credentials are not working. Can you please check and send it once again.

Thanks

I’ve updated the secure note, should work now!

Hey @RubberDuckers,

I went to the PL page to investigate but I get a Too Many Redirects error. Please have the web host fix that first.

image

If you can access a PL page, try outputting the {{dc:url:segment}} DC in a Text element to see what it will display. The expected output should be pl if you view PL pages unless GTranslate does something different.

Also, try resetting your permalinks.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.