Custom culture in Azure Websites

Vote:
 

Hi all,

I'm working on a website that will be available in m any countries and languages. One thing I have create is a custom culture like "en-NL". It is the Dutch local website in the English language. I've tried to create an initialization module to register the missing cultures. Goot thing here is that it works on Azure VM because you have control over the user running the process. Problem I have is that it's not possible in an Azure Website. Does someone has another option to register custom cultures in Azure Websites?

{
    [InitializableModule]
    public class CultureAndRegionInfoInitialization : IInitializableModule
    {
        private static readonly ILogger _logger = LogManager.GetLogger(typeof(InitializationModule));

        public void Initialize(InitializationEngine context)
        {
            CreateCulture("en-NL", "English (Netherlands)", "English (Nederland)");
        }

        public void Uninitialize(InitializationEngine context)
        {
            throw new NotImplementedException();
        }

        public static void CreateCulture(string cultureName, string cultureEnglishName, string cultureNativeName)
        {

            try
            {
                //* Check if the culture already exists
                if (
                    CultureInfo.GetCultures(CultureTypes.AllCultures)
                        .FirstOrDefault(x => x.Name.ToLowerInvariant() == cultureName.ToLowerInvariant()) != null)
                {
                    _logger.Information("The culture with name {0} already exists.", cultureName);
                    return;
                }

                //* Get the base culture and region information
                CultureInfo cultureInfo = new CultureInfo("en-GB");
                RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);

                //* Create the a locale for en-HK
                CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);

                //* Load the base culture and region information
                cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
                cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);

                //* Set the culture name
                cultureAndRegionInfoBuilder.CultureEnglishName = cultureEnglishName;
                cultureAndRegionInfoBuilder.CultureNativeName = cultureNativeName;

                //* Register with your operating system
                cultureAndRegionInfoBuilder.Register();
            }
            catch (Exception exception)
            {
                _logger.Error(exception.Message);
            }
        }
    }
}
#171996
Nov 23, 2016 9:41
Vote:
 

I've found a workaround for earlier .NET versions (2.0) that calls CultureDefinition.Compile using reflection. Unfortunattely this is not going to work in .NET Framework 4.

https://msdn.microsoft.com/en-au/library/azure/ms404375(v=vs.80).aspx

#172000
Nov 23, 2016 9:57
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.