0

I'm working on an SXA multilingual site, and I've enabled the embed language option, now I can see the URL in the navigation has language code + region code

Example:

  • mysite/fr-fr/mypage
  • mysite/it-it/mypage

But I want to display the URL without the region code

To be like the following :

  • mysite/fr/mypage

  • mysite/it/mypage

Any idea please?

2
  • For this you need to customize, I don't think it is possible OOTB Jun 17, 2022 at 7:46
  • The easiest way to do this is probably to remove the region from the language itself. That way your urls will be correct. Not sure what will happen to existing content however, you might need to write a script to change the language on the existing items.
    – Gatogordo
    Jun 17, 2022 at 7:52

1 Answer 1

1

I found the fix of this issue

1- create a new patch

 <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
      <sitecore role:require="Standalone or ContentManagement or ContentDelivery" search:require="solr">
        <links>
          <itemUrlBuilder>
            <patch:attribute name="type">Mysite.Foundation.Multisite.Pipelines.NavigationItemUrlBuilder, Mysite.Foundation.Multisite</patch:attribute>
          </itemUrlBuilder>
        </links>
      </sitecore>
    </configuration>

2- Implement the ItemUrlBuilder

public class NavigationItemUrlBuilder : ItemUrlBuilder
    {
        public NavigationItemUrlBuilder(DefaultItemUrlBuilderOptions defaultOptions) : base(defaultOptions)
        {
        }

        public override string Build(Item item, ItemUrlBuilderOptions options)
        {
            //enable the Language Embedding for non- english languages 
        options.LanguageEmbedding = item.Language.Name.Equals("en") ? Sitecore.Links.LanguageEmbedding.Never : Sitecore.Links.LanguageEmbedding.Always;
        var RegionName = item.Language.CultureInfo.TwoLetterISOLanguageName.ToLower() ?? "";
        return item.Language.Name.Equals("en") ? base.Build(item, options) : base.Build(item, options).ToLower().ReplaceFirst(item.Language.Name.ToLower(), RegionName);
        }

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.