Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

LocalizedResourcesHelper problem in Swedish #2793


User avatar
0
DennisAhlin created

When Swedish language is selected (sv-SE or sv), LocalizedResourcesHelper tries to find jquery.jtable.sv-SE.js or jquery.jtable.sv.js here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/3c65f620aab8042b9b85109054c606836d15b8ed/angular/src/shared/helpers/LocalizedResourcesHelper.ts#L40">https://github.com/aspnetzero/aspnet-ze ... per.ts#L40</a> Too bad the language file is called jquery.jtable.se.js, so we get a 404. The same goes for jquery timeago.

Bootstrap Select also checks for supported cultures, so it reverts to english, since it cannot find sv-SE or sv in the supportedCultures array.

This is probably not only a problem with Swedish. How to solve this best?


4 Answer(s)
  • User Avatar
    0
    DennisAhlin created

    I solved it like this:

    private static loadLocalizedScripts(): JQueryPromise<any> {
            if (!abp.session.userId) {
                return $.Deferred().resolve();
            }
    
            var currentCulture = abp.localization.currentLanguage.name;
    
            var jTable = "/assets/localization/jtable/jquery.jtable.{0}.js";
            var bootstrapSelect = "/assets/localization/bootstrap-select/defaults-{0}.js";
            var jqueryTimeago = "/assets/localization/jquery-timeago/jquery.timeago.{0}.js";
    
            return $.when(
                ((currentCulture !== 'en') ? jQuery.getScript(abp.utils.formatString(jTable, LocalizedResourcesHelper.mapCultureForJtable(currentCulture))) : $.Deferred().resolve()),
                jQuery.getScript(abp.utils.formatString(bootstrapSelect, LocalizedResourcesHelper.mapCultureForBootstrapSelect(currentCulture))),
                jQuery.getScript(abp.utils.formatString(jqueryTimeago, LocalizedResourcesHelper.mapCultureForTimeago(currentCulture)))
            );
        }
    
        private static mapCultureForJtable(currentCulture: string): string {
            const cultureMap = {
                'sv-SE': 'se',
                'sv': 'se'
                //Add more here
            };
    
            if (cultureMap[currentCulture])
                return cultureMap[currentCulture];
    
            return currentCulture;
        }
    
        private static mapCultureForBootstrapSelect(currentCulture: string): string {
            const cultureMap = {
                'en': 'en_US'
                //Add more here
            };
    
            if (cultureMap[currentCulture])
                return cultureMap[currentCulture];
    
            return currentCulture.replace('-', '_');
        }
    
        private static mapCultureForTimeago(currentCulture: string): string {
            const cultureMap = {
                'sv-SE': 'sv'
                //Add more here
            };
    
            if (cultureMap[currentCulture])
                return cultureMap[currentCulture];
    
            return currentCulture;
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for sharing the solution as well. You can create an issue in aspnet zero repository and we will think a better way and if we can find one, we will apply it.

    Thanks.

  • User Avatar
    0
    DennisAhlin created

    GitHub issue here: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/109">https://github.com/aspnetzero/aspnet-ze ... issues/109</a>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks :)