1

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)
  • WPLANG should work, so long as you're defining it before you load wp-load.php - the current language is set in wp-settings.php using load_default_textdomain, which internally uses get_locale – TheDeadMedic Nov 29 '16 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.