umbraco-headrest icon indicating copy to clipboard operation
umbraco-headrest copied to clipboard

Language variants (v8) through culture and hostnames

Open jessevdp opened this issue 5 years ago • 7 comments

Umbraco 8 introduced Language Variants. The "Adding language variants" section in the "Creating basic site" tutorial on Our Umbraco mentions that hostnames configuration is required to output the language variants of a content node (scroll down to "culture and hostnames" which is boldly printed somewhere in the article 😄). Consider the culture and hostnames configuration below.

culture and hostnames configuration

After some (limited) experimentation I've concluded that HeadRest does not take the hostname configuration into account. Attempting to access a content item at an alternative URL results in a 404 error. I've tested both, a config in which the alternative URL has a different language, and a config where the alternative URL is in the same language.

I suppose that making HeadRest work with the hostnames config makes it work with language variants as a result. If not inherently, then I think it should be reasonable to add on top. (Note that I'm not familiar enough with the codebase to know for sure.)

jessevdp avatar Dec 09 '19 15:12 jessevdp

What would it take to implement this kind of functionality? What are the roadblocks?

jessevdp avatar Dec 09 '19 15:12 jessevdp

Note that #13 suggests manually adding every alternative route to HeadRests mapping. But that doesn't scale...

jessevdp avatar Dec 09 '19 15:12 jessevdp

Ahh, I think I might have identified the need for this in a previous PR on a different subject, but I think the route handler would need updating to handle the "domain" entries https://github.com/mattbrailsford/umbraco-headrest/blob/develop/src/Our.Umbraco.HeadRest/Web/Routing/HeadRestRouteHandler.cs and possibly the URL provider too https://github.com/mattbrailsford/umbraco-headrest/blob/develop/src/Our.Umbraco.HeadRest/Web/Routing/HeadRestUrlProvider.cs

I'd need to look into this to determine exactly what would need to happen, but I don't really have time atm. If someone wants to investigate, I'd happily provide guidance as to whether it sounds like you are on the right path. Otherwise it'll have to wait till I have some time free.

mattbrailsford avatar Dec 09 '19 16:12 mattbrailsford

Thanks for the pointer. I'm going to see if I can make some time.

So in the route handler, the path variable contains whatever path is entered after where HeadRest is mounted? Considering a base path of "/api" and a request to http://headrest.local/api/foo/bar it would contain something like: "/foo/bar".

https://github.com/mattbrailsford/umbraco-headrest/blob/a50f41145e6b9481ed5b739fa2cbf6e7ef1cb27b/src/Our.Umbraco.HeadRest/Web/Routing/HeadRestRouteHandler.cs#L28

The code then moves on to build an xpath based on the path entered and retrieves the node from that path if it exists.

I guess it would be possible to rewrite this method and see if the path matches any of the URLs of any of the content nodes.

That would break the rootNodeXPath option of HeadRest though. So the code would need to keep that in mind. (Maybe just look at content nodes starting from the content node at the root xpath?)

jessevdp avatar Dec 10 '19 08:12 jessevdp

@jessevdp I think so yes.

I think there might be need to look into the core Domain entities where the hostnames are registered and whether we need to do some lookup based on those paths. I seem to remember having to do this for a content finder some time ago, but I can't fully remember what I did. I'll see if I can dig something out later.

mattbrailsford avatar Dec 10 '19 09:12 mattbrailsford

@jessevdp I am currently developing VueJS based community site NC COVID Support that I am looking to shortly port across to use Umbraco as it's back end ( the site's data currently comes from a Google spreadsheet via their JSON API )

I was just looking to see if Matt's package would suit our requirements, I noticed this thread about multilingual usage of the API. I wondered if you had managed to make any progress with this?

@mattbrailsford - As always, a great looking package 🥇

Cheers, Chris

readingdancer avatar May 06 '20 01:05 readingdancer

As far as I know, no progress. I was hoping to pick this up as part of an internship I was doing at the time. Never got around to it due to time constraints/priorities.

Note that this issue is in regard to Umbraco 8 language variants. You can still achieve an Umbraco 7 like multi-language setup if you like. (Separate content trees.)

jessevdp avatar May 06 '20 10:05 jessevdp