| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form\View; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Admin\Form\Helpers; |
| 6 | +use BitCode\BitForm\Core\Util\Translation\TranslationManager; | |
| 6 | 7 | use BitCode\BitForm\Frontend\Form\FrontendFormManager; |
| 7 | 8 | use BitCode\BitForm\Frontend\Form\View\Conversational\ConversationalHelpers; |
| 8 | 9 | use BitCode\BitForm\Frontend\Form\View\Conversational\DefaultConversationalTheme; |
| 9 | 10 | |
| @@ -65,8 +66,40 @@ | ||
| 65 | 66 | } |
| 66 | 67 | return $honeypotInput; |
| 67 | 68 | } |
| 68 | 69 | |
| 70 | + /** | |
| 71 | + * Opt-out markers for HTML-layer translators (Google/GTranslate, TranslatePress) | |
| 72 | + * when a form disables translation. Empty otherwise, so markup is untouched. | |
| 73 | + * | |
| 74 | + * @return array{attrs:string, cls:string} | |
| 75 | + */ | |
| 76 | + private function noTranslateMarkup() | |
| 77 | + { | |
| 78 | + // Pass the row we already hold; otherwise the lookup re-queries form_content per render. | |
| 79 | + $rawContent = $this->_form->isExist() ? $this->_form->getFieldsContent() : null; | |
| 80 | + $enabled = TranslationManager::isFormTranslationEnabled($this->getFormID(), $rawContent); | |
| 81 | + if ($enabled) { | |
| 82 | + return ['attrs' => '', 'cls' => '']; | |
| 83 | + } | |
| 84 | + return ['attrs' => ' translate="no" data-no-translation', 'cls' => ' notranslate']; | |
| 85 | + } | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * Carries the page language into the AJAX submission so validation and | |
| 89 | + * confirmation strings match it. Empty when no provider resolves one. | |
| 90 | + * | |
| 91 | + * @return string | |
| 92 | + */ | |
| 93 | + private function languageField() | |
| 94 | + { | |
| 95 | + $lang = (string) apply_filters('bitform_current_language', '', $this->getFormID()); | |
| 96 | + if ('' === $lang) { | |
| 97 | + return ''; | |
| 98 | + } | |
| 99 | + return '<input type="text" class="d-none" name="bf_lang" value="' . esc_attr($lang) . '">'; | |
| 100 | + } | |
| 101 | + | |
| 69 | 102 | public function setTheme($theme = 'Default') |
| 70 | 103 | { |
| 71 | 104 | $this->_theme = $theme; |
| 72 | 105 | } |
| @@ -147,8 +180,9 @@ | ||
| 147 | 180 | } |
| 148 | 181 | |
| 149 | 182 | public function getConversationalView($hasFile, $msg = null) |
| 150 | 183 | { |
| 184 | + $noTranslate = $this->noTranslateMarkup(); | |
| 151 | 185 | $conversationSettings = $this->getFormInfo()->conversationalSettings; |
| 152 | 186 | $this->_themeDetails = new DefaultConversationalTheme($conversationSettings); |
| 153 | 187 | $file_upload_tag = null; |
| 154 | 188 | $restrictionMsg = ''; |
| @@ -199,9 +233,9 @@ | ||
| 199 | 233 | '; |
| 200 | 234 | } |
| 201 | 235 | $formHTML = |
| 202 | 236 | ' |
| 203 | - <div id="' . $formIdentifier . '" class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper"> | |
| 237 | + <div id="' . $formIdentifier . '"' . $noTranslate['attrs'] . ' class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper' . $noTranslate['cls'] . '"> | |
| 204 | 238 | ' . $restrictionMsg . ' |
| 205 | 239 | <form novalidate id="form-' . $formIdentifier . '" class="_frm-bc' . $formID . ' bf-form" ' . $file_upload_tag . ' method=\'post\'> |
| 206 | 240 | <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> |
| 207 | 241 | <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> |
| @@ -206,8 +240,9 @@ | ||
| 206 | 240 | <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> |
| 207 | 241 | <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> |
| 208 | 242 | ' . $this->honeypotField() . ' |
| 209 | 243 | <input type="text" class="d-none" name="bitforms_id" value="bitforms_' . $this->_form->getFormID() . '"> |
| 244 | + ' . $this->languageField() . ' | |
| 210 | 245 | <div class="bc' . $formID . '-steps-container"> |
| 211 | 246 | ' . $welcomePageHtml . ' |
| 212 | 247 | ' . $fieldHtml . ' |
| 213 | 248 | ' . $conversationNavigationHtml . ' |
| @@ -222,8 +257,9 @@ | ||
| 222 | 257 | } |
| 223 | 258 | |
| 224 | 259 | private function setView($hasFile, $msg) |
| 225 | 260 | { |
| 261 | + $noTranslate = $this->noTranslateMarkup(); | |
| 226 | 262 | $file_upload_tag = null; |
| 227 | 263 | $restrictionMsg = ''; |
| 228 | 264 | $formID = $this->_form->getFormID(); |
| 229 | 265 | if ($hasFile) { |
| @@ -301,9 +337,9 @@ | ||
| 301 | 337 | '; |
| 302 | 338 | } |
| 303 | 339 | $formHTML = |
| 304 | 340 | ' |
| 305 | - <div id="' . $formIdentifier . '" class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper"> | |
| 341 | + <div id="' . $formIdentifier . '"' . $noTranslate['attrs'] . ' class="b' . $formID . '-bit-form ' . $this->_form->getAtomicCls("_frm-bg-b{$formID}") . ' bit-form bf-form-wrapper' . $noTranslate['cls'] . '"> | |
| 306 | 342 | ' . $restrictionMsg . ' |
| 307 | 343 | <form novalidate id="form-' . $formIdentifier . '" class="' . $this->_form->getAtomicCls("_frm-b{$formID}") . ' bf-form" ' . $file_upload_tag . ' method=\'post\'> |
| 308 | 344 | <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> |
| 309 | 345 | <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> |
| @@ -308,8 +344,9 @@ | ||
| 308 | 344 | <input type="text" class="d-none" name="csrf" value="' . $this->_tokens['csrf'] . '"> |
| 309 | 345 | <input type="text" class="d-none" name="t_identity" value="' . $this->_tokens['t_identity'] . '"> |
| 310 | 346 | ' . $this->honeypotField() . ' |
| 311 | 347 | <input type="text" class="d-none" name="bitforms_id" value="bitforms_' . $this->_form->getFormID() . '"> |
| 348 | + ' . $this->languageField() . ' | |
| 312 | 349 | ' . $fieldHtml . ' |
| 313 | 350 | </form> |
| 314 | 351 | ' . $abandonmentMsg . ' |
| 315 | 352 | <div id=\'bf-form-msg-wrp-' . $formIdentifier . '\'></div> |