/** * Customize the cookie banner message based on site language. * * @param string $message Default cookie message. * @return string Translated cookie message. */ function cky_translate_cookie_message( $message ) { // Get the current language of the site. $current_lang = substr( get_locale(), 0, 2 ); // Example: 'en', 'pt', 'es'. // Define translations for cookie banner message. $translations = array( 'en' => 'This website uses cookies to ensure you get the best experience.', 'pt' => 'Este site utiliza cookies para garantir a melhor experiência.', 'es' => 'Este sitio utiliza cookies para garantizar la mejor experiencia.', ); // Return the message based on the current language or default to English. return isset( $translations[ $current_lang ] ) ? $translations[ $current_lang ] : $translations['en']; } /** * Customize the text of the cookie banner buttons based on site language. * * @param array $button_texts Default button texts. * @return array Translated button texts. */ function cky_translate_cookie_buttons( $button_texts ) { // Get the current language of the site. $current_lang = substr( get_locale(), 0, 2 ); // Define translations for buttons. $translations = array( 'en' => array( 'accept' => 'Accept All', 'settings' => 'Cookie Settings', ), 'pt' => array( 'accept' => 'Aceitar todos', 'settings' => 'Configurações de cookies', ), 'es' => array( 'accept' => 'Aceptar todo', 'settings' => 'Configuración de cookies', ), ); // Return the button texts based on the current language or default to English. return isset( $translations[ $current_lang ] ) ? $translations[ $current_lang ] : $translations['en']; } /** * Apply translations to cookie banner texts. */ add_filter( 'cli_cookie_message', 'cky_translate_cookie_message' ); add_filter( 'cli_cookie_buttons', 'cky_translate_cookie_buttons' );