akserg / ng2-toasty

Angular2 Toasty component shows growl-style alerts and messages for your app.
MIT License
283 stars 103 forks source link

Translate integration #89

Open rubenCodeforges opened 7 years ago

rubenCodeforges commented 7 years ago

Integrate support for translation keys for ngx-translate The ngx-translate is a module that supports translation files, a good idea would be to add its service to translate incoming string so that when you add a translation key to the toast message it will translate it.

example :

this.toastyService.success("TOAST.UPDATE.SUCCESS");
rubenCodeforges commented 7 years ago

At first sight i guess its doable in here https://github.com/akserg/ng2-toasty/blob/master/src/toasty.service.ts in the add method, if @akserg you are ok with that , please assign the issue to me ill add the changes.

rubenCodeforges commented 7 years ago

Btw ive currently a wrapper service:

export class ToastService {
    constructor(private toastyService: ToastyService,
                private translateServie: TranslateService){
    }

    default(options: ToastOptions | string | number): void {
        if(typeof options == "string") {
            this.translateServie.get(options).subscribe((message)=>{
                this.toastyService.default(message);
            })
        }
    };
//....
}

Btw if the string is a simple message ( not translation ) the translate service will just return it in the subscribe, so you can do :

             this.toastService.default("Im just a string");
             this.toastService.success("TOAST.UPDATE.SUCCESS");