! empty( $eshb_settings['cart-blocking-switcher'] ) ? '1' : '0', 'msg' => $eshb_notice_msg, ] ); wp_localize_script('eshb-public-script', 'eshb_rest', [ 'root' => esc_url(rest_url()), 'nonce' => wp_create_nonce('wp_rest') ]); // Convert the WordPress "date_format" (Settings > General) into a moment.js format // so the calendar can display dates exactly as WordPress does, per the site locale. // The conversion has to walk the format token by token rather than character by // character: locales escape literal words with a backslash — Spanish ships // "j \d\e F \d\e Y" — and a plain strtr() rewrites the "de" inside those escapes // into date tokens, printing "4 DDe agosto DDe 2026". $eshb_moment_format = ESHB_Helper::eshb_date_format_to_moment( get_option( 'date_format', 'F j, Y' ) ); // Translated month + short weekday names (from WordPress translations, so they are // guaranteed localized even when moment.js has no bundled locale on the page). // Each sample instant is built at local noon in the site timezone: wp_date() renders // in the site timezone, so a UTC-midnight sample would roll back to the previous // day/month on any timezone behind UTC and shift the whole array by one. $eshb_tz = wp_timezone(); $eshb_months = array(); for ( $m = 1; $m <= 12; $m++ ) { $eshb_month_sample = new DateTime( sprintf( '2025-%02d-15 12:00:00', $m ), $eshb_tz ); $eshb_months[] = wp_date( 'F', $eshb_month_sample->getTimestamp() ); } $eshb_weekdays_short = array(); // Sunday-first to match moment.js weekdaysShort() $eshb_weekday_sample = new DateTime( '2025-01-05 12:00:00', $eshb_tz ); // a Sunday for ( $d = 0; $d < 7; $d++ ) { $eshb_weekdays_short[] = wp_date( 'D', $eshb_weekday_sample->getTimestamp() ); $eshb_weekday_sample->modify( '+1 day' ); } // moment.monthsShort() drives the calendar header; without it the header falls back // to moment's built-in English names regardless of the site locale. $eshb_months_short = array(); for ( $m = 1; $m <= 12; $m++ ) { $eshb_month_sample = new DateTime( sprintf( '2025-%02d-15 12:00:00', $m ), $eshb_tz ); $eshb_months_short[] = wp_date( 'M', $eshb_month_sample->getTimestamp() ); } // Prepare translations dynamically based on current locale $translations = [ 'displayFormat' => $eshb_moment_format, 'locale' => str_replace( '_', '-', strtolower( $locale ) ), 'months' => $eshb_months, 'monthsShort' => $eshb_months_short, 'weekdaysShort' => $eshb_weekdays_short, 'applyLabel' => !empty($apply_text_default) ? eshb_get_translated_string($apply_text_default) : __('Apply', 'easy-hotel'), 'cancelLabel' => !empty($cancel_text_default) ? eshb_get_translated_string($cancel_text_default) : __('Cancel', 'easy-hotel'), 'BookedTooltip' => __('Already Booked!', 'easy-hotel'), 'holidayTooltip' => __('This is Holiday!', 'easy-hotel'), 'fromLabel' => __('From', 'easy-hotel'), 'toLabel' => __('To', 'easy-hotel'), 'customRangeLabel' => __('Custom Range', 'easy-hotel'), 'weekLabel' => __('W', 'easy-hotel'), 'firstDay' => get_option('start_of_week'), // Get WordPress's start of the week setting 'currentLocale' => $locale, // Pass current locale for debugging or further use ]; // Pass translations to JavaScript wp_localize_script('eshb-date-range-picker-js', 'eshb_daterangepicker_i18n', $translations); }