Skip to content
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

Translations doesn't work #88

Open
gasci opened this issue Dec 3, 2023 · 2 comments
Open

Translations doesn't work #88

gasci opened this issue Dec 3, 2023 · 2 comments

Comments

@gasci
Copy link

gasci commented Dec 3, 2023

I am using Django Rest Framework alongside Django 4.2.6.

I am using the from django.utils.translation import activate function just before the send_password and send_email functions but the messages are failing to be translated in my responses. The response always defaults to the default language of the server that is stated in the settings.py file. How can I overcome this problem?

@gasci
Copy link
Author

gasci commented Dec 3, 2023

I had to make the emails Thread=False to make it work. I would add a language section to the method so that users can pass languages:

def send_auth_email(user, type: str = "verification", language: str = "en") -> None:
    """
    The function sends an authentication email to a user, either for verification or password reset, in
    the specified language.

    Args:
      user: The "user" parameter represents the user object or user information that will be used to
    send the authentication email.
      type (str): The "type" parameter is used to specify the type of email to be sent. It can have two
    possible values: "verification" or "reset". Defaults to verification
      language (str): The "language" parameter is a string that specifies the language in which the
    email should be sent.
    """
    translation.activate(language)

    if type == "verification":
        send_email(user, thread=False)
    elif type == "password_reset":
        send_password(user, thread=False)

    translation.deactivate()

@gasci
Copy link
Author

gasci commented Dec 3, 2023

I couldn't find a solution for this problem, though:

EMAIL_MAIL_SUBJECT = _("Confirm your email")
EMAIL_PASSWORD_SUBJECT = _("Set your new password")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant