I have a bilingual site working no problem that tests for cookies before setting WPLANG in wp-config.php, with all the text internationalised etc.
My one problem is that notification emails are being sent in the language of the current user, not the language of the recipient. So if user1 comments in English, and user2, who uses the site in Spanish but replies in broken English, the comment notification email that user1 receives will be in Spanish.
I have a language preference stored for each user, so I intend to customise how the emails are sent so that it checks for the language of the recipient first.
So, to the question.
Here is a sample line plucked from wp_notify_postauthor() in pluggable.php which uses gettext calls to construct the email message:
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "rn";
I’m hoping to continue with this gettext-based method.
But that would mean temporarily switching the locale setting immediately prior to constructing the email message, and then switching it back again immediately afterwards.
[edit] Reading through the core files I think I might better describe this as unloading the text domain prior to sending the emails and reloading afterwards, where required. To optimise I could create a text-domain subset specifically for notification messages to load and unload, rather than the text-domain for the entire site, and, of course, when sending multiple notifications, group the messages to send by language [/edit]
Is that a) meaningful, b) possible, and c) sensible?
Because the alternative is to drop gettext here and have both (and eventually, all) language versions there in the php and build the email string accordingly based on my language test.
Add a locale filter
and in the filter return the locale of your choice,
however, this needs to be done in context, your mail sending trigger will need to know the target user and get the locale from there, not very easy, although doable.
I am unsure if I understand your question entirely, but in any case, I would advise against editing
WPLANG
directly, and avoid messing with cookies that much. WordPress already differentiates between a site-wide language setting and a user-specific language preference:Site-wide language setting (Settings > General)
User-specific language preference (Users > Your profile)
The latter setting is only visible if multiple site languages are installed.
Doesn’t this solve the e-mail translation issues?