Jump to content

Languages based on domain/host

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:

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

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

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

Share this post

Link to post
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!

Share this post

Link to post
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).

Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By iipa
      Hi everybody!
      I have been reading about Multisite, but it kinda bugs me that every topic talks about having both admin and database same for multiple sites.
      I have a project where customer tests it by adding content to the site, while I still need to do some changes here and there in code, maybe some in database. If something crashes for a while, customer can't keep testing, which is a bit problematic.
      Is there any way that I could have two separate versions of one site ("production" and development) that share the same database, but are otherwise independent? Just the thought of having to migrate database every time I want to show client something new gives me anxiety 😁
    • By Peter Knight
      Hi guys
      Is it possible to have a PW site display content from another PW site?
      I've been reading about ProcessWire's Multi-site options and I don't think either is a way forward for me.
      Both PW sites are separate installs with separate databases but crucially they are on the same VPS. So I'm hoping that's a good thing.
      Basically, Site A has approx 100 reviews consisting of these fields
      Reviewer name Review Date Instead of setting up the fields onto Site B and duplicating work and creating 100 pages, I want to *somehow* get site B to use a selector to fetch the necessary content from Site A.
      In future, if I need to update the reviews, I can goto the 'source' Site A to do this.
    • By Guy Verville
      I know it is possible to have a different domain name for each language of a site. For exemple:
      monsite.com (for French) mysite.com (for English) I know also that we can have several sites in one installation with the help of Soma's Multisite module.
      I have a company who has four independent sites (four different companies under a same umbrella). The new design and structure of those sites will be practically identical. There will be different administrators for each site, but a lot of data will be shared, so using Soma's module seems to be a good idea. The problem is that those 4 sites have different names for the French and English version.
      compagnieUn.com (for French) companyOne.com (for English) compagnieDeux.com (for French) companyTwo.com (for English) etc. Will we shoot ourselves in our feet to develop with just one installation? Would it be preferable to make those sites able to talk to each other instead?
      Your input would be very much welcome!
    • By MateThemes
      I am fairly new to Processwire. In the past I used OctoberCMS for my project. But I have more and more multilanguage projects and OctoberCMS don't fit my needs anymore.
      My first question to the community is, is it possible to hide/disable content based on the language. I mean, can a content editor say in German I want this content block and in Englisch I wanna hide this content block, based on the same layout?
      Thanks for your answers.
    • By Jimmie Bragdon
      Wondering if anyone can help me get past a sticking point.  
      I'm setting up a Processwire instance in a multiple site setup (using Soma's multisite) to run several related websites.  I am getting stuck on the tagging system that I am using (adapted from a standalone PW site I'm running).  I have the tags themselves set up as Pages, and the Tags field on the related pages is and ASMselect field that populates based on the pages underneath /tags/ in the tree.  This system works fine on the standalone site.
      Where I am running into issues, is with trying to use them with the multisite setup.  Specifically, choosing the proper subset of pages for tags on the ASMselect input tab.  I want to choose only the tag pages for the site in question.  
      My tree is laid out like this:
      Multisite / 
                | site1.com
                     | subsections
                | site2.com
                     | subsections
                | Tags
                     | site1.com
                          | tagA
                          | tagB
                     | site2.com
                           | tagC
      So far, the best I've been able to do is to use  'parent.has_parent=/tags/' in the Custom Find or Selector String portion of the Selectable Pages section of the input.  This gives me the options of choosing tagA, tagB, or tagC on a page under site1.com.  What I'd like to find is a selector that allows me to only see tagA, tagB as options from a page under site1.com and only tagC on a page under site2.com.
      Elsewhere in my php templates, I'm using $page->rootParent->title to set the proper scope and URLs for things, but I have not found a way to get that to work in this field input setup.  I am trying to avoid creating specific fields and templates for each site, as unified templates were part of the purpose of going with a multisite install.
      Thanks in advance for any ideas.
  • Create New...