This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rbsn
rbsn

Hey, i'm new to October so hello. I'm currently working on multisite and i have issue with Translate plugin - with the pages URL's. Tried to find answer but search didnt help.

So let's say that i have static page called /subpage (having translated url in polish to /podstrona). I can translate it perfectly and make it work with locale as parameter in url like so:

  • mydomain.pl/en/subpage
  • mydomain.pl/pl/podstrona

Both of them will alwyas work, and set right locale.

Yet if i would like to not use locale param in url, because mydomain.pl/pl/ looks not good - as pl is doubled. Then i can't. It seems that when i go to both urls in two tabs in browser, then one of them will throw 404

  • mydomain.pl/subpage
  • mydomain.pl/podstrona

I assume it's because the CMS is using selected/active locale and throwing 404 because other url / route is not in that locale. But it's bad for SEO, as google instead of getting content will get 404 depending on which locale it will have. So won't index other subpage.

So is there an option or workaround to make both urls work, without locale param in url. For example if it doesn't find that page url / route in active locale it will search that url / route in another language / locale?

Or is there a way to make Default locale to not use locale in url, while any other locale will use it, i.e:

  • mydomain.pl/en/subpage - locale in url
  • mydomain.pl/podstrona - no locale in url as it's default language

Thanks in advance

Last updated

mjauvin
mjauvin

yes, you must set config in Rainlab.Translate:

prefixDefaultLocale => false

mjauvin
mjauvin

https://github.com/rainlab/translate-plugin/blob/master/config/config.php

You can override this file in your app's config folder using path = /config/rainlab/translate/config,php

rbsn
rbsn

Faboulous that works, thank you for your answer.

One more thing bothers me, i would like to have url in languege picker due to SEO purposes. Having this in menu:

<a href="#" class="locale" data-request="onSwitchLocale" data-request-data="locale: '{{code}}'">{{ name }}</a>

Is there a simple twig function or a way to retrive http url for each locale - {{code}} to put it in href? I can't find a solution or answers on forum.

mjauvin
mjauvin

You cannot change the href in there, otherwise the AJAX request won't fire

rbsn
rbsn

Well i inserted the href manually and seems like AJAX is firing. Anyway i don't need AJAX, is it possible to translate actual url to other locale url? I found some solution that does this for page but seems advanced, and i would like to do it for whole site, including static pages, translatable plugins like blog or those from builder etc. Trying to find some function in Translate plugin code now.

rbsn
rbsn

Ok i found a function for that in LocalePicker component, yet author didn't make it public. So either i need to copy function, or extend the component now. The function is makeLocaleUrlFromPage()

mjauvin
mjauvin

Maybe try Classes/Translator::getPathInLocale()?

rbsn
rbsn

I think i tried that as well as some other options / functions, and the returned url was changing the language as it had /locale/ in url, but the slug didn't translated. Anyway i will go with extending component, as i will also need better options to generate language switcher in menu. Thanks for help!

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.