<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Haakon Peder Haugsten</title> <link>https://world.optimizely.com/blogs/haakon-peder-haugsten/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Handling Nynorsk and Bokm&#229;l in Optimizely CMS</title>            <link>https://world.optimizely.com/blogs/haakon-peder-haugsten/dates/2024/5/mixing-bokmal-and-nynorsk-pages/</link>            <description>&lt;p&gt;Warning: Blog post about Norwegian language handling (but might be applicable to other languages and/or use cases).&lt;/p&gt;
&lt;p&gt;Optimizely have flexible and several powerful ways of working with languages. From automatic translation via Azure Cognitive Services or Chat GPT to handling fallback. A customer can easily set up a new language and have it translated in one go with builtin workflows and project management.&lt;/p&gt;
&lt;h2&gt;Use case&lt;/h2&gt;
&lt;p&gt;In Norway, we have two official written forms of the Norwegian language: Bokm&amp;aring;l and Nynorsk. There is a law stating that public websites must publish at least 25% of their content in Nynorsk. This can be achieved in various ways, but since the languages are quite similar, many websites choose to mix articles in both language forms. By using standard language handling and fallback in Optimizely CMS, it&#39;s easy to achieve this in an organized way. You can easily display meta tags for the language, use correct labels or show a different logo for pages in the two language forms.&lt;/p&gt;
&lt;p&gt;Let&#39;s see how this can be set up with the Alloy templates.&lt;/p&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Add Bokm&amp;aring;l and Nynorsk to the website languages. &lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;&lt;img src=&quot;/link/4f1d43007ebc43a6a4662db2e9402714.aspx&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Set the Web address prefix for Bokm&amp;aring;l to &amp;ldquo;no&amp;rdquo; and Nynorsk to &amp;ldquo;nn&amp;rdquo;.&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;&lt;img src=&quot;/link/16beff1662cf48a888203ee684d5cd1e.aspx&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;&lt;img src=&quot;/link/e714347698254e6a997f92b983889e5e.aspx&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Enable the languages and set Nynorsk to fall back language for Bokm&amp;aring;l.&lt;/span&gt;&lt;/h2&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;&lt;img src=&quot;/link/942d6c1c4f324028b3121f6b5ca9381c.aspx&quot; /&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Redirect urls from /nn to /no&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Create a middleware to redirect urls from /nn to /no. This is mainly for editors using the &quot;View on website&quot; link but will also ensure that visitors will always visit the site with the correct url.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Should this be the case for the entire site or should parts of the site be available in both languages? Depending on the actual requirements the middleware could be something like:&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public class RedirectToBokmaalMiddleware
{
    private readonly RequestDelegate _next;
    
    public RedirectToBokmaalMiddleware(RequestDelegate next)
    {
        _next = next;
    }
    
    public async Task InvokeAsync(HttpContext httpContext)
    {
        if (httpContext.Request.Path.StartsWithSegments(&quot;/nn&quot;))
        {
            var path = httpContext.Request.Path.Value;
            var newUrl = path.StartsWith(&quot;/nn&quot;) ? &quot;/no&quot; + path.Substring(3) : path;
            httpContext.Response.Redirect(newUrl);
        }
        
        await _next(httpContext);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Use content language to translate labels&lt;/h2&gt;
&lt;p&gt;To display labels and other texts from the LocalizationService in the content language (Nynorsk on Nynorsk pages) you will need to do some modifications. Add translations for labels and other texts for both languages to the XML-language files. Create an IHtmlHelper extension method and use this instead of the built-in extension without the language parameter.&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;public static class HtmlHelperExtensions
{
    private static readonly LocalizationService LocalizationService = LocalizationService.Current;
    
    public static IHtmlContent Translate(this IHtmlHelper html, string translationKey, CultureInfo contentCulture)
    {
        var translation = LocalizationService.GetStringByCulture(translationKey, contentCulture);
        return new HtmlString(translation);
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;&lt;span&gt;Install Optimizely Languages (EPiServer.Labs.LanguageManager)&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;I will also recommend installing Optimizely Languages (EPiServer.Labs.LanguageManager). This addon is a must for all Optimizely sites with more than one language.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/72f4767689ff40b897d633b06f5d9a65.aspx&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;This is how the Alloy site can be customized to mix Bokm&amp;aring;l and Nynorsk. Depending on your Optimizely CMS implementation you might need to do other adjustments aswell.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Summary&lt;/span&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Add Bokm&amp;aring;l and Nynorsk to the website languages.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Set the Web address prefix for Bokm&amp;aring;l to &amp;ldquo;no&amp;rdquo; and Nynorsk to &amp;ldquo;nn&amp;rdquo;.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Set Nynorsk to fall back language for Bokm&amp;aring;l.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Redirect urls from /nn to /no&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Use content language to translate labels&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Install Optimizely Languages (EPiServer.Labs.LanguageManager)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;</description>            <guid>https://world.optimizely.com/blogs/haakon-peder-haugsten/dates/2024/5/mixing-bokmal-and-nynorsk-pages/</guid>            <pubDate>Thu, 05 Sep 2024 10:05:43 GMT</pubDate>           <category>Blog post</category></item><item> <title>Inspect In Index is finally back</title>            <link>https://world.optimizely.com/blogs/haakon-peder-haugsten/dates/2024/5/inspect-in-index-is-finally-back/</link>            <description>&lt;p&gt;EPiCode.InspectInIndex was &lt;a href=&quot;/link/3c979d4041a347128fedc629f8804d0f.aspx&quot;&gt;released 9 years ago&lt;/a&gt;. The Search and Navigation addon is now finally upgraded to support Optimizely CMS 12.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/BVNetwork/InspectInIndex&quot;&gt;https://github.com/BVNetwork/InspectInIndex&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://nuget.optimizely.com/package/?id=EPiCode.InspectInIndex&quot;&gt;https://nuget.optimizely.com/package/?id=EPiCode.InspectInIndex&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/link/11c7c8e071764fe6b17a487022375cc4.aspx&quot; width=&quot;858&quot; height=&quot;483&quot; /&gt;&lt;/p&gt;</description>            <guid>https://world.optimizely.com/blogs/haakon-peder-haugsten/dates/2024/5/inspect-in-index-is-finally-back/</guid>            <pubDate>Fri, 14 Jun 2024 10:12:29 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>