Read and switch language context safely

pom_translate_get_current_language() returns the active WordPress locale, such as es_ES. It is resolved from explicit request context, locale prefixes, supported REST or AJAX data, and the configured base language.

Use pom_translate_with_locale( $locale, $callback ) when code must run temporarily under another locale. It validates the requested locale, pushes the POM Translate and WordPress locale overrides, executes the callback, and restores the previous state even when the callback throws.

$subject = pom_translate_with_locale(
    'es_ES',
    static function (): string {
        return pom_translate_get_post_title( 42 );
    }
);

For legacy integrations that call pom_translate_set_current_language(), capture the previous value and restore it in a finally block. A leaked global locale can affect later menus, dates, URLs, emails, and cached output in the same request.

Do not infer locale from get_locale() alone when processing a localized frontend request; WordPress administration locale and POM request locale serve different purposes.

Check function_exists() and handle unavailable or disabled locales. On multisite, locale configuration and current context belong to the active site.