Run code in a temporary locale
pom_translate_with_locale( string $locale, callable $callback ) executes a callback with matching POM Translate and WordPress locale overrides.
$html = pom_translate_with_locale(
'fr_FR',
static fn(): string => render_invoice()
);
The helper returns the callback result and restores both previous contexts in a finally path. An invalid or unavailable locale resolves through POM Translate's normal locale normalization.
Use it for emails, exports, documents, queues, and other work that deliberately renders a locale different from the current request.
Avoid nesting manual calls to switch_to_locale() around it or changing the global POM locale inside the callback. If an older integration must call pom_translate_set_current_language(), restore the captured value yourself.
Test callbacks that throw as well as callbacks that return normally; subsequent work must still use its original locale.