Jump to content

Language switch on homepage


Juergen
 Share

Recommended Posts

Hello @ all,

I am new to Processwire and I am struggling for a while with this problem.

I have setted up a multilingual site with a language switcher. The switcher works fine except on the homepage. It seems the aliases for the different languages (German: startseite, English: home) will not be taken on the homepage.

If I switch to the other language on the homepage it doesnt work - it wil be always in German. The aliases will not be added to the homepage url so it is always the root url and this maybe causes the problem.

I found this in the explanation:

Please note that the URL for the default-language homepage is always your site's root URL, regardless of what you specify in the homepage name. This is intentional, as it's not desirable to have a homepage that produces a 404 or immediately performs a redirect to another URL. If populated, your homepage name for the default language is still applicable for the rest of the pages in your site.

But how can I switch on the homepage to another language???

Do I need the language prepend in the urls (de, en,...)????

I have searched in the forum but I couldnt find a solution to this problem.

I use the latest version of Processwire.

Can anyone point me into the right direction?

Best regards Jürgen

Link to comment
Share on other sites

Hi Jürgen!

You can set language (de, en) to homepage name in Settings tab and have it as part of page path.

URLs to homepage:



URLs to subpage:



When you talk about alias do you mean page name field by that? So if you already have startseite and home defined here it should basicly work as described above and have english version homepage available at http://mydomain.com/home/

Link to comment
Share on other sites

Hello Roope,

I found out what is the problem, but I could not understand it. Alias is the path name in the settings (home/, startseite/). If I name the English version "home" it doesnt work, but if I name it another name than home it will work. I seems that the word home is protected and could not be used for this purpose.

Very strange behaviour. I call it homepage instead of home and now it works quiete well.

Thanks for your effort!

Best regards Jürgen

Link to comment
Share on other sites

Don't think this marked solution is the solution?

It's very simple. First it's always nice to know what multi-language approach you use since there's multiple ways.

If you use the LanguageSupport modules with LanguageSupportPageNames also installed (which I guess you use), you'd set the language segments on the home/root page. There you'll find a name for each language. 

Let's assume you have german default and english alternative language, you'd probably set the name to 

german: "de"

english: "en"

This will result in urls like /de/meineseite/ and /en/mypage/

Default name could also left empty, so there won't be any language segment for it and only be /meineseite/.

So, but you name them  "startseite" and "home" which is strange as this would result in /startseite/meineseite/ and /home/mypage/, which is not desirable I think.

So taking the language segments as described before a language switch using $page->localUrl(language) will return the correct url to the language.

On the homepage this would result in 

domain.com (always default language, unless you set option to redirect to /de/ in LanguageSupportPageNames module)

domain.com/de/

domain.com/en/

The language is always evaluated from the requested URL, and $page->url will always return urls of a page according the current language. You can get a localized url of a page explicit with $page->localUrl(language).

  • Like 6
Link to comment
Share on other sites

Hello Soma,

thank you for this explanation. I have always used Joomla and there are a lot of other approaches in creating multilingual site so it was difficult for me to figure out the procedure here in Processwire.

Yes, I use the module and I have changed the homepage names to de and en and this makes much more sense. Thank you for your hint.

Best regards Jürgen

Link to comment
Share on other sites

Thing that got in to my eye was this:

It seems the aliases for the different languages (German: startseite, English: home) will not be taken on the homepage.

If I switch to the other language on the homepage it doesnt work - it wil be always in German. The aliases will not be added to the homepage url so it is always the root url and this maybe causes the problem.

That's why I was saying that it should work but was also suggesting to use language code version instead.

So I had to test it and it sure looks like if you give your homepage name "home" it doesn't work (throws 404). I do agree with Soma that name like this is not suggested for homepage but it could be the case with multilingual one page website for example so this clearly looks like a bug here.

EDIT: one page website may be bad example here since language code would be preferred way but still "home" should be acceptable to use as homepage name.

Edited by Roope
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...