Base solution for your next web application
Open Closed

CurrentCulture isn't respecting web.config globalization #525


User avatar
0
ellfish created

Hi there,

Firstly just wanted to say I'm really enjoying using ASP.NET Zero, it's exactly what I was looking for in a framework. Great job with it!

Within my Zero application I've been trying to set my CurrentCulture to en-AU, primarily for date formatting. I've ensured that both the Windows system region settings and my web.config setting (below) are set to en-AU. I've also verified that other ASP.NET applications on my machine with the same settings are working as expected.

<system.web>
    <globalization culture="en-AU" uiCulture="en-AU" />
</system.web>

I've tried changing my localization .xml file culture as so:

<localizationDictionary culture="en-AU">

But within my Zero app, Thread.CurrentThread.CurrentCulture (and CurrentUICulture) is reporting "en" instead of "en-AU". This is problematic because "en" has the wrong date format for me.

Is this a known problem? Is there any way to force Zero to respect the Web.config globalization setting?

PS I've also found this line which I can hard-code with "en-AU" to localize moment.js client side, but I need server side to be consistent. <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/blob/7f4f765b74c3dd06931b4f8c81e81567071512f1/src/MyCompanyName.AbpZeroTemplate.Web/App/common/views/layout/layout.cshtml#L86">https://github.com/aspnetzero/aspnet-ze ... cshtml#L86</a>

Thanks, Elliot


5 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you very much :) I'm glad to see it works for you.

    Does your application only supports single language or you want to convert 'en' to 'en-AU'? Did you changed it here: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/blob/v1.4.1/src/MyCompanyName.AbpZeroTemplate.Web/App_Start/AbpZeroTemplateWebModule.cs#L32">https://github.com/aspnetzero/aspnet-ze ... ule.cs#L32</a>

    ABP framework uses cookies to store user language. Maybe your cookie is set to 'en' before you change it to 'en-AU'. You can try to delete cookies. This is the code: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.Web/Web/AbpWebApplication.cs#L69">https://github.com/aspnetboilerplate/as ... ion.cs#L69</a>

    If it does not works at all, as a workaround, you can override Application_BeginRequest method in global.asax and implement your own logic.

    Thanks.

  • User Avatar
    0
    ellfish created

    Thanks for the super speedy response! I basically want to offer my application in en-AU by default and disable language selection because it's too hard to maintain translations.

    I didn't realise the cookie was being used to set the culture, thanks for pointing that out. I had tried searching the Zero repo but forgot about the ABP repo.

    My problem was that I removed the language select drop-down but the cookie was still set to "en", and without the drop-down there was no way to update the cookie to the new en-AU language. I've resolved it by overriding Application_BeginRequest.

    Cheers!

  • User Avatar
    0
    ellfish created

    Following up on this in case anyone else has the same problem:

    The ApplicationLanguage (stored in the AbpLanguages table) should not be changed from "en" to "en-AU" or similar. I had originally changed this is the AbpLanguages table and in my embedded localization xml file (see original post).

    It's a problem because this affects which texts the ABP framework attempts to load from it's own embedded localization files (eg AbpWeb.xml). Because my language was en-AU, no texts were loaded because there were no en-AU xml files, only en files. I noticed this because suddenly the "AreYouSure" text was no longer being localized (via abp.sweet-alert.js).

    I know I could compile my own version of ABP with an embedded en-AU file but that's a bit of a maintenance problem for future updates.

    Note that it is still safe to override Application_BeginRequest to override the CurrentCulture and CurrentUICulture to en-AU, and this still solves the problem I had.

    @hikalkan you might want to think about this, because if someone wants to add another language to Zero it seems the dependencies on abp.localization.abpWeb will prevent localization of those texts.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Actually, you have some options;

    You can always extend AbpWeb localization source with adding AbpWeb-en-AU.xml file and configure it like <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Localization#DocExtending">http://www.aspnetboilerplate.com/Pages/ ... cExtending</a>

    Also, if you are using database based localization, then you can localize AbpWeb for en-AU on database.

    Thanks.

  • User Avatar
    0
    ellfish created

    Ah, ok, that makes sense. Thanks again for getting back to me!