/** * Language Switching Functionality */ function gas_station_rental_language_switcher() { // Simple language switching without plugins if (isset($_GET['lang'])) { $lang = sanitize_text_field($_GET['lang']); if ($lang === 'ar') { switch_to_locale('ar'); setcookie('gas_station_lang', 'ar', time() + (86400 * 30), '/'); // 30 days } else { switch_to_locale('en_US'); setcookie('gas_station_lang', 'en', time() + (86400 * 30), '/'); // 30 days } } elseif (isset($_COOKIE['gas_station_lang'])) { $lang = sanitize_text_field($_COOKIE['gas_station_lang']); if ($lang === 'ar') { switch_to_locale('ar'); } else { switch_to_locale('en_US'); } } } add_action('init', 'gas_station_rental_language_switcher'); /** * Add RTL body class for Arabic */ function gas_station_rental_body_classes($classes) { if (is_rtl() || get_locale() === 'ar') { $classes[] = 'rtl'; $classes[] = 'arabic'; } return $classes; } add_filter('body_class', 'gas_station_rental_body_classes'); /** * Add language attributes to HTML tag */ function gas_station_rental_language_attributes($output) { if (get_locale() === 'ar') { $output = str_replace('lang="ar"', 'lang="ar" dir="rtl"', $output); } return $output; } add_filter('language_attributes', 'gas_station_rental_language_attributes'); /** * Modify form labels and placeholders for Arabic */ function gas_station_rental_localize_form_strings() { if (get_locale() === 'ar') { // Add any specific Arabic form modifications here add_filter('gas_station_rental_form_placeholder_address', function($placeholder) { return __('أدخل عنوان العقار الكامل', 'gas-station-rental'); }); add_filter('gas_station_rental_form_placeholder_gps', function($placeholder) { return __('https://maps.google.com/...', 'gas-station-rental'); }); add_filter('gas_station_rental_form_placeholder_layout', function($placeholder) { return __('صف التخطيط وعدد المضخات وحجم متجر الخدمات وما إلى ذلك.', 'gas-station-rental'); }); } } add_action('init', 'gas_station_rental_localize_form_strings'); /** * Add Arabic number formatting */ function gas_station_rental_format_number($number, $locale = null) { if (!$locale) { $locale = get_locale(); } if ($locale === 'ar') { // Format numbers for Arabic locale return number_format_i18n($number); } return number_format($number); } /** * Currency formatting for different locales */ function gas_station_rental_format_currency($amount, $currency = 'USD') { $locale = get_locale(); if ($locale === 'ar') { // Arabic formatting - assuming SAR (Saudi Riyal) return number_format($amount) . ' ' . __('ريال', 'gas-station-rental'); } // Default USD formatting return '$' . number_format($amount); } /** * Add language switcher to admin bar */ function gas_station_rental_admin_bar_language_switcher($wp_admin_bar) { if (!is_admin_bar_showing()) { return; } $current_locale = get_locale(); $current_lang = ($current_locale === 'ar') ? 'العربية' : 'English'; $wp_admin_bar->add_node(array( 'id' => 'language-switcher', 'title' => $current_lang, 'href' => '#', )); $wp_admin_bar->add_node(array( 'id' => 'switch-to-english', 'parent' => 'language-switcher', 'title' => 'English', 'href' => add_query_arg('lang', 'en', home_url($_SERVER['REQUEST_URI'])), )); $wp_admin_bar->add_node(array( 'id' => 'switch-to-arabic', 'parent' => 'language-switcher', 'title' => 'العربية', 'href' => add_query_arg('lang', 'ar', home_url($_SERVER['REQUEST_URI'])), )); } add_action('admin_bar_menu', 'gas_station_rental_admin_bar_language_switcher', 100); /** * Enqueue additional styles for Arabic typography */ function gas_station_rental_arabic_typography() { if (get_locale() === 'ar') { wp_add_inline_style('gas-station-rental-style', ' body, input, textarea, select { font-family: "Cairo", "Noto Sans Arabic", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; } .hero-title, .section-title, .feature-title, .step-title { font-family: "Cairo", "Noto Sans Arabic", sans-serif; font-weight: 700; } .form-input::placeholder, .form-textarea::placeholder { font-family: "Cairo", "Noto Sans Arabic", sans-serif; } '); } } add_action('wp_enqueue_scripts', 'gas_station_rental_arabic_typography', 20); /** * Add meta tags for better Arabic SEO */ function gas_station_rental_arabic_meta_tags() { if (get_locale() === 'ar') { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } } add_action('wp_head', 'gas_station_rental_arabic_meta_tags');