PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.12.1
Translate and Go multilingual – Automatic AI translation – wpLingua v2.12.1
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / admin / option-page-switcher.php

option-page-switcher.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.12.1, at inc/admin/option-page-switcher.php

599 lines 21.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8
9 /**
10 * Print HTML Option page : wpLingua Switcher
11 *
12 * @return void
13 */
14 function wplng_option_page_switcher() {
15
16 $insert = wplng_get_switcher_insert();
17 $theme = wplng_get_switcher_theme();
18 $style = wplng_get_switcher_style();
19 $name_format = wplng_get_switcher_name_format();
20 $flags_style = wplng_get_switcher_flags_style();
21 $custom_css = get_option( 'wplng_custom_css' );
22
23 $switcher_html = wplng_get_switcher_html(
24 array( 'class' => 'switcher-preview' )
25 );
26
27 if ( empty( $custom_css ) || ! is_string( $custom_css ) ) {
28 $custom_css = '';
29 } else {
30 $custom_css = wp_strip_all_tags( $custom_css );
31 }
32
33 ?>
34
35 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Switcher settings', 'wplingua' ); ?></h1>
36
37
38
39 <div class="wrap">
40 <hr class="wp-header-end">
41 <form method="post" action="options.php">
42 <?php
43 settings_fields( 'wplng_switcher' );
44 do_settings_sections( 'wplng_switcher' );
45 ?>
46 <table class="form-table wplng-form-table">
47
48 <?php if ( empty( $switcher_html ) ) : ?>
49 <div class="wplng-notice notice notice-error">
50 <p>
51 <strong><?php esc_html_e( 'No target language selected.', 'wplingua' ); ?></strong>
52 </p>
53 </div>
54 <?php else : ?>
55 <tr>
56 <th scope="row"><span class="dashicons dashicons-visibility"></span> <?php esc_html_e( 'Preview', 'wplingua' ); ?></th>
57 <td id="wplng-switcher-preview-container">
58 <div class="wplng-switcher-preview">
59 <?php echo $switcher_html; ?>
60 </div>
61 </td>
62 </tr>
63 <?php endif; ?>
64
65 <tr>
66 <th scope="row"><span class="dashicons dashicons-admin-appearance"></span> <?php esc_html_e( 'Design', 'wplingua' ); ?></th>
67 <td>
68 <p>
69 <fieldset>
70
71 <label for="wplng_style" class="wplng-fe-50">
72 <strong><?php esc_html_e( 'Layout: ', 'wplingua' ); ?></strong>
73 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-layout"></span>
74 </label>
75
76 <select id="wplng_style" name="wplng_style" class="wplng-fe-50">
77 <?php
78
79 $style_options = wplng_data_switcher_valid_style();
80
81 foreach ( $style_options as $option_value => $option_name ) {
82 if ( $style === $option_value ) {
83 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
84 } else {
85 echo '<option value="' . esc_attr( $option_value ) . '">';
86 }
87 echo esc_html( $option_name );
88 echo '</option>';
89 }
90
91 ?>
92 </select>
93
94 </fieldset>
95 </p>
96
97 <div class="wplng-help-box" id="wplng-hb-layout">
98 <p>
99 <?php esc_html_e( 'This option allow you to define the layout of the languages ​​in the switcher.', 'wplingua' ); ?>
100 </p>
101 <hr>
102 <ul>
103 <li>
104 <strong><?php esc_html_e( 'Inline list: ', 'wplingua' ); ?></strong>
105 <?php esc_html_e( 'the languages ​​are lined up next to each other.', 'wplingua' ); ?>
106 </li>
107 <li>
108 <strong><?php esc_html_e( 'Block: ', 'wplingua' ); ?></strong>
109 <?php esc_html_e( 'the languages ​​are placed in columns, one under the other.', 'wplingua' ); ?>
110 </li>
111 <li>
112 <strong><?php esc_html_e( 'Dropdown: ', 'wplingua' ); ?></strong>
113 <?php esc_html_e( 'the languages ​​appear in a drop-down menu; this is recommended when your website offers several languages.', 'wplingua' ); ?>
114 </li>
115 </ul>
116 </div>
117
118 <hr>
119
120 <p>
121 <fieldset>
122 <label for="wplng_name_format" class="wplng-fe-50">
123 <strong><?php esc_html_e( 'Displayed names: ', 'wplingua' ); ?></strong>
124 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-name-format"></span>
125 </label>
126 <select id="wplng_name_format" name="wplng_name_format" class="wplng-fe-50">
127 <?php
128
129 $name_format_options = wplng_data_switcher_valid_name_format();
130
131 foreach ( $name_format_options as $option_value => $option_name ) {
132 if ( $name_format === $option_value ) {
133 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
134 } else {
135 echo '<option value="' . esc_attr( $option_value ) . '">';
136 }
137 echo esc_html( $option_name );
138 echo '</option>';
139 }
140
141 ?>
142 </select>
143 </fieldset>
144 </p>
145
146 <div class="wplng-help-box" id="wplng-hb-name-format">
147 <p>
148 <?php esc_html_e( 'This option allow you to choose how the languages names should be written in the switcher.', 'wplingua' ); ?>
149 </p>
150
151 <hr>
152
153 <ul>
154 <li>
155 <strong><?php esc_html_e( 'Translated names: ', 'wplingua' ); ?></strong>
156 <?php esc_html_e( 'the name of the languages ​​is translated into the current language displayed.', 'wplingua' ); ?>
157 </li>
158 <li>
159 <strong><?php esc_html_e( 'Original name: ', 'wplingua' ); ?></strong>
160 <?php esc_html_e( 'each language retains its name in its own language (English, Français, 日本語, Português, Español, etc.).', 'wplingua' ); ?>
161 </li>
162 <li>
163 <strong><?php esc_html_e( 'Language ID: ', 'wplingua' ); ?></strong>
164 <?php esc_html_e( 'language names use language ID (FR, EN, DE, RU, etc.).', 'wplingua' ); ?>
165 </li>
166 <li>
167 <strong><?php esc_html_e( 'No display: ', 'wplingua' ); ?></strong>
168 <?php esc_html_e( 'no text, only flags are displayed.', 'wplingua' ); ?>
169 </li>
170 </ul>
171 </div>
172
173 <hr>
174
175 <p>
176 <fieldset>
177 <label for="wplng_flags_style" class="wplng-fe-50">
178 <strong><?php esc_html_e( 'Flags style: ', 'wplingua' ); ?></strong>
179 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-flags-style"></span>
180 </label>
181 <select id="wplng_flags_style" name="wplng_flags_style" class="wplng-fe-50">
182 <?php
183
184 $flags_style_options = wplng_data_switcher_valid_flags_style();
185
186 foreach ( $flags_style_options as $option_value => $option_name ) {
187 if ( $flags_style === $option_value ) {
188 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
189 } else {
190 echo '<option value="' . esc_attr( $option_value ) . '">';
191 }
192 echo esc_html( $option_name );
193 echo '</option>';
194 }
195
196 ?>
197 </select>
198 </fieldset>
199 </p>
200
201 <div class="wplng-help-box" id="wplng-hb-flags-style">
202 <p><?php esc_html_e( 'This option allow you to choose the appearance of the flags in the switcher. ', 'wplingua' ); ?></p>
203
204 <hr>
205
206 <ul>
207 <li>
208 <strong><?php esc_html_e( 'Circle: ', 'wplingua' ); ?></strong>
209 <?php esc_html_e( 'display round flags.', 'wplingua' ); ?>
210 </li>
211 <li>
212 <strong><?php esc_html_e( 'Rectangular: ', 'wplingua' ); ?></strong>
213 <?php esc_html_e( 'display rectangular flags.', 'wplingua' ); ?>
214 </li>
215 <li>
216 <strong><?php esc_html_e( 'Wave: ', 'wplingua' ); ?></strong>
217 <?php esc_html_e( 'display wavy flags.', 'wplingua' ); ?>
218 </li>
219 <li>
220 <strong><?php esc_html_e( 'No display: ', 'wplingua' ); ?></strong>
221 <?php esc_html_e( 'no display any flags, only the language name will be displayed.', 'wplingua' ); ?>
222 </li>
223 </ul>
224
225 <hr>
226
227 <p><?php esc_html_e( 'You can also change the country flag or set a custom flag from wpLingua ➔ General settings. For example, you can set the flag of Mexico for Spanish instead of the flag of Spain.', 'wplingua' ); ?></p>
228
229 </div>
230
231 <hr>
232
233 <p>
234 <fieldset>
235 <label for="wplng_theme" class="wplng-fe-50">
236 <strong><?php esc_html_e( 'Color theme: ', 'wplingua' ); ?></strong>
237 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-theme"></span>
238 </label>
239
240 <select id="wplng_theme" name="wplng_theme" class="wplng-fe-50">
241 <?php
242
243 $theme_options = wplng_data_switcher_valid_theme();
244
245 foreach ( $theme_options as $option_value => $option_name ) {
246 if ( $theme === $option_value ) {
247 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
248 } else {
249 echo '<option value="' . esc_attr( $option_value ) . '">';
250 }
251 echo esc_html( $option_name );
252 echo '</option>';
253 }
254
255 ?>
256 </select>
257 </fieldset>
258 </p>
259
260 <div class="wplng-help-box" id="wplng-hb-theme">
261 <p>
262 <?php esc_html_e( 'This option allows you to choose the color and border styles of the languages switcher.', 'wplingua' ); ?>
263 </p>
264
265 <hr>
266
267 <p>
268 <?php esc_html_e( 'The color options offer 5 themes: ', 'wplingua' ); ?>
269 </p>
270
271 <ul>
272 <li>
273 <strong><?php esc_html_e( 'Light: ', 'wplingua' ); ?></strong>
274 <?php esc_html_e( 'white color in the background of the switcher.', 'wplingua' ); ?>
275 </li>
276 <li>
277 <strong><?php esc_html_e( 'Grey: ', 'wplingua' ); ?></strong>
278 <?php esc_html_e( 'grey background color.', 'wplingua' ); ?>
279 </li>
280 <li>
281 <strong><?php esc_html_e( 'Dark: ', 'wplingua' ); ?></strong>
282 <?php esc_html_e( 'black background color.', 'wplingua' ); ?>
283 </li>
284 <li>
285 <strong><?php esc_html_e( 'Blur Black: ', 'wplingua' ); ?></strong>
286 <?php esc_html_e( 'transparent and blurred background color with black text and borders.', 'wplingua' ); ?>
287 </li>
288 <li>
289 <strong><?php esc_html_e( 'Blur White: ', 'wplingua' ); ?></strong>
290 <?php esc_html_e( 'transparent and blurred background color with white text and borders.', 'wplingua' ); ?>
291 </li>
292 </ul>
293
294 <hr>
295
296 <p>
297 <?php esc_html_e( 'Each theme is then broken down by shape and border style:', 'wplingua' ); ?>
298 </p>
299
300 <ul>
301 <li>
302 <strong><?php esc_html_e( 'Double – Smooth: ', 'wplingua' ); ?></strong>
303 <?php esc_html_e( 'the switcher will be framed by a double border with rounded corners.', 'wplingua' ); ?>
304 </li>
305 <li>
306 <strong><?php esc_html_e( 'Double – Square: ', 'wplingua' ); ?></strong>
307 <?php esc_html_e( 'double border with square corners.', 'wplingua' ); ?>
308 </li>
309 <li>
310 <strong><?php esc_html_e( 'Simple – Smooth: ', 'wplingua' ); ?></strong>
311 <?php esc_html_e( 'single border with rounded corners.', 'wplingua' ); ?>
312 </li>
313 <li>
314 <strong><?php esc_html_e( 'Simple – Square: ', 'wplingua' ); ?></strong>
315 <?php esc_html_e( 'single border with square corners.', 'wplingua' ); ?>
316 </li>
317 </ul>
318
319 </div>
320
321 </td>
322 </tr>
323
324 <tr>
325 <th scope="row"><span class="dashicons dashicons-media-code"></span> <?php esc_html_e( 'Custom CSS', 'wplingua' ); ?></th>
326 <td>
327 <p><strong><?php esc_html_e( 'Set custom CSS: ', 'wplingua' ); ?></strong></p>
328 <hr>
329 <p>
330 <?php esc_html_e( 'The field below allows you to add custom CSS code that will run on all pages.', 'wplingua' ); ?>
331 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-css"></span>
332 </p>
333 <div class="wplng-help-box" id="wplng-hb-css">
334 <p>
335 <?php _e( 'First of all, note that the CSS class <code>.switcher-content</code> allows you to act on the entire block of the language switcher while the class <code>.wplng-langague</code> allows you to act on the languages ​​themselves.', 'wplingua' ); ?>
336 </p>
337
338 <?php
339 echo '<pre>';
340 echo '.wplng-switcher.theme-light-double-square .switcher-content {' . PHP_EOL;
341 echo ' background-color: #5e33d9;' . PHP_EOL;
342 echo ' border: 1px solid #5e33d9;' . PHP_EOL;
343 echo '}';
344 echo '</pre>';
345 ?>
346
347 <hr>
348
349 <p>
350 <?php _e( 'To change the background and border colors of languages, here is the CSS:' ); ?>
351 </p>
352
353 <?php
354 echo '<pre>';
355 echo '.wplng-switcher.theme-light-double-square .switcher-content .wplng-language {' . PHP_EOL;
356 echo ' border: 1px solid #5e33d9;' . PHP_EOL;
357 echo ' color: #5e33d9;' . PHP_EOL;
358 echo '}';
359 echo '</pre>';
360 ?>
361
362 <hr>
363
364 <p>
365 <a href="https://wplingua.com/documentation/user/how-to-customize-the-language-switcher/" target="_blank"><?php _e( 'More example on wplingua.com' ); ?></a>
366 </p>
367 </div>
368
369 <fieldset>
370 <textarea name="wplng_custom_css" id="wplng_custom_css" spellcheck="false"><?php echo esc_textarea( $custom_css ); ?></textarea>
371 </fieldset>
372 </td>
373 </tr>
374
375 <tr>
376 <th scope="row"><span class="dashicons dashicons-admin-post"></span> <?php esc_html_e( 'Insertion', 'wplingua' ); ?></th>
377 <td>
378
379 <p>
380 <fieldset>
381
382 <label for="wplng_insert" class="wplng-fe-50">
383 <strong><?php _e( 'Automatic insert: ', 'wplingua' ); ?></strong>
384 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-insert-automatic"></span>
385 </label>
386
387 <select id="wplng_insert" name="wplng_insert" class="wplng-fe-50">
388 <?php
389
390 $insert_options = wplng_data_switcher_valid_insert();
391
392 foreach ( $insert_options as $option_value => $option_name ) {
393 if ( $insert === $option_value ) {
394 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
395 } else {
396 echo '<option value="' . esc_attr( $option_value ) . '">';
397 }
398 echo esc_html( $option_name );
399 echo '</option>';
400 }
401
402 ?>
403 </select>
404
405 </fieldset>
406 </p>
407
408 <div class="wplng-help-box" id="wplng-hb-insert-automatic">
409 <p><?php esc_html_e( 'Choose a predefined location: ', 'wplingua' ); ?></p>
410
411 <ul>
412 <li>
413 <strong><?php esc_html_e( 'Bottom right: ', 'wplingua' ); ?></strong>
414 <?php esc_html_e( 'the switcher is placed at the bottom right of the screen.', 'wplingua' ); ?>
415 </li>
416 <li>
417 <strong><?php esc_html_e( 'Bottom Center: ', 'wplingua' ); ?></strong>
418 <?php esc_html_e( 'bottom center of the screen.', 'wplingua' ); ?>
419 </li>
420 <li>
421 <strong><?php esc_html_e( 'Bottom left: ', 'wplingua' ); ?></strong>
422 <?php esc_html_e( 'bottom left of the screen.', 'wplingua' ); ?>
423 </li>
424 <li>
425 <strong><?php esc_html_e( 'None: ', 'wplingua' ); ?></strong>
426 <?php esc_html_e( 'the switcher is not inserted automatically.', 'wplingua' ); ?>
427 </li>
428 </ul>
429
430 </div>
431
432 <hr>
433
434 <p>
435 <strong class="wplng-fe-50">
436 <?php esc_html_e( 'Shortcode switcher: ', 'wplingua' ); ?>
437 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-insert-shortcode"></span>
438 </strong>
439 <code class="wplng-fe-50">[wplng_switcher]</code>
440 </p>
441
442 <div class="wplng-help-box" id="wplng-hb-insert-shortcode">
443 <p><?php esc_html_e( 'If you want to insert the language switcher only in certain places on your website, you can use the shortcode provided for this purpose. Note that in this case, the previous option should be "None". This method is ideal for placing the switcher where you want it, whether you are using a Gutenberg block-based theme (FSE), a classic theme or even a page or theme builder like Divi, Elementor...', 'wplingua' ); ?></p>
444 <hr>
445 <p><?php esc_html_e( 'You can add parameters to the language selector shortcode, for example: ', 'wplingua' ); ?></p>
446 <pre>[wplng_switcher style="dropdown" theme="dark-simple-smooth"]</pre>
447 <hr>
448 <p><?php esc_html_e( 'Here is a list of all available settings: ', 'wplingua' ); ?></p>
449 <pre>[wplng_switcher style="list|block|dropdown" flags="circle|rectangular|wave|none" title="original|name|id|none" class="you-css-class" theme="light-double-smooth|light-double-square|light-simple-smooth|light-simple-square|grey-double-smooth|grey-double-square|grey-simple-smooth|grey-simple-square|dark-double-smooth|dark-double-square|dark-simple-smooth|dark-simple-square|blurblack-double-smooth|blurblack-double-square|blurblack-simple-smooth|blurblack-simple-square|blurwhite-double-smooth|blurwhite-double-square|blurwhite-simple-smooth|blurwhite-simple-square"]</pre>
450 <hr>
451 <p><?php esc_html_e( 'If a setting is not specified, the value entered on the language switcher options page will be used.', 'wplingua' ); ?></p>
452 </div>
453
454 <hr>
455
456 <p>
457 <strong class="wplng-fe-50">
458 <?php esc_html_e( 'Gutenberg & FSE: ', 'wplingua' ); ?>
459 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-insert-block"></span>
460 </strong>
461 <span class="wplng-fe-50"><?php esc_html_e( 'Block wpLingua Switcher', 'wplingua' ); ?> </span>
462 </p>
463
464 <div class="wplng-help-box" id="wplng-hb-insert-block">
465 <p><?php esc_html_e( 'Block based themes, wpLingua offers a dedicated Gutenberg block. You can insert the switcher wherever you want, whether in the content or via the overall site editor.', 'wplingua' ); ?></p>
466 </div>
467
468 <hr>
469
470 <p>
471 <strong class="wplng-fe-50">
472 <?php esc_html_e( 'Switcher in menu: ', 'wplingua' ); ?>
473 <span title="<?php esc_attr_e( 'Click to expand', 'wplingua' ); ?>" wplng-help-box="#wplng-hb-insert-menu"></span>
474 </strong>
475 <span class="wplng-fe-50">
476 <?php
477
478 $support_menus = ! empty( get_nav_menu_locations() );
479
480 if ( $support_menus ) {
481 echo '<a ';
482 echo 'href="' . esc_url( get_admin_url() . 'nav-menus.php' ) . '" ';
483 echo 'target="_blank"';
484 echo '>';
485 }
486
487 esc_html_e( 'Appearance ➔ Menus', 'wplingua' );
488
489 if ( $support_menus ) {
490 echo '</a>';
491 }
492
493 ?>
494 </span>
495 </p>
496
497 <div class="wplng-help-box" id="wplng-hb-insert-menu">
498 <p><?php esc_html_e( 'If the active theme manages menus (classic theme), it is possible to add a language switcher. The design of these language switchers will be defined by the theme. Go to the Appearance ➔ Menu tab to add the wpLingua switcher as a menu item. It is also possible to add it as a sub-element.', 'wplingua' ); ?></p>
499 </div>
500
501 </td>
502 </tr>
503 <tr class="wplng-tr-submit">
504 <th scope="row"><span class="dashicons dashicons-yes-alt"></span> <?php _e( 'Save', 'wplingua' ); ?></th>
505 <td>
506 <?php submit_button(); ?>
507 </td>
508 </tr>
509 </table>
510 </form>
511 </div>
512 <?php
513 }
514
515
516 /**
517 * Print HTML subsection of Option page : wpLingua Switcher - Flags style
518 *
519 * @param string $old_flags_style Flag URL
520 * @param string $new_flags_style Flag URL
521 * @return void
522 */
523 function wplng_options_switcher_update_flags_style( $old_flags_style, $new_flags_style ) {
524
525 if ( $old_flags_style === $new_flags_style ) {
526 return;
527 }
528
529 if ( 'none' === $new_flags_style ) {
530 $new_flags_style = 'rectangular';
531 }
532
533 if ( 'none' === $old_flags_style ) {
534 $old_flags_style = 'rectangular';
535 }
536
537 /**
538 * Replace flag URL for website language
539 */
540
541 $website_flag = wplng_get_language_website_flag();
542
543 $website_flag = str_replace(
544 '/wplingua/assets/images/' . $old_flags_style . '/',
545 '/wplingua/assets/images/' . $new_flags_style . '/',
546 $website_flag
547 );
548
549 $website_flag = sanitize_url( $website_flag );
550
551 update_option( 'wplng_website_flag', $website_flag );
552
553 /**
554 * Replace flag URL for target languages
555 */
556
557 $target_languages_json = get_option( 'wplng_target_languages' );
558
559 if ( empty( $target_languages_json ) ) {
560 return;
561 }
562
563 $target_languages = json_decode(
564 $target_languages_json,
565 true
566 );
567
568 if ( empty( $target_languages ) || ! is_array( $target_languages ) ) {
569 return;
570 }
571
572 foreach ( $target_languages as $key => $target_language ) {
573 if ( ! empty( $target_language['flag'] )
574 && is_string( $target_language['flag'] )
575 ) {
576
577 $old_src = sanitize_url( $target_language['flag'] );
578
579 $new_src = str_replace(
580 '/' . $old_flags_style . '/',
581 '/' . $new_flags_style . '/',
582 $old_src
583 );
584
585 $new_src = sanitize_url( $new_src );
586
587 $target_languages[ $key ]['flag'] = $new_src;
588 }
589 }
590
591 update_option(
592 'wplng_target_languages',
593 wp_json_encode(
594 $target_languages,
595 JSON_UNESCAPED_SLASHES
596 )
597 );
598 }
599