Showing posts with label multi language. Show all posts
Showing posts with label multi language. Show all posts

Tuesday, November 6, 2018

Extend Sitecore SXA metadata with hreflang and better favicon support (pt. 2 - hreflang)

When you're creating a multi lingual site, you probably want to tell the search engines to tell where to find the content in a different language. The way to do this is using hreflang.

Using the hreflang from the MetadataExtended this is really easy peasy!

You'll only have to add the hreflang rendering to the metadata partial design (like with the FaviconExtension in the previous post) manually, the rest is in the config.

The idea is that you don't use the language cookie, but always use the language from the url. To do so we need to enable the custom link manager and add a pipeline to remove the language cookie:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <linkManager defaultProvider="sitecore">
      <providers>
        <add name="ExtendedLinkProvider" 
             type="SXA.Feature.MetadataExtended.Providers.ExtendedLinkProvider, SXA.Feature.MetadataExtended" 
             cacheExpiration="5" 
             addAspxExtension="false" 
             alwaysIncludeServerUrl="false" 
             lowercaseUrls="true" 
             encodeNames="true" 
             languageEmbedding="always" 
             languageLocation="filePath" 
             shortenUrls="false" 
             useDisplayName="true">
        </add>
      </providers>
      <patch:attribute name="defaultProvider">switchableLinkProvider</patch:attribute>
    </linkManager>
    <pipelines>
      <httpRequestProcessed>
        <processor type="SXA.Feature.MetadataExtended.Pipelines.HttpRequestProcessed.LanguageCookieRemover, SXA.Feature.MetadataExtended" resolve="true" />
      </httpRequestProcessed>
    </pipelines>
  </sitecore>
</configuration>

Then enable the ExtendedLinkProvider in your SXA site, and disable language cookie support. Browse to /sitecore/content/{tenant}/{site}/Settings/Site Grouping/{site} and update the Link Provider Name. You'll also need to set the disableLanguageCookie to true:


The ExtendedLinkProvider does a bit of magic, it adds the language to the url for all languages, except for 'en'. You can always modify this behavior, but I like it this way.

To get the right localized url which uses the displayname instead of the item name (see LinkManager config above 'useDisplayName'), you'll have to do something weird, I would expect that it works when you use the language switcher it will pick up the displayname in that language. Too bad it doesn't do that, you'll need to get the language item. But the language item itself doesn't add the language in front of the url, so wrapping it around a LanguageSwitcher does the magic:

var language = Language.Parse(languageCode);

// We have to get the language item for the right display-name
var languageItem = item.Database.GetItem(item.ID, language);

// And use the Language switcher to get the right language in the url
using (new LanguageSwitcher(language))
{
    return LinkManager.GetItemUrl(languageItem); 
    // NOTE: The actual code has an option to return the full server url
    // which is needed for hreflang
}

With this, you'll get the hreflang:


If you have any questions or issues, please hit me a message below or file a ticket on:
https://github.com/luuksommers/sitecore-sxa-metadataextended

[dutch]Computer ze![/dutch]

Luuk

Sunday, February 19, 2012

Export and import a large set of resx resources

For a project at work we needed to export a lot of resource tables to excel and let an external party validate, correct and complement them. For this we used simple excel sheets. But then the application grows larger, so do the resource tables. With more than 13 languages this becomes a huge pain in the ***. To overcome this we've build a Resource Extractor which uses NPOI to export and import the data.

Currently only the Export functions are included. Once the import is finished I'll write another more complete post.


If you have even more translations to do you can also use dedicated websites so external parties can help you even better with translating. The one I've seen which looks very impressive is amanuens. If you have any experience with them or any other, please let us know in the comments.

The source is available at GitHub https://github.com/luuksommers/resourceextractor