How can I change the language of automated Mails?
I've got a problem with translations, that sounds pretty simple, but I can't find a way around this.
The Situation
I got a software running on WordPress, and I need to send Emails to my users after certain actions. The contents of these Mails has been localized using __()
and all the other built in translation functions, as well as translated in the corresponging .mo
/.po
files.
My users can choose the language for the frontend of the software, and this works just fine.
However, when I finish an automated task, the Emails always get sent in the main language, as the automated tasks are called without a login.
The automated tasks are triggerd by a cronjob (not wp-cron
) that executes a function to handle the stack of tasks.
This function loads WordPress via wp-load.php
, and searches for the next task to be executed. The information on this task contains the language the user has set for himself - and this is the earliest point where I know the language.
The Question
How can I force WordPress, after it is loaded, to use certain languages? When does the language has to be defined/the filter added to locale
, so the changes are applied?
Solutions I already tried
- adding a filter on locale
- defining WPLANG with the constant
- setting the auth cookie for the user (I know, that's bad - just tried it)
Topic localization constants translation filters Wordpress
Category Web