Preserve locale in background processes

Cron, queue, CLI, and asynchronous workers have no reliable visitor URL from which to infer a language. Store the required locale with the job payload and validate it when the job runs.

Wrap locale-sensitive work with pom_translate_with_locale():

pom_translate_with_locale(
    $job['locale'],
    static function () use ( $job ): void {
        generate_document( $job['post_id'] );
    }
);

This temporarily changes POM Translate context and the WordPress locale, then restores both. Do not leave a locale set globally across multiple jobs in the same process.

Store canonical identifiers such as post IDs and locale codes, not already translated titles or URLs that can become stale. Resolve translated values inside the temporary context at execution time.

Background callbacks must remain idempotent, capability-independent where appropriate, and safe to retry. They should not derive a customer language from cookies, browser headers, or the administrator who scheduled the event.

Test two queued items with different locales in the same worker run. Confirm that the second item does not inherit strings, date formats, URLs, or caches from the first.