-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to translate toastr messessage #201
Comments
How do you usually handle this? I haven't looked into i18n w/ angular yet |
|
If you are using ngx-translate, it might be better if you provide the translated text to ngx-toastr using the The example on ngx-translate/core looks like this: translate.get('HELLO', {value: 'world'}).subscribe((res: string) => {
console.log(res);
//=> 'hello world'
}); So maybe something like this? // Set up translations somewhere
translate.setTranslation('en', {
INVALID_CREDENTIALS: 'Invalid Credentials'
});
translate.setTranslation('es', {
INVALID_CREDENTIALS: 'Credenciales No Válidas'
});
// At the place of showing a toast
translate.get('INVALID_CREDENTIALS').subscribe((res: string) => {
toastr.error(res);
}); |
thanks a lot Mr Yarrgh it worked |
I also created a gist with a custom component that would handle the translations for you. This might be better, depending on how often you have to show translated toasts. Observables can get messy if you have to translate the message and the title of a toast. The gist is located at https://gist.github.com/yarrgh/84ee1cb78cdcdb537cc0c7c203b49216 The component is almost exactly like the original Toast component except it uses the Translate pipe on line 31 and line 36 I also provided an example app.module.ts of using that custom component (sets it up globally). I haven't actually tested (or even ran) the code, although I think it should work. |
HI Guys, |
I use angular custom i18n in my application
Is there a way (other then custom component) to support it?
|
for angular i18n translation of ngx-toastr message check my answer here: |
@yarrgh Unfortunate the result display only Key not value.. |
You can always use your own service to translate message before showing toast. Ex. here: https://gist.github.com/krzyhan/079989d41d7dbf9de26ee79ef71ffcdc |
The best example using json file https://stackoverflow.com/questions/46155989/ngx-translate-with-dynamic-text-on-ts-file |
I just installed ngx-toaster and need to work with two language and I can't translate the message any suggestion?
The text was updated successfully, but these errors were encountered: