, and the * translation files WordPress, the theme and plugins load. */ declare( strict_types = 1 ); namespace AddBlack\Lang\Frontend; defined( 'ABSPATH' ) || exit; use AddBlack\Lang\Hookable; use AddBlack\Lang\Hooks; use AddBlack\Lang\Routing\CurrentLanguage; use AddBlack\Lang\Settings\SettingsRepository; final class Locale implements Hookable { public function __construct( private readonly CurrentLanguage $current, private readonly SettingsRepository $settings ) {} public function register(): void { Hooks::filter( 'locale', array( $this, 'locale' ) ); } public function locale( mixed $locale ): mixed { if ( is_admin() ) { return $locale; } $lang = $this->current->get(); if ( '' === $lang ) { return $locale; } $wp_locale = $this->settings->get()->language( $lang )->locale ?? ''; return '' !== $wp_locale ? $wp_locale : $locale; } }