You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The email channel (EmailChannel) will send real-time emails using Django’s built-in `send_mail` method. This is a blocking function call, meaning that while a connection with the SMTP server is made and the email is sent off, the process that’s sending the notification has to wait. This is not ideal, but easily solved by using something like [django-mailer](https://github.com/pinax/django-mailer/), which provides a queueing backend for `send_mail`. This means that sending email is no longer a blocking action.
389
389
390
+
## Multilingual Notifications
391
+
392
+
For applications that support multiple languages, you have two main approaches to handle translatable notification content.
393
+
394
+
### Approach 1: store parameters per language in metadata
395
+
396
+
Store translated parameters for each language in the `metadata` field and use Django's translation system in `get_text()`:
397
+
398
+
```python
399
+
from django.utils.translation import gettext as _, get_language
400
+
401
+
@register
402
+
classCommentNotificationType(NotificationType):
403
+
key ="comment"
404
+
name ="Comments"
405
+
description ="When someone comments on your content"
406
+
407
+
defget_text(self, notification):
408
+
current_lang = get_language()
409
+
# Get parameters for current language, fallback to English
| Approach 1 | Moderate | Excellent | Frozen when created |
483
+
| Approach 2 | None | Good (with prefetching) | Always current |
484
+
485
+
- Use **approach 1** if you have performance-critical displays and can accept that text is frozen when the notification is created
486
+
- Use **approach 2** if you need always-current data
487
+
390
488
## Example App
391
489
392
490
An example app is provided, which shows how to create a custom notification type, how to send a notification, it has a nice looking notification center with unread notifications as well as an archive of all read notifications, plus a settings view where you can manage notification preferences.
0 commit comments