ASP. NET CORE 3.1 - How to add Haitian Creole on my culture list?

Ronaldo Ademar 21 Reputation points
2022-10-07T20:17:38.057+00:00
  services.Configure<RequestLocalizationOptions>(options =>  
            {  
                 
                var cultures = new List<CultureInfo>  
                {  
                    new CultureInfo("pt-BR"),  
                    new CultureInfo("en-US"),  
                    new CultureInfo("es"),  
                    new CultureInfo("ht"),  // <--   Haitian Creole                
                    new CultureInfo("tr"),  
                    new CultureInfo("ar")  
                };  
                options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("pt-BR");  
                options.SupportedCultures = cultures;  
                options.SupportedUICultures = cultures;  
            });  

Is there any way to add Haitian Creole to my list of cultures? Since it is not in the list of supported languages? I've looked in several places, read and reread the localization docs. And I didn't find anything. Can someone help me? Because I know that in NET Framework, it is possible through CultureAndRegionInfoBuilder. But in .Net Core 3.1 I haven't seen anything similar.

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-10-10T05:34:30.51+00:00

    Hi @Ronaldo Ademar ,

    Is there any way to add Haitian Creole to my list of cultures? Since it is not in the list of supported languages?

    Do you mean display the Haitian Creole in the cultures select DropDownList?

    From the official document and its sample code, we can see that it, in the Views/Shared/_SelectLanguagePartial.cshtml file, we could get the supported cultures via the IOptions<RequestLocalizationOptions>, then use a select element to display the culture.

    248891-image.png

    Then, to change the Unknown Language (ht) to Haitian Creole, you can modify the query statement as below:

    248836-image.png

    Besides, if you want to add custom language and culture, you could use a custom provider, and add it via the AddInitialRequestCultureProvider method, refer to the following code:

    private const string enUSCulture = "en-US";  
      
    services.Configure<RequestLocalizationOptions>(options =>  
    {  
        var supportedCultures = new[]  
        {  
            new CultureInfo(enUSCulture),  
            new CultureInfo("fr")  
        };  
      
        options.DefaultRequestCulture = new RequestCulture(culture: enUSCulture, uiCulture: enUSCulture);  
        options.SupportedCultures = supportedCultures;  
        options.SupportedUICultures = supportedCultures;  
      
        options.AddInitialRequestCultureProvider(new CustomRequestCultureProvider(async context =>  
        {  
            // My custom request culture logic  
            return await Task.FromResult(new ProviderCultureResult("en"));  
        }));  
    });  
    

    More detail information, see Use a custom provider and Writing a Custom Request Culture Provider.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ronaldo Ademar 21 Reputation points
    2022-10-10T15:33:24.063+00:00

    Hi, I appreciate your very thorough answer. But maybe I didn't make myself so clear. The implementation of language choice I know how to do. My problem is implementing a language that is not supported. And it is a requirement of my client. That list here https://learn.microsoft.com/en-us/bingmaps/rest-services/common-parameters-and-types/supported-culture-codes. Haitian Creole is not an existing culture on the list. And I've searched, searched, tested different ways to add it as a culture option and found nothing.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.