Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ) . "\r\n";

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.

share|improve this question
    
I am still not sure I understand your setup: you provide different languages under the same address? –  toscho Feb 16 at 10:46
    
Yes, it is a multi-lingual site (currently bilingual, others to be added). In wp-config.php WPLANG is set for each user (first time via browser language check, subsequently via a cookie). –  terraling Feb 16 at 16:14
    
This is not a good setup. Search engines will never find the second language. I strongly recommend to use a multi-site with one separate site for each language. –  toscho Feb 16 at 16:21
    
Search engines are not so much of a consideration, usability is. It's not a blog, it has a social layer using BuddyPress, will be used by a multi-lingual audience who will interact with each other, they don't want segregating into their own silos, any more than they are on sites like facebook or twitter. If I go down the multi-site route then I have to work out linking the content so that people on the "English" site see and can interact with the content on the "Spanish" site and vice versa. –  terraling Feb 16 at 16:28

1 Answer 1

Add a locale filter

add_filter('locale', 'locale_filter');

and in the filter return the locale of your choice,

function locale_filter($locale) {
    return "whatever";
}

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.

share|improve this answer
    
Thanks for replying @oferwald. I'm not used to using add_filter this way, but I've just gone to read the codex about it, I'm still slightly confused. I assume where you have 'locale_filter' you mean the name of your function 'transposh_locale_filter'? But then I don't understand the difference between add_filter('locale', array(&$this, 'my_function')) and add_filter('locale', 'my_function'). Can you elaborate? Or should I ask a new question? –  terraling Feb 19 at 10:33
    
Hi, Sorry for the late reply, You are quite correct, the name of the function does not match the function, and the call method is wrong, because the array(&this method is used to call functions located inside the same object the filter was added in, Changing the code is the proper thing, and I'll fix my answer –  oferwald Apr 20 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.