Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1461 posts 1883 karma points
    Apr 18, 2018 @ 10:23
    Gordon Saxby
    0

    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)?

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Apr 18, 2018 @ 11:23
    Nik
    0

    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

  • Gordon Saxby 1461 posts 1883 karma points
    Apr 18, 2018 @ 11:30
    Gordon Saxby
    0

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

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Apr 18, 2018 @ 13:28
    Nik
    0

    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

  • Gordon Saxby 1461 posts 1883 karma points
    Apr 18, 2018 @ 14:37
    Gordon Saxby
    0

    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.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Apr 18, 2018 @ 14:56
    Nik
    0

    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.

  • Gordon Saxby 1461 posts 1883 karma points
    Apr 18, 2018 @ 15:01
    Gordon Saxby
    1

    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!

Please Sign in or register to post replies

Write your reply to:

Draft