Issue with Displaying NativeName for CultureInfo in C# and .NetCore (prs-AF)

43 Views Asked by At

I'm facing an issue with CultureInfo in C#, specifically regarding the display of the NativeName for the "prs-AF" culture (Dari in Afghanistan).

Here's my code snippet:

program.cs:

 services.AddMvc()
                .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
                .AddDataAnnotationsLocalization();

            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.Configure<RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo("en"),
                    new CultureInfo("prs-AF"),
                    new CultureInfo("ar"),
                    new CultureInfo("ps"),
                };
                options.DefaultRequestCulture = new RequestCulture(culture: "prs-AF", uiCulture: "prs-AF");
                options.SetDefaultCulture("prs-AF");
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
                options.RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider());
            });

Razor view:

@inject IOptions<RequestLocalizationOptions> LocOptions
@{
    var cultures = LocOptions.Value.SupportedUICultures;
    var culture = System.Globalization.CultureInfo.CurrentCulture.Name;
}

result:

result for (prs-AF) and result for (ps)

When I retrieve the NativeName for "prs-AF," it returns "prs-AF," which is not the expected behavior. However, for the "ps" culture (Pashto), the NativeName is correctly displayed as "پشتو."

I have attached two images to illustrate the issue. One shows the NativeName for "ps," correctly displayed as "پشتو," and the other for "prs-AF," incorrectly displayed as "prs-AF."

Is there a way to configure CultureInfo to display the NativeName for "prs-AF" as "دری" (Dari), similar to how it is done for the "ps" culture?

If there is no solution through code modification, is it possible for C# language developers to be contacted and urged to address this issue?

Do you suggest any specific solution for this problem?

Any guidance or assistance on resolving this issue would be greatly appreciated. Thank you!

I attempted to customize the display of NativeName for "prs-AF" by modifying the code related to CultureInfo.

Expected: I expected the NativeName for "prs-AF" to be customized and displayed as "دری" (Dari).

Actual: Despite making code modifications, the display for "prs-AF" NativeName remained unchanged.

0

There are 0 best solutions below