Open Closed

error in fraction point in arabic language #4102


User avatar
0
hussein created
  • ABP Framework version: v7
  • UI type: MVC
  • DB provider: EF Core / MongoDB
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

when I change the language to Arabic (RTL) , the issue appears in the localization of numbers such as the "," instead of "."

i added the following code:

`

public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var app = context.GetApplicationBuilder();
        var env = context.GetEnvironment();
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        var dateformat = new DateTimeFormatInfo
        {
            ShortDatePattern = "MM/dd/yyyy",
            LongDatePattern = "MM/dd/yyyy hh:mm:ss tt"
        };
        var defaultDateCulture = "ar";
        var ar = new CultureInfo(defaultDateCulture);
        ar.NumberFormat.NumberDecimalSeparator = ".";
        ar.NumberFormat.CurrencyDecimalSeparator = ".";
        ar.DateTimeFormat = dateformat;
        var en = new CultureInfo("en");
        en.NumberFormat.NumberDecimalSeparator = ".";
        en.NumberFormat.CurrencyDecimalSeparator = ".";
        en.DateTimeFormat = dateformat;
        var supportedCultures = new[]
        {
               ar,
               en,
            };
        app.UseAbpRequestLocalization(options =>
        {
            options.DefaultRequestCulture = new RequestCulture("ar");
            options.SupportedCultures = supportedCultures;
            options.SupportedUICultures = supportedCultures;
            options.RequestCultureProviders = new List<IRequestCultureProvider>
                {
                    new QueryStringRequestCultureProvider(),
                    new CookieRequestCultureProvider()
                };
        });
        app.UseAbpRequestLocalization();

the above code didn't work for me but I use to add the following line on each razor page

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

my question here: how i configure my app to take it automatically instead of modifying the code for each page? and I want to make the digits count after the decimal point in a specific format for all language

question #2: can i only use the following code in the other language?do i need to make extra step to work instead of the above code

abp.localization.currentCulture
{
  "displayName": "Arabic",
  "englishName": "Arabic",
  "threeLetterIsoLanguageName": "arb",
  "twoLetterIsoLanguageName": "ar",
  "isRightToLeft": true,
  "cultureName": "ar",
  "name": "ar",
  "nativeName": "Arabic",
  "formatNumber":" <<<<<<<<?
  "dateTimeFormat": {
    "calendarAlgorithmType": "SolarCalendar",
    "dateTimeFormatLong": "dddd, MMMM d, yyyy",
    "shortDatePattern": "M/d/yyyy",
    "fullDateTimePattern": "dddd, MMMM d, yyyy h:mm:ss tt",
    "dateSeparator": "/",
    "shortTimePattern": "h:mm",
    "longTimePattern": "h:mm:ss tt"
  }
}

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    how i configure my app to take it automatically instead of modifying the code for each page? and I want to make the digits count after the decimal point in a specific format for all language

    You can add a custom middleware after UseAbpRequestLocalization and set System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

    or add a Razor Page filters

    https://learn.microsoft.com/en-us/aspnet/core/razor-pages/filter?view=aspnetcore-7.0#implement-razor-page-filters-globally

  • User Avatar
    0
    hussein created

    custom middleware adding System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; after app.UseAbpRequestLocalization(); didn't solve it what do you mean by add custom middleware?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
    app.UseAbpRequestLocalization();
    
    app.Use(async (httpContext, next) =>
    {
        if (System.Threading.Thread.CurrentThread.CurrentCulture.Name == "ar")
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
        }
        await next(httpContext);
    });
    
    if (!env.IsDevelopment())
    {
        app.UseErrorPage();
    }
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11