4

I'm trying to figure out of this is even possible, and if so, how to go about it. I have a requirement that URLs be localized to the target language, but that the items are common and translated. ex: the item at

/sitecore/Content/Home/About/ContactUs

would be reachable at:

www.example.ca/About/ContactUs

for the en variant, but the french translation could have a URL along the lines of:

www.example.ca/Sur/ContactezNous

Is this even possible? Have you tackled it yourself? What was your approach?

6

This is ootb functionality if you use the display names. First of all, set the display names of the items (like displayname "Sur" for the "about" item in French).

Then patch the LinkManager settings like this:

<sitecore>
    <linkManager>
      <providers>
        <add name="sitecore">
          <patch:attribute name="useDisplayName">true</patch:attribute>
        </add>
      </providers>
    </linkManager>
</sitecore>

This will tell Sitecore to use the display names when creating urls, resulting in the behavior you requested.

Sitecore will be able to resolve the url's as long as the language is known and set to the one needed for your request. As that might not always be the case, the best thing to do is to add the language to the url - this will result in www.example.ca/en/About/ContactUs and www.example.ca/fr/Sur/ContactezNous. To do this, set the languageEmbedding parameter to always by adding this line in the config above:

          <patch:attribute name="languageEmbedding">always</patch:attribute>
5
  • Will that handle resolving the item from the URL as well, or just the link generation? – GoetzOnline Nov 15 '16 at 16:18
  • 1
    Resolving should work just fine. Just be careful that when no display name is set or the names should be the same in both languages Sitecore might not be able to detect the language you want - in that case it would be better to include the language in the url as well by setting languageEmbedding to "always". – Gatogordo Nov 15 '16 at 16:41
  • 1
    Sitecore is not able to resolve the Language from the URL, you need to either set languageEmbedding=always or pass it through as an ?sc_lang parameter. Without those, browsing from and english to french URL for example will mean the item does not resolve (since the language cookie will be set to english/default) – jammykam Nov 15 '16 at 16:48
  • Indeed - will add it to the answer. – Gatogordo Nov 15 '16 at 17:07
  • You can also completely override the Sitecore.Links.LinkProvider class and customize the URL as per your need, but this will require lot more time and effort. – Naveed Ahmad Nov 15 '16 at 20:54
1

This is in addition to the accepted answer of Gatogordo.

I had a similar question, while slightly differ on the domain url... I do want 1 content item that supports two languages too, but I do not like the idea of ?sc_lang=nl-NL or the /nl-nl/ part in the url. I want to have one language per domain. So, if you have a second domain, like example.com for English targeted content, and example.nl for Dutch targeted content, then you could use this patch config to force a language for the context / domain.

<configuration>
  <sitecore>
    <sites>
      <site name="example" patch:before="site[@name='website']"
        hostName="example.nl"
        targetHostName="example.nl" language="nl-NL" enableTracking="true"
        virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content/sites/Example" startItem="/home"
        database="master" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="50MB"
        registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="0" filteredItemsCacheSize="10MB"
        enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false"
        cacheRenderingParameters="true" renderingParametersCacheSize="10MB" mvcArea="Example"
        dictionaryDomain="SitesExampleDictionary" />
      <site name="exampleEN" patch:before="site[@name='website']"
        hostName="example.com"
        targetHostName="example.com" language="en" enableTracking="true"
        virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content/sites/Example" startItem="/home"
        database="master" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="50MB"
        registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="0" filteredItemsCacheSize="10MB"
        enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false"
        cacheRenderingParameters="true" renderingParametersCacheSize="10MB" mvcArea="Example"
        dictionaryDomain="SitesExampleDictionary" />
    </sites>
  </sitecore>
</configuration>

Note that database is set to master in this config sample, you might need to change it to web.

Tailor this configuration to your needs, apply the solution above from @Gatogordo as well for SEO score.

Another tip for in your mvc layout cshtml, add the lang attribute to your html-tag:

<html lang="@Model.Item.Language.CultureInfo.TwoLetterISOLanguageName">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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