Jump to content

Languages based on domain/host


sins7ven
 Share

Recommended Posts

Hi community, I am wondering if its possible to display languages based on what host/domain has been requested.

The use case is the following: I have one installation of PW - and within this installation I set up 5 different languages (default, english, spanish, french, dutch). Now I have 3 different domains (domainA.com, domainB.com, domainC.com) and I want to decide which languages to make available based on what domain has been navigated to. 

For example:

domainA.com
 - default (domainA.com)
 - english (domainA.com/en)

domainB.com
  - default (domainB.com)
  - french (domainB.com/fr)
  - dutch (domainB.com/nl)

domainC.com
  - default (domainC.com)
  - dutch (domainC.com/nl)

So what I want to achieve is making only these particular languages selectable in the language switcher on the frontend. Since all pages share the same templates and overall site structure I don't see the benefits of running this installation as a multisite setup or would it be better to do so? But I assume that this would be difficult to handle since the default language might change as well. (On the french version of the page, french should be the default language and so on). Any suggestions how to accomplish that? Thanks!

Link to comment
Share on other sites

Thank you! That looks pretty close to what I have in mind. However - I am not sure if this approach let me allow only some selected languages to be available in the language switcher (for example domainA.com should only show default and english and domainB.com should show default, french and dutch). But I am not sure if it is even possible to change the default language based on the host? I am going to play around with your solution and see what I can achieve. Thanks again!

Link to comment
Share on other sites

3 hours ago, sins7ven said:

I am not sure if this approach let me allow only some selected languages to be available in the language switcher

Since you probably implement the language switcher on your own, you are obviously free to only allow specific selections depending on the domain name (in $config->httpHost). You may even make this configurable in admin. You may either add some "allowed_domains" field to the language template, or create a new template named "httphost" (for example), which holds a multi page selector for supported languages. So there are multiple options to achieve that.

3 hours ago, sins7ven said:

But I am not sure if it is even possible to change the default language based on the host?

That's exactly what I do in the described example. I'll check the domain name and set user's language accordingly. If you go with the httphost template, you may add another single page select for the default language, so everything stays configurable in admin (but you'll have to account for some additional database accesses, of course).

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...