pypi / warehouse

The Python Package Index
https://pypi.org
Apache License 2.0
3.58k stars 963 forks source link

Emails language to be based on receiver nationality #7583

Open MVrachev opened 4 years ago

MVrachev commented 4 years ago

What's the problem this feature will solve? While I was working to add email notifications for project/release removed we had a discussion that translation of those emails can't be used because the nationality of the initiator of that action could be different from that of the receiver. For example if the initiator of the project removal is from Spain that doesn't mean that the rest of the contributors of that package will speak spanish.

Read more about that discussion here: https://github.com/pypa/warehouse/pull/7530#issuecomment-598897978

Describe the solution you'd like

I propose to use the receiver nationality when deciding what language to use in the emails. That seems logical solution to me as we are doing just that in our daily lives - in our social interactions with other people we choose our language of communication based on the language spoken from the other person.
That way we would be able to translate the emails which are aimed for groups of people.

The question is, do we have information about the nationality of every user of PyPI?

di commented 4 years ago

The question is do we have information about the nationality of ever user of PyPI?

We don't currently have this information. Presumably when a logged-in user selects a locale, we could store it along with their other account details:

https://github.com/pypa/warehouse/blob/519afb3b82a682258b5baa8263cdd7813bf6e961/warehouse/views.py#L234-L258

This would probably also require some changes to how we determine the locale based on the request, to take this new attribute into account.

di commented 4 years ago

This would probably also require some changes to how we determine the locale based on the request, to take this new attribute into account.

By this I actually mean, how we determine for the locale for the localizer when translating emails, since right now it is based on the request, but it will need to use the attribute on the user who the email is being sent to instead. We'd likely need to construct new localizers for each user with this attribute. We do something similar here:

https://github.com/pypa/warehouse/blob/519afb3b82a682258b5baa8263cdd7813bf6e961/warehouse/views.py#L253-L254

almet commented 9 months ago

Thanks @miketheman for pointing me here.

Unless I'm missing something, the preferred language of the users is not defined in the models.

Is there any other way to do this than adding a field to the model? (e.g. is there somewhere this information is already being stored?)

adamchainz commented 5 months ago

A few days ago, I received an email notification in Russian, the language of my collaborator, rather than my preferred language, English:

Xnapper-2024-05-07-10 11 49

I got the gist from the non-translated subject (missing translation?) and Google Translate helped me verify, but it was surprising.