| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) |
| 3 |
exit; |
| 4 |
|
| 5 |
$translation_settings = AIBUI_Translation_Settings::get_settings(); |
| 6 |
$supported_languages = AIBUI_Translation_Handler::get_supported_languages(); |
| 7 |
|
| 8 |
$header_link = admin_url('site-editor.php?p=%2Fpattern&postType=wp_template_part&categoryId=header'); |
| 9 |
$footer_link = admin_url('site-editor.php?p=%2Fpattern&postType=wp_template_part&categoryId=footer'); |
| 10 |
?> |
| 11 |
<div class="wrap ai-builder-settings"> |
| 12 |
<h1><?php esc_html_e('AI Builder – Translation Settings', 'ai-builder'); ?></h1> |
| 13 |
|
| 14 |
<?php if (isset($_GET['translation_saved'])) : ?> |
| 15 |
<div class="notice notice-success is-dismissible"> |
| 16 |
<p><?php esc_html_e('Translation settings saved.', 'ai-builder'); ?></p> |
| 17 |
</div> |
| 18 |
<?php endif; ?> |
| 19 |
|
| 20 |
<p><?php esc_html_e('Configure the global behavior of language switching and learn how to translate your headers and footers.', 'ai-builder'); ?></p> |
| 21 |
|
| 22 |
<div class="aibui-settings-grid"> |
| 23 |
<div class="aibui-card aibui-card--highlight"> |
| 24 |
<h2><?php esc_html_e('Translate your headers & footers', 'ai-builder'); ?></h2> |
| 25 |
<p><?php esc_html_e('Template parts follow the same language as your pages. Follow these steps to translate them:', 'ai-builder'); ?></p> |
| 26 |
<ol> |
| 27 |
<li><?php esc_html_e('Open the Site Editor and select the template part (header or footer).', 'ai-builder'); ?></li> |
| 28 |
<li><?php esc_html_e('In the editing canvas, click the floating “Translate with AI” button located in the bottom-right corner.', 'ai-builder'); ?></li> |
| 29 |
<li><?php esc_html_e('Publish the translated template part. AI Builder will automatically serve it when visitors switch languages.', 'ai-builder'); ?></li> |
| 30 |
</ol> |
| 31 |
<p> |
| 32 |
<a href="<?php echo esc_url($header_link); ?>" class="button button-primary"><?php esc_html_e('Open header in Site Editor', 'ai-builder'); ?></a> |
| 33 |
<a href="<?php echo esc_url($footer_link); ?>" class="button"><?php esc_html_e('Open footer in Site Editor', 'ai-builder'); ?></a> |
| 34 |
</p> |
| 35 |
<p><?php esc_html_e('Once translations exist, insert the “Language Switcher” block in your templates to let visitors change the language.', 'ai-builder'); ?></p> |
| 36 |
</div> |
| 37 |
|
| 38 |
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="aibui-card aibui-translation-settings-form"> |
| 39 |
<input type="hidden" name="action" value="aibui_save_translation_settings"> |
| 40 |
<?php wp_nonce_field('aibui_save_translation_settings'); ?> |
| 41 |
|
| 42 |
<table class="form-table" role="presentation"> |
| 43 |
<tbody> |
| 44 |
<tr> |
| 45 |
<th scope="row"><?php esc_html_e('Language switcher', 'ai-builder'); ?></th> |
| 46 |
<td> |
| 47 |
<label> |
| 48 |
<input type="checkbox" name="enable_switcher" <?php checked($translation_settings['enable_switcher']); ?> /> |
| 49 |
<?php esc_html_e('Enable the Language Switcher block for visitors', 'ai-builder'); ?> |
| 50 |
</label> |
| 51 |
<p class="description"> |
| 52 |
<?php esc_html_e('When enabled, you can insert the “Language Switcher” block into your site header or anywhere else on your pages and patterns. Visitors can then pick a language and only translated content will be shown.', 'ai-builder'); ?> |
| 53 |
</p> |
| 54 |
</td> |
| 55 |
</tr> |
| 56 |
<tr> |
| 57 |
<th scope="row"><label for="aibui-default-lang"><?php esc_html_e('Default site language', 'ai-builder'); ?></label></th> |
| 58 |
<td> |
| 59 |
<select name="default_lang" id="aibui-default-lang"> |
| 60 |
<?php foreach ($supported_languages as $code => $label) : ?> |
| 61 |
<option value="<?php echo esc_attr($code); ?>" <?php selected($translation_settings['default_lang'], $code); ?>> |
| 62 |
<?php echo esc_html($label); ?> |
| 63 |
</option> |
| 64 |
<?php endforeach; ?> |
| 65 |
</select> |
| 66 |
<p class="description"> |
| 67 |
<?php esc_html_e('Pages and template parts created without translation will belong to this language.', 'ai-builder'); ?> |
| 68 |
</p> |
| 69 |
</td> |
| 70 |
</tr> |
| 71 |
<tr> |
| 72 |
<th scope="row"><?php esc_html_e('Available languages', 'ai-builder'); ?></th> |
| 73 |
<td> |
| 74 |
<fieldset class="aibui-available-langs-grid"> |
| 75 |
<?php foreach ($supported_languages as $code => $label) : ?> |
| 76 |
<label> |
| 77 |
<input type="checkbox" name="available_langs[]" value="<?php echo esc_attr($code); ?>" <?php checked(in_array($code, $translation_settings['available_langs'], true)); ?> /> |
| 78 |
<?php echo esc_html($label); ?> |
| 79 |
</label> |
| 80 |
<?php endforeach; ?> |
| 81 |
</fieldset> |
| 82 |
<p class="description"> |
| 83 |
<?php esc_html_e('Choose the languages exposed to visitors via the selector. The default language is always enforced.', 'ai-builder'); ?> |
| 84 |
</p> |
| 85 |
</td> |
| 86 |
</tr> |
| 87 |
<tr> |
| 88 |
<th scope="row"><?php esc_html_e('Language switcher appearance', 'ai-builder'); ?></th> |
| 89 |
<td> |
| 90 |
<details> |
| 91 |
<summary style="cursor:pointer;font-weight:500;"> |
| 92 |
<?php esc_html_e('Customize the look of the front-end language switcher', 'ai-builder'); ?> |
| 93 |
</summary> |
| 94 |
<div style="margin-top:12px;padding-top:8px;border-top:1px solid #e5e7eb;"> |
| 95 |
<p class="description"> |
| 96 |
<?php esc_html_e('These options control the floating selector shown on the front-end (top-right corner).', 'ai-builder'); ?> |
| 97 |
</p> |
| 98 |
<table class="form-table" role="presentation"> |
| 99 |
<tbody> |
| 100 |
<tr> |
| 101 |
<th scope="row"> |
| 102 |
<label for="aibui-switcher-bg"><?php esc_html_e('Background color', 'ai-builder'); ?></label> |
| 103 |
</th> |
| 104 |
<td> |
| 105 |
<input type="color" id="aibui-switcher-bg" name="switcher_bg" value="<?php echo esc_attr($translation_settings['switcher_bg']); ?>" /> |
| 106 |
</td> |
| 107 |
</tr> |
| 108 |
<tr> |
| 109 |
<th scope="row"> |
| 110 |
<label for="aibui-switcher-text"><?php esc_html_e('Text color', 'ai-builder'); ?></label> |
| 111 |
</th> |
| 112 |
<td> |
| 113 |
<input type="color" id="aibui-switcher-text" name="switcher_text" value="<?php echo esc_attr($translation_settings['switcher_text']); ?>" /> |
| 114 |
</td> |
| 115 |
</tr> |
| 116 |
<tr> |
| 117 |
<th scope="row"> |
| 118 |
<label for="aibui-switcher-min-height"><?php esc_html_e('Minimum height (px)', 'ai-builder'); ?></label> |
| 119 |
</th> |
| 120 |
<td> |
| 121 |
<input type="number" id="aibui-switcher-min-height" name="switcher_min_height" min="20" step="1" value="<?php echo esc_attr((int) $translation_settings['switcher_min_height']); ?>" /> |
| 122 |
</td> |
| 123 |
</tr> |
| 124 |
<tr> |
| 125 |
<th scope="row"> |
| 126 |
<label for="aibui-switcher-min-width"><?php esc_html_e('Minimum width (px)', 'ai-builder'); ?></label> |
| 127 |
</th> |
| 128 |
<td> |
| 129 |
<input type="number" id="aibui-switcher-min-width" name="switcher_min_width" min="80" step="1" value="<?php echo esc_attr((int) $translation_settings['switcher_min_width']); ?>" /> |
| 130 |
</td> |
| 131 |
</tr> |
| 132 |
<tr> |
| 133 |
<th scope="row"> |
| 134 |
<label for="aibui-switcher-alpha"><?php esc_html_e('Background opacity', 'ai-builder'); ?></label> |
| 135 |
</th> |
| 136 |
<td> |
| 137 |
<input type="number" id="aibui-switcher-alpha" name="switcher_alpha" min="0" max="1" step="0.05" value="<?php echo esc_attr($translation_settings['switcher_alpha']); ?>" /> |
| 138 |
<p class="description"> |
| 139 |
<?php esc_html_e('0 = fully transparent, 1 = fully opaque. Default is 0.9.', 'ai-builder'); ?> |
| 140 |
</p> |
| 141 |
</td> |
| 142 |
</tr> |
| 143 |
</tbody> |
| 144 |
</table> |
| 145 |
</div> |
| 146 |
</details> |
| 147 |
</td> |
| 148 |
</tr> |
| 149 |
</tbody> |
| 150 |
</table> |
| 151 |
|
| 152 |
<p class="submit"> |
| 153 |
<button type="submit" class="button button-primary"><?php esc_html_e('Save Translation Settings', 'ai-builder'); ?></button> |
| 154 |
</p> |
| 155 |
</form> |
| 156 |
</div> |
| 157 |
</div> |
| 158 |
|
| 159 |
<style> |
| 160 |
.aibui-settings-grid { |
| 161 |
display: grid; |
| 162 |
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); |
| 163 |
gap: 24px; |
| 164 |
margin-top: 24px; |
| 165 |
} |
| 166 |
.aibui-card { |
| 167 |
background: #fff; |
| 168 |
border: 1px solid #e5e7eb; |
| 169 |
border-radius: 14px; |
| 170 |
padding: 24px; |
| 171 |
box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08); |
| 172 |
} |
| 173 |
.aibui-card--highlight { |
| 174 |
background: linear-gradient(135deg, #f6f8ff, #eef2ff); |
| 175 |
} |
| 176 |
.aibui-card ol { |
| 177 |
margin-left: 20px; |
| 178 |
} |
| 179 |
.aibui-card .button { |
| 180 |
margin-right: 8px; |
| 181 |
margin-top: 8px; |
| 182 |
} |
| 183 |
.aibui-available-langs-grid { |
| 184 |
display: grid; |
| 185 |
grid-template-columns: repeat(2, minmax(0, 1fr)); |
| 186 |
gap: 4px 16px; |
| 187 |
max-width: 480px; |
| 188 |
} |
| 189 |
.aibui-available-langs-grid label { |
| 190 |
display: flex; |
| 191 |
align-items: center; |
| 192 |
gap: 6px; |
| 193 |
margin: 0; |
| 194 |
} |
| 195 |
</style> |
| 196 |
|
| 197 |
|