I need to get the URL of a specific node in each of the languages defined for the site - not just the Url for the current culture / language.
For a language switcher page, I am writing links for each language. It's easy enough to get the root URL, but I would like to get the language specific URL for the "Referrer" page.
Ignoring the potential issues with getting the referrer page (!), how can I get the Language specific URL for each language (E.g. English, French, German, etc)?
I'm not certain, but UrlProvider.GetOtherUrls() using this might be a helpful start point. I was asking a similar question in Slack and was pointed to this but as of yet I've not had a chance to play with it as my requirements changed slightly after asking.
Presumably, you have the current content node at the point you are trying to do this. So you could get the main URL from the content node and then all of the others using the UrlProvider.GetOtherUrls() method?
If you know that the GB one doesn't start in GB but all the others do, could you iterate around the list of URLs and assign the languages based on them. But your final check is if none of them match then it's English?
I get the problem, this side of multi-lingual isn't the easiest and I've tried various different solutions. None of which I'm happy with. But I usually end up working on the premise that editors cannot add a new language, so as part of adding a new language I update my language switcher to handle it. Wish it was simpler to tie language/culture to hostname on the url when creating these sorts of things.
The language switcher page itself works fine, in that it gets the list of defined (used) languages and writes a link for each, displays a flag, writes the text in the local language, etc.
The one issue I now have is that the customer wants to go back to the previous page, after going to the language switcher and choosing a language. I just need to figure out how to get / identify each of the language URLs for that previous page!
I might be getting there - I'll let you know if I figure it!
Get specific language URL
I need to get the URL of a specific node in each of the languages defined for the site - not just the Url for the current culture / language.
For a language switcher page, I am writing links for each language. It's easy enough to get the root URL, but I would like to get the language specific URL for the "Referrer" page.
Ignoring the potential issues with getting the referrer page (!), how can I get the Language specific URL for each language (E.g. English, French, German, etc)?
Hey Gordon,
I'm not certain, but
UrlProvider.GetOtherUrls()
using this might be a helpful start point. I was asking a similar question in Slack and was pointed to this but as of yet I've not had a chance to play with it as my requirements changed slightly after asking.Nik
Hi Nik,
I think GetOtherUrls excludes the "main" URL, so I would also need the "main" URL.
It looks like I need to use similar code to write my own method ... ?
Hi Gordon,
Presumably, you have the current content node at the point you are trying to do this. So you could get the main URL from the content node and then all of the others using the UrlProvider.GetOtherUrls() method?
Nik
Hi Nik,
the problem is - GetOtherUrls() returns an IEnumerable
I would search the URL for the culture (e.g. /fr/), but that won't work for English, as we don't have "/gb/" in the URL.
If you know that the GB one doesn't start in GB but all the others do, could you iterate around the list of URLs and assign the languages based on them. But your final check is if none of them match then it's English?
I get the problem, this side of multi-lingual isn't the easiest and I've tried various different solutions. None of which I'm happy with. But I usually end up working on the premise that editors cannot add a new language, so as part of adding a new language I update my language switcher to handle it. Wish it was simpler to tie language/culture to hostname on the url when creating these sorts of things.
The language switcher page itself works fine, in that it gets the list of defined (used) languages and writes a link for each, displays a flag, writes the text in the local language, etc.
The one issue I now have is that the customer wants to go back to the previous page, after going to the language switcher and choosing a language. I just need to figure out how to get / identify each of the language URLs for that previous page!
I might be getting there - I'll let you know if I figure it!
is working on a reply...