0
votes

I am having an issue when I create new cultures for the use of translations. The current issue I have is that windows does not allow the app to access a folder where this cultures seem to be. In our local machine we can just put Visual Studio as admin and then we have no issues with this but since we deploy our app with Azure I would not know how to allow access to the folder that is having issues so we are getting this exception: System.Globalization.CultureNotFoundException: Culture is not supported. Parameter name: name en-US-biz is an invalid culture identifier.

Exception in the next part of code when we update the user Language:

    var currentUserLanguage = 'en-US-biz';
    IocContainer.SetCurrentUserLanguage(currentUserLanguage);

    var ci = domCultureLanguage != null ? domCultureLanguage.CultureInfo : new CultureInfo(currentUserLanguage);

    Thread.CurrentThread.CurrentUICulture = ci;
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);

inthe line: new CultureInfo(currentUserLanguage) is where I get the Exception.

We register the culture in the global.asax file:

private void LoadCultureManager()
{
    BizCultureEn.Register();
    BizCultureEs.Register();
}

And we have built 2 different culture classes + the rsex respective files.

Eg of BizCultureEn Class:

public static class BizCultureEn
{
    //"es-ES-custom" need to match with Translations.es-ES-custom.resx
    public static string CustomCultureName = "en-US-biz";
    public static CultureInfo CultureInfo { get; set; }

    public static void Register()
    {
        // Create a custom culture for ru-US.
        CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(CustomCultureName, CultureAndRegionModifiers.None);
        CultureInfo = CultureInfo.CreateSpecificCulture(CustomCultureName);
        builder.LoadDataFromCultureInfo(CultureInfo);
        builder.CultureEnglishName = "Biz English (United States)";
        builder.CultureNativeName = "Biz English (United States)";

        builder.ThreeLetterISOLanguageName = "ben";
        builder.ThreeLetterWindowsLanguageName = "ben";
        builder.TwoLetterISOLanguageName = "bn";

        builder.RegionEnglishName = "Biz English";
        builder.ThreeLetterISORegionName = "USA";
        builder.ThreeLetterWindowsRegionName = "USA";
        builder.TwoLetterISORegionName = "US";

        // Register the culture.
        try
        {
            builder.Register();
        }
        catch (InvalidOperationException ex)
        {
            var ex1 = ex;
            // Swallow the exception: the culture already is registered.
        }

        // Use the custom culture.
        //CultureInfo = CultureInfo.CreateSpecificCulture(CustomCultureName);
        Thread.CurrentThread.CurrentCulture = CultureInfo;
        Thread.CurrentThread.CurrentUICulture = CultureInfo;
    }
}
1
Talking with microsoft about this they do not have an option to add languages, so the only way to create new languages is to take existing ones and use them eg. you want to define an Executive language for your app. then take Brazil br and use that for executive language.. This means that if you use azure you can not make an app that will support all the existing languages of the world :/alecellis1985

1 Answers

0
votes

You can run [system.Globalization.CultureInfo]::GetCultures('AllCultures') command to retrieve all the cultures by accessing "Debug console > PowerShell" from Kudu.

Besides, As far as I know, when we call the CultureAndRegionInfoBuilder.Register method to register the custom culture, the registration process will create an .nlp file and store the .nlp file in the %windir%\Globalization system directory, which requires administrative privileges. If we do this on Azure web app, which would cause access privileges related issue. You can try to remote debug your web app to check if any exception occurs while registering the custom culture.

If registering the custom culture can not work fine on Azure Web App sandbox, you can try another hosting options (such Virtual Machines).