In order to make sure language is embedded in the local links and not on the cross site link, you will need to customize the link provider
as below. Inside the custom link provider, GetItemUrl
function is overridden to embed the language as always
when the language embedding is enabled for the site and never
when language embedding is disabled on the site.
using Microsoft.Extensions.DependencyInjection;
using Sitecore.Abstractions;
using Sitecore.Data.Items;
using Sitecore.DependencyInjection;
using Sitecore.Diagnostics;
using Sitecore.Links;
using Sitecore.Links.UrlBuilders;
using Sitecore.XA.Foundation.Multisite;
using Sitecore.XA.Foundation.Multisite.Extensions;
public class CustomLinkProvider : LinkProvider
{
private readonly BaseFactory _factory;
public CustomLinkProvider()
: this(ServiceProviderServiceExtensions.GetService<BaseFactory>(ServiceLocator.ServiceProvider))
{
}
public CustomLinkProvider(BaseFactory factory) : base(factory)
{
this._factory = factory;
}
public override string GetItemUrl(Item item, ItemUrlBuilderOptions options)
{
Assert.ArgumentNotNull((object)item, nameof(item));
Assert.ArgumentNotNull((object)options, nameof(options));
var siteInfoResolver = ServiceProviderServiceExtensions.GetService<ISiteInfoResolver>(ServiceLocator.ServiceProvider);
var siteInfo = siteInfoResolver.GetSiteInfo(item);
if (siteInfo != null)
{
var site = Sitecore.Configuration.Factory.GetSite(siteInfo.Name);
if (site.IsLanguageEmbeddingEnabled())
{
options.LanguageEmbedding = LanguageEmbedding.Always;
}
else
{
options.LanguageEmbedding = LanguageEmbedding.Never;
}
}
return base.GetItemUrl(item, options);
}
}
This custom link provider then can be applied on the international site
as below.
<add name="internationalProvider" type="SitecoreScaledExtensions.Pipelines.CustomLinkProvider,SitecoreScaledExtensions" resolve="true" languageEmbedding="always" lowercaseUrls="true" />
Lastly we need to make sure Rendering.SiteResolvingMatchCurrentLanguage
is patched as below. This setting decides whether language should be taken into consideration when a cross-site
link is built.
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Rendering.SiteResolvingMatchCurrentLanguage">
<patch:attribute name="value">false</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
Once all above changes are applied, links on the local site
will contain language
in the url whereas cross site link
will contain no language on the url inside the international site.
Hope this helps!!! Let me know in case you face any issues.