Base solution for your next web application
Open Closed

Setting default language to English (United Kingdom) en-GB #5047


User avatar
0
Mitch created

When creating a new language (English (United Kingdom) en-GB) using the ASP Net Zero interface, I've noticed that it still shows the default language as English (US) despite setting the default to en-GB several times.

I can fix this by removing the US version of English from the options, but it will be problematic for people who might want both language options.


11 Answer(s)
  • User Avatar
    0
    alirizaadiyahsi created

    Hi @Mitch, I created an issue for this: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/1097">https://github.com/aspnetzero/aspnet-ze ... ssues/1097</a>

  • User Avatar
    0
    ismcagdas created
    Support Team

    @Mitch can you restart your Host project and see if you can select the new Language ? If so, this is becasue ASP.NET Core reads languages only at startup. So, your app must be restarted after adding a new language.

  • User Avatar
    0
    Mitch created

    I noticed this issue a few weeks ago but I've only recently got around to reporting it.

    I've restarted the app many times and for some reason it always chooses US English and not GB English.

    To recreate, get a fresh version of ASP.Net Zero jQuery.

    Go to Administration, Languages and Create a new Language which is en-GB, choose the British Flag and then save as Default.

    Restart the App and you will notice that US English is still shown as Default.

    I've attached a screenshot to show US English at the top of the screen and English (United Kingdom) shown as the Default.

    I hope this helps.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Mitch,

    If you are talking about the column on the grid named "Default". Then it's explanation like this;

    • Can not edit or delete default languages. You can only edit or delete the languages you added. But you can change texts of all languages.

    When you click "Actions > Set as default language" for a language on the grid, it doesn't change the value of Default column. I can see that the name of that column is not clear.

    So, as I can see in the screenshot you have shared, en-GB is displayed in bold font, so it is the default language.

  • User Avatar
    0
    aaron created
    Support Team

    @ismcagdas It can't be set in the top bar, even though it is already set in the database.

    Explanation

    Cultures have to be pre-defined in options.SupportedCultures and options.SupportedUICultures. The RequestLocalizationMiddleware will only set the current request culture to an entry in this list.

    This means that although ASP.NET Zero supports tenant-specific languages, ASP.NET Core doesn't.

    Workarounds

    Workaround 1: Manually add to GetInitialLanguages in DefaultLanguagesCreator.cs.

    • Trade-off: This adds the language for all tenants.

    Workaround 2: Manually add to SupportedCultures and SupportedUICultures in Startup.cs:

    • Trade-off: Although this doesn't add the language for all tenants, ASP.NET Core may return it in AcceptLanguageHeaderRequestCultureProvider.
    app.UseAbpRequestLocalization(options =>
    {
        options.SupportedCultures = options.SupportedCultures.Append(new CultureInfo("en-GB")).ToArray();
        options.SupportedUICultures = options.SupportedUICultures.Append(new CultureInfo("en-GB")).ToArray();
    }
    

    Workaround 3: Automatically add to SupportedCultures and SupportedUICultures in Startup.cs:

    • Trade-off: Same as Workaround 2.
    app.UseAbpRequestLocalization(options =>
    {
        var iocResolver = app.ApplicationServices.GetRequiredService<IIocResolver>();
        iocResolver.UsingScope(scope =>
        {
            var languageRepository = scope.Resolve<IRepository<ApplicationLanguage>>();
            var unitOfWorkManager = scope.Resolve<IUnitOfWorkManager>();
                            
            using (var uow = unitOfWorkManager.Begin())
            {
                using (unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
                {
                    var supportedCultures = languageRepository.GetAll()
                        .Select(l => CultureInfo.GetCultureInfo(l.Name))
                        .ToArray();
    
                    options.SupportedCultures = supportedCultures;
                    options.SupportedUICultures = supportedCultures;
                }
            }
        });
    });
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    @aaron you are right about ASP.NET Core. But, tenant specific languages must be loaded in <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.AspNetCore/AspNetCore/AbpApplicationBuilderExtensions.cs#L87">https://github.com/aspnetboilerplate/as ... ons.cs#L87</a> when the app is restarted.

    What do you think ?

  • User Avatar
    0
    aaron created
    Support Team
  • User Avatar
    0
    Mitch created

    It's not just making it the default that an issue, I cannot select from the top right language dropdown menu.

    I've created a xxxxxxx-en-GB.xml file in Localization and made sure <localizationDictionary culture="en-GB"> but still if I select English (United Kingdom) from the top right language dropdown, it gives me US English again!

    This might just be an issue with en-GB as its base language (en) is the same as the ASP Net Zero default language.

    Please just take a moment to setup en-GB for yourselves and then try to select it, it seems impossible.

    The only workaround seems to be to disable US English.

  • User Avatar
    0
    aaron created
    Support Team

    @Mitch That's what I said. I reproduced your issue, found the cause, explained it and offered 3 workarounds.

  • User Avatar
    0
    Mitch created

    Apologies Aaron, I thought your workaround was only for the Default issue. I only discovered the dropdown issue this afternoon!

    Many thanks for your help.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @aaron thanks a lot for explaining it again :), now I got it. We can try workaround 3 as well.