Search code examples
localizationaspnetboilerplatesweetalert2

abp.sweet-alert.js - No localization on buttons with v3.5.0


I have a project with ABP 3.5.0 ASP.NET Core and Angular, including Sweetalert 2.0.8.

When a delete button is pressed (ex. roles or tenants), confirm dialog doesn't localize the buttons Cancel and Yes. I have tried to get a fresh template today, same behavior.

I have tried to change abp.sweet-alert.js as expected here, but no luck: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2708

Here you can see the fresh template for today. I have tried to get an Italian Translation of the confirm Buttons. As you can see on the menu, 'About' was translated.

SEE HERE PICTURE from fresh template


Solution

  • Good news, I fixed the issue!

    Open root.module.ts and add the below line into the AppPreBootstrap.run() callback method.

    abp.event.trigger('abp.dynamicScriptsInitialized');

    Final look of the root.module.ts is below

    import { BrowserModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { NgModule, Injector, APP_INITIALIZER, LOCALE_ID } from '@angular/core';
    
    import { AbpModule, ABP_HTTP_PROVIDER } from '@abp/abp.module';
    
    import { SharedModule } from '@shared/shared.module';
    import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module';
    import { RootRoutingModule } from './root-routing.module';
    
    import { AppConsts } from '@shared/AppConsts';
    import { AppSessionService } from '@shared/session/app-session.service';
    import { API_BASE_URL } from '@shared/service-proxies/service-proxies';
    
    import { RootComponent } from './root.component';
    import { AppPreBootstrap } from './AppPreBootstrap';
    import { ModalModule } from 'ngx-bootstrap';
    
    
    export function appInitializerFactory(injector: Injector) {
        return () => {
    
            abp.ui.setBusy();
            return new Promise<boolean>((resolve, reject) => {
                AppPreBootstrap.run(() => {
                    abp.event.trigger('abp.dynamicScriptsInitialized');
                    var appSessionService: AppSessionService = injector.get(AppSessionService);
                    appSessionService.init().then(
                        (result) => {
                            abp.ui.clearBusy();
                            resolve(result);
                        },
                        (err) => {
                            abp.ui.clearBusy();
                            reject(err);
                        }
                    );
                });
            });
        }
    }
    
    export function getRemoteServiceBaseUrl(): string {
        return AppConsts.remoteServiceBaseUrl;
    }
    
    export function getCurrentLanguage(): string {
        return abp.localization.currentLanguage.name;
    }
    
    @NgModule({
        imports: [
            BrowserModule,
            BrowserAnimationsModule,
            SharedModule.forRoot(),
            ModalModule.forRoot(),
            AbpModule,
            ServiceProxyModule,
            RootRoutingModule
        ],
        declarations: [
            RootComponent
        ],
        providers: [
            ABP_HTTP_PROVIDER,
            { provide: API_BASE_URL, useFactory: getRemoteServiceBaseUrl },
            {
                provide: APP_INITIALIZER,
                useFactory: appInitializerFactory,
                deps: [Injector],
                multi: true
            },
            {
                provide: LOCALE_ID,
                useFactory: getCurrentLanguage
            }
        ],
        bootstrap: [RootComponent]
    })
    export class RootModule {
    
    }
    
    • Proof:

    Abp Angular SweetAlert Localization Fix

    • Issue for this:

    https://github.com/aspnetboilerplate/module-zero-core-template/issues/200

    • Fix for this:

    https://github.com/aspnetboilerplate/module-zero-core-template/commit/8752cd1b4f33afc1c8330f9990f3a6395b14bfeb