Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7104 karma points c-trib
    Jan 04, 2017 @ 19:00
    Nicholas Westby
    0

    "Culture is Not Supported" Error on Dictionary in Settings Section

    I created some languages in Umbraco, including "English (Austria)", as shown here:

    Languages

    That works fine on my local (Windows 10). However, when I deploy to dev (Windows Server 2012), I get this error when I click on "Dictionary" (in the Settings section):

    Culture is Not Supported

    For the search engines, here's the text version of that image:

    Server Error in '/' Application.
    
    Culture is not supported.
    Parameter name: name
    en-AT is an invalid culture identifier.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Globalization.CultureNotFoundException: Culture is not supported.
    Parameter name: name
    en-AT is an invalid culture identifier.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace: 
    
    
    [CultureNotFoundException: Culture is not supported.
    Parameter name: name
    en-AT is an invalid culture identifier.]
       System.Globalization.CultureInfo.GetCultureInfo(String name) +13714447
       umbraco.presentation.settings.DictionaryItemList.Page_Load(Object sender, EventArgs e) +89
       System.Web.UI.Control.OnLoad(EventArgs e) +109
       umbraco.BasePages.BasePage.OnLoad(EventArgs e) +38
       System.Web.UI.Control.LoadRecursive() +68
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4498
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1087.0
    

    My guess is that different versions of Windows handle cultures differently. I came across this thread that links to some other threads: https://our.umbraco.org/forum/developers/extending-umbraco/71148-create-new-language-culture

    Seems like I need to register the cultures. Is there something I'm missing, or is registering the cultures using some custom C# code the standard way of handling this?

    Umbraco 7.5.6.

  • Nicholas Westby 2054 posts 7104 karma points c-trib
    Jan 04, 2017 @ 20:18
    Nicholas Westby
    0

    I ended up creating a console application to register the cultures I need:

    // Namespaces.
    using System;
    using System.Globalization;
    using System.Linq;
    
    /// <summary>
    /// Console application that ensures the necessary cultures exist on the system.
    /// </summary>
    /// <remarks>
    /// This console application was necessary because some systems don't contain the necessary
    /// cultures, and this logic couldn't reside within the website as the creation of new
    /// cultures requires administrative privileges.
    /// </remarks>
    class Program
    {
    
        #region Main
    
        /// <summary>
        /// Main entry point for the console application.
        /// </summary>
        static void Main(string[] args)
        {
            EnsureCulturesExist();
        }
    
        #endregion
    
        #region Private Methods
    
        /// <summary>
        /// Ensures all the necessary cultures exist (e.g., "en-AT" doesn't exist on some computers).
        /// </summary>
        /// <remarks>
        /// Some of this code comes from https://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.aspx
        /// and http://stackoverflow.com/a/16476935/2052963.
        /// </remarks>
        private static void EnsureCulturesExist()
        {
    
            // Variables.
            var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
            var ignoreCase = StringComparison.InvariantCultureIgnoreCase;
    
            // Reusable cultures/regions.
            var english = CultureInfo.CreateSpecificCulture("en-US");
            var austria = new RegionInfo("AT");
            var germany = new RegionInfo("DE");
            var sweden = new RegionInfo("SE");
            var switzerland = new RegionInfo("CH");
    
            // Register English (Austria) / "en-AT".
            var englishAustriaExists = allCultures.Any(x => "en-AT".Equals(x.Name, ignoreCase));
            if (!englishAustriaExists)
            {
                var englishAustria = new CultureAndRegionInfoBuilder("en-AT", CultureAndRegionModifiers.None);
                englishAustria.LoadDataFromCultureInfo(english);
                englishAustria.LoadDataFromRegionInfo(austria);
                englishAustria.CultureEnglishName = "English (Austria)";
                englishAustria.CultureNativeName = "English (Austria)";
                TryRegisterCulture(englishAustria);
            }
    
            // Register English (Germany) / "en-DE".
            var englishGermanyExists = allCultures.Any(x => "en-DE".Equals(x.Name, ignoreCase));
            if (!englishGermanyExists)
            {
                var englishGermany = new CultureAndRegionInfoBuilder("en-DE", CultureAndRegionModifiers.None);
                englishGermany.LoadDataFromCultureInfo(english);
                englishGermany.LoadDataFromRegionInfo(germany);
                englishGermany.CultureEnglishName = "English (Germany)";
                englishGermany.CultureNativeName = "English (Germany)";
                TryRegisterCulture(englishGermany);
            }
    
            // Register English (Sweden) / "en-SE".
            var englishSwedenExists = allCultures.Any(x => "en-SE".Equals(x.Name, ignoreCase));
            if (!englishSwedenExists)
            {
                var englishSweden = new CultureAndRegionInfoBuilder("en-SE", CultureAndRegionModifiers.None);
                englishSweden.LoadDataFromCultureInfo(english);
                englishSweden.LoadDataFromRegionInfo(sweden);
                englishSweden.CultureEnglishName = "English (Sweden)";
                englishSweden.CultureNativeName = "English (Sweden)";
                TryRegisterCulture(englishSweden);
            }
    
            // Register English (Switzerland) / "en-CH".
            var englishSwitzerlandExists = allCultures.Any(x => "en-CH".Equals(x.Name, ignoreCase));
            if (!englishSwitzerlandExists)
            {
                var englishSwitzerland = new CultureAndRegionInfoBuilder("en-CH", CultureAndRegionModifiers.None);
                englishSwitzerland.LoadDataFromCultureInfo(english);
                englishSwitzerland.LoadDataFromRegionInfo(switzerland);
                englishSwitzerland.CultureEnglishName = "English (Switzerland)";
                englishSwitzerland.CultureNativeName = "English (Switzerland)";
                TryRegisterCulture(englishSwitzerland);
            }
    
        }
    
        /// <summary>
        /// Attempts to register the specified culture, swallowing any errors that may occur.
        /// </summary>
        /// <param name="culture">
        /// The culture to register.
        /// </param>
        private static void TryRegisterCulture(CultureAndRegionInfoBuilder culture)
        {
            try
            {
                culture.Register();
            }
            catch
            {
            }
        }
    
        #endregion
    
    }
    

    Couldn't build it as part of the website, as it needs to be run as an administrator to change some system files.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies