Currently in the localization systems we are missing the support for managing more than one language on a single page request. This is needed for:
- Modules that produce email need to localize that emails for each user's language, not for the page request language. These emails are usually triggered on cron.
- When an administrator creates/approves an user account and the user gets a notification it is currently in the administrator's language. It should be in the user's language.
- When a user registers and the administrator is notified, the email is currently in the language the user has used for registering, that the administrator may understand or not...
This patch has several parts.
- It adds the ability to translate into several languages in the same page request to locale module and a 'locale_switch_language' function that will temporarily change the current language, while it stores the original one to reset it later
- Adds a 'user_context' function to user module, which will be the one to switch language and maybe other settings for a specific user. This is meant to be a simple api function in user module. To switch language back and forth for an user account, the code would look like
- Adds a new operation for user hook, $type = 'context' so other modules can act when switching the context of the user. Currently it is only used by locale module to switch language. Other uses may be, i.e. some module changing the 'from' address for emails depending on the user being emailed, or customizing the emails for groups of users...
- Uses all the above functionality for emails sent to users from the user module. Also, when a user registers, it uses the administrator's language when emailing him.
- Adds the language selection for user accounts for some cases when it didn't make sense before, because now, besides changing the interface language, it is also used for notifications.
user_context($account); // Will switch language to user account
// operations here
user_context() // Will reset the language to the original one in the request
Hope I've been able to explain right this language mess.. :-)
There are some tricky issues in this patch, like switching global variables, and this 'context' hook that needs to be documented also. But this is just a starting point. There's been some talk in the past about global variables, user variables, etc... This new hook operation at least would allow modules to switch global settings -in the $conf array- on a per user basis, which is something to start with.
Also, I've implemented the whole thing to show the complete picture, but I could post some smaller patch just for the locale module.
|locale_multilingual_requests.patch||7.83 KB||Ignored: Check issue status.||None||None|