Adding hreflang to head section. How to get translated url

2 месяца назад
I'm trying to update my NopCommerce 4.20 webshop and implement SEO suggestions.
One suggestion is to add `hreflang` links to the header of each page, pointing to the different translated pages.

I implemented the following code in `_Root.Head.cshtml`:

    // Languages for hreflang tags:
    var allLanguages = languageService.GetAllLanguages();
    var segments = webHelper.GetThisPageUrl(false).Split('/');
    var pageUrl = "";
    for (var i = 4; i < segments.Length; i++)
    {
        pageUrl = $"{pageUrl}/{segments[i]}";
    }

    <!-- Show languages -->
    @foreach (var language in allLanguages)
    {
        var hreflang = languageService.GetTwoLetterIsoLanguageName(language).ToLower();
        var url = $"{webHelper.GetStoreLocation()}{hreflang}/{pageUrl}";
        <link rel="alternate" hreflang="@hreflang" href="@url" />
    }


This results in:
  <link rel="alternate" hreflang="en" href="https://www.josephiena.nl/en/foto-draak-in-de-lucht-digif-006">
  <link rel="alternate" hreflang="nl" href="https://www.josephiena.nl/nl/foto-draak-in-de-lucht-digif-006">

When I'm on the NL-version of the page. Although the EN link is working, the actual URL should be https://www.josephiena.nl/en/photo-dragon-in-the-sky-digif-006, because I also translated the title and thus the `Search engine friendly page name` is also translated.

How do I get the correct translated URL?
2 месяца назад
This does not look right
    var pageUrl = "";
    for (var i = 4; i < segments.Length; i++)
    {
        pageUrl = $"{pageUrl}/{segments[i]}";
    }


First, it's outside your next loop, thus the last language's calculated pageUrl will apply to all.
Also, I don't think it's correct because you keep replacing pageUrl in the loop (not ??appending segments??)
  pageUrl = $"{pageUrl}/{segments[i]}";
один месяц назад
This plugin adds this tag
https://www.nopcommerce.com/en/google-multi-language-sitemap-foxnetsoftcom