Skip to content

Instantly share code, notes, and snippets.

@perosb
Last active September 11, 2021 15:56

Revisions

  1. perosb revised this gist Sep 11, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -57,4 +57,4 @@ That's it.
    you still need to install the custom cultures on the CM/CD side as usual.
    if you're to run RendeingHost in Windows container, you could also just install the cultures as with CM/CD and they should be picked up by `GetCultures()` method.

    Cross posted to [medium blog)[https://medium.com/@osbeck.per/sitecore-10-1-and-net-core-and-custom-cultures-on-linux-7b8e8719bd8e?sk=c143403b2395ce253d57cec5a9c9cb2f]
    Cross posted to [medium blog](https://medium.com/@osbeck.per/sitecore-10-1-and-net-core-and-custom-cultures-on-linux-7b8e8719bd8e?sk=c143403b2395ce253d57cec5a9c9cb2f)
  2. perosb revised this gist Sep 11, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -57,4 +57,4 @@ That's it.
    you still need to install the custom cultures on the CM/CD side as usual.
    if you're to run RendeingHost in Windows container, you could also just install the cultures as with CM/CD and they should be picked up by `GetCultures()` method.

    Cross posted to https://medium.com/@osbeck.per/sitecore-10-1-and-net-core-and-custom-cultures-on-linux-7b8e8719bd8e?sk=c143403b2395ce253d57cec5a9c9cb2f
    Cross posted to [medium blog)[https://medium.com/@osbeck.per/sitecore-10-1-and-net-core-and-custom-cultures-on-linux-7b8e8719bd8e?sk=c143403b2395ce253d57cec5a9c9cb2f]
  3. perosb revised this gist Sep 11, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -57,3 +57,4 @@ That's it.
    you still need to install the custom cultures on the CM/CD side as usual.
    if you're to run RendeingHost in Windows container, you could also just install the cultures as with CM/CD and they should be picked up by `GetCultures()` method.

    Cross posted to https://medium.com/@osbeck.per/sitecore-10-1-and-net-core-and-custom-cultures-on-linux-7b8e8719bd8e?sk=c143403b2395ce253d57cec5a9c9cb2f
  4. perosb revised this gist Sep 10, 2021. No changes.
  5. perosb revised this gist Sep 10, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## Sitecore 10.1 and .NET Core Rendering Host with Custom Cultures
    ## Sitecore 10.1 and .NET Core Rendering Host with Custom Cultures on Linux

    In traditional Sitecore you can always install custom cultures using .NET Framework (unless you're on PaaS ;).

  6. perosb revised this gist Sep 10, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ services.Configure<RouteOptions>(options =>
    ```
    That's it.

    ####Note
    ### Note
    you still need to install the custom cultures on the CM/CD side as usual.
    if you're to run RendeingHost in Windows container, you could also just install the cultures as with CM/CD and they should be picked up by `GetCultures()` method.

  7. perosb revised this gist Sep 10, 2021. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    In traditional Sitecore you can always install custom cultures using .NET Framework (unless you're on PaaS ;).

    If you're running .NET Core RenderingHost on a Alpine linux based container, you're options are a bit more limited.
    If you're running .NET Core RenderingHost on a alpine linux based container, you're options are a bit more limited.
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom [.dat file first etc](https://github.com/unicode-org/icu).

    However, it turns out that you can actually create `new CultureInfo("en-IS")` without them being installed.
    @@ -51,5 +51,9 @@ services.Configure<RouteOptions>(options =>
    });

    ```
    That's it.

    ####Note
    you still need to install the custom cultures on the CM/CD side as usual.
    if you're to run RendeingHost in Windows container, you could also just install the cultures as with CM/CD and they should be picked up by `GetCultures()` method.

    Note: you still need to install the custom cultures on the CM/CD side as usual.
  8. perosb revised this gist Sep 10, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Sitecore 10.1 and .NET Core Rendering Host with Custom Cultures

    In traditional Sitecore you can always insstall custom cultures using .NET Framework (unless you're on PaaS ;).
    In traditional Sitecore you can always install custom cultures using .NET Framework (unless you're on PaaS ;).

    If you're running .NET Core RenderingHost on a Alpine linux based container, you're options are a bit more limited.
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom [.dat file first etc](https://github.com/unicode-org/icu).
  9. perosb revised this gist Sep 10, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,6 @@ services.Configure<RouteOptions>(options =>
    }
    });

    ```
    ```

    Note: you still need to install the custom cultures on the CM/CD side as usual.
  10. perosb revised this gist Sep 10, 2021. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,17 @@ public bool Match(HttpContext httpContext, IRouter route, string routeKey, Route
    }

    return culture != null;

    }
    }
    ```

    Next, in your `Startup.cs` replace Sitecore version with your class:
    ```csharp
    services.Configure<RouteOptions>(options =>
    {
    if (options.ConstraintMap.ContainsKey(RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix))
    {
    options.ConstraintMap[RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix] = typeof(LanguageRouteConstraint);
    }
    });

    ```
  11. perosb revised this gist Sep 10, 2021. 1 changed file with 23 additions and 23 deletions.
    46 changes: 23 additions & 23 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -10,34 +10,34 @@ There is however one culprit, these cultures are not included in the `GetCulture

    Luckily you can replace the contraint added by Sitecore with a custom version that looks like
    ```csharp
    public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
    public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
    {
    if (!values.ContainsKey(RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix))
    {
    return false;
    }

    var lang = values[RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix].ToString();
    CultureInfo culture = null;
    if (!string.IsNullOrEmpty(lang))
    {
    culture = CultureInfo.GetCultures(CultureTypes.AllCultures)
    .SingleOrDefault(c => c.IetfLanguageTag.Equals(lang, StringComparison.InvariantCultureIgnoreCase));

    if (culture == null && Regex.IsMatch(lang, "^[a-z]{2,3}(?:-[a-z]{2,3}(?:-[a-z]{4})?)?$"))
    {
    if (!values.ContainsKey(RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix))
    try
    {
    return false;
    culture = new CultureInfo(lang);
    }

    var lang = values[RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix].ToString();
    CultureInfo culture = null;
    if (!string.IsNullOrEmpty(lang))
    catch (Exception ex)
    {
    culture = CultureInfo.GetCultures(CultureTypes.AllCultures)
    .SingleOrDefault(c => c.IetfLanguageTag.Equals(lang, StringComparison.InvariantCultureIgnoreCase));

    if (culture == null && Regex.IsMatch(lang, "^[a-z]{2,3}(?:-[a-z]{2,3}(?:-[a-z]{4})?)?$"))
    {
    try
    {
    culture = new CultureInfo(lang);
    }
    catch (Exception ex)
    {
    }
    }
    }

    return culture != null;

    }
    }

    return culture != null;

    }
    }
    ```
  12. perosb revised this gist Sep 10, 2021. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ However, it turns out that you can actually create `new CultureInfo("en-IS")` wi
    There is however one culprit, these cultures are not included in the `GetCultures` method. This method is used internally by Sitecore to validate the that the route contains a valid culture for the localization to work.

    Luckily you can replace the contraint added by Sitecore with a custom version that looks like
    `csharp
    ```csharp
    public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
    {
    if (!values.ContainsKey(RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix))
    @@ -39,4 +39,5 @@ Luckily you can replace the contraint added by Sitecore with a custom version th
    return culture != null;

    }
    }`
    }
    ```
  13. perosb revised this gist Sep 10, 2021. 1 changed file with 37 additions and 1 deletion.
    38 changes: 37 additions & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,40 @@
    In traditional Sitecore you can always insstall custom cultures using .NET Framework (unless you're on PaaS ;).

    If you're running .NET Core RenderingHost on a Alpine linux based container, you're options are a bit more limited.
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom [.dat file first etc](https://github.com/unicode-org/icu).
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom [.dat file first etc](https://github.com/unicode-org/icu).

    However, it turns out that you can actually create `new CultureInfo("en-IS")` without them being installed.
    There is however one culprit, these cultures are not included in the `GetCultures` method. This method is used internally by Sitecore to validate the that the route contains a valid culture for the localization to work.

    Luckily you can replace the contraint added by Sitecore with a custom version that looks like
    `csharp
    public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
    {
    if (!values.ContainsKey(RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix))
    {
    return false;
    }

    var lang = values[RenderingEngineConstants.SitecoreLocalization.RequestCulturePrefix].ToString();
    CultureInfo culture = null;
    if (!string.IsNullOrEmpty(lang))
    {
    culture = CultureInfo.GetCultures(CultureTypes.AllCultures)
    .SingleOrDefault(c => c.IetfLanguageTag.Equals(lang, StringComparison.InvariantCultureIgnoreCase));

    if (culture == null && Regex.IsMatch(lang, "^[a-z]{2,3}(?:-[a-z]{2,3}(?:-[a-z]{4})?)?$"))
    {
    try
    {
    culture = new CultureInfo(lang);
    }
    catch (Exception ex)
    {
    }
    }
    }

    return culture != null;

    }
    }`
  14. perosb revised this gist Sep 10, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,4 @@
    In traditional Sitecore you can always insstall custom cultures using .NET Framework (unless you're on PaaS ;).

    If you're running .NET Core RenderingHost on a Alpine linux based container, you're options are a bit more limited.
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom (.dat file first etc)[https://github.com/unicode-org/icu].
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom [.dat file first etc](https://github.com/unicode-org/icu).
  15. perosb revised this gist Sep 10, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,6 @@
    ## Sitecore 10.1, .NET Core Rendering Host with Custom Cultures
    ## Sitecore 10.1 and .NET Core Rendering Host with Custom Cultures

    In traditional Sitecore you can always insstall custom cultures using .NET Framework (unless you're on PaaS ;).

    If you're running .NET Core RenderingHost on a Alpine linux based container, you're options are a bit more limited.
    One way would be to build additional cultures into alpine but it's quite a hassle. You need to build the custom (.dat file first etc)[https://github.com/unicode-org/icu].
  16. perosb revised this gist Sep 10, 2021. No changes.
  17. perosb created this gist Sep 10, 2021.
    1 change: 1 addition & 0 deletions sitecore-dotnetcore-customcultures.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ## Sitecore 10.1, .NET Core Rendering Host with Custom Cultures