PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.14.2
Translate and Go multilingual – Automatic AI translation – wpLingua v2.14.2
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-dictionary.php

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

415 lines 11.8 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 Dictionary
11 *
12 * @return void
13 */
14 function wplng_option_page_dictionary() {
15
16 $entries_json = wplng_dictionary_get_entries_json();
17
18 ?>
19
20 <h1 class="wplng-option-page-title"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Dictionary rules', 'wplingua' ); ?></h1>
21
22 <div class="wrap">
23 <hr class="wp-header-end">
24 <form method="post" action="options.php">
25 <?php
26 settings_fields( 'wplng_dictionary' );
27 do_settings_sections( 'wplng_dictionary' );
28 ?>
29 <table class="form-table wplng-form-table">
30
31 <tr class="wplng-beta-hidden" style="display: none;">
32 <th scope="row"><span class="dashicons dashicons-printer"></span> <?php esc_html_e( 'Debug', 'wplingua' ); ?></th>
33 <td>
34 <fieldset>
35 <textarea name="wplng_dictionary_entries" id="wplng_dictionary_entries"><?php echo esc_textarea( $entries_json ); ?></textarea>
36 </fieldset>
37 </td>
38 </tr>
39
40 <tr id="wplng-section-entries-all">
41 <th scope="row"><span class="dashicons dashicons-book"></span> <?php esc_html_e( 'Dictionary entries', 'wplingua' ); ?></th>
42 <td>
43 <fieldset>
44
45 <p><strong><?php esc_html_e( 'Translation rules by dictionary: ', 'wplingua' ); ?></strong></p>
46
47 <p><?php esc_html_e( 'The dictionary allows you to define translation rules that apply when generating machine translations. You can specify words or sets of words that should never be translated, or define how they should be translated for each language.', 'wplingua' ); ?></p>
48
49 <hr>
50
51 <?php wplng_option_page_dictionary_entries_html(); ?>
52
53 <a href="javascript:void(0);" class="button button-primary" id="wplng-new-rule-button">
54 <?php esc_html_e( 'Add a dictionary entry', 'wplingua' ); ?>
55 </a>
56
57 </fieldset>
58 </td>
59 </tr>
60
61 <tr id="wplng-section-entry-new" style="display: none;">
62 <th scope="row"><span class="dashicons dashicons-welcome-add-page"></span> <?php esc_html_e( 'Add an entry', 'wplingua' ); ?></th>
63 <td>
64 <div id="wplng-dictionary-entry-new">
65 <?php wplng_option_page_dictionary_new_entry_html(); ?>
66 </div>
67 </td>
68 </tr>
69
70 <tr id="wplng-section-entry-edit" style="display: none;">
71 <th scope="row"><span class="dashicons dashicons-welcome-write-blog"></span> <?php esc_html_e( 'Edit the entry', 'wplingua' ); ?></th>
72 <td>
73 <div id="wplng-dictionary-entry-edit">
74 <?php wplng_option_page_dictionary_edit_entry_html(); ?>
75 </div>
76 </td>
77 </tr>
78 </table>
79
80 <?php submit_button(); ?>
81
82 </form>
83 </div>
84 <?php
85 }
86
87
88 /**
89 * Print HTML subsection of Option page : wpLingua Dictionary - Entries
90 *
91 * @return void
92 */
93 function wplng_option_page_dictionary_entries_html() {
94
95 $dictionary_entries = wplng_dictionary_get_entries();
96
97 if ( empty( $dictionary_entries ) ) {
98 return '';
99 }
100
101 $language_website = wplng_get_language_website();
102 $language_website_html = '<img';
103 $language_website_html .= ' src="' . esc_url( $language_website['flag'] ) . '"';
104 $language_website_html .= ' alt="' . esc_attr( $language_website['name'] ) . '"';
105 $language_website_html .= ' class="wplng-flag"';
106 $language_website_html .= '>';
107
108 $html = '<label><strong>';
109 $html .= esc_html__( 'All dictionary entries: ', 'wplingua' );
110 $html .= '</strong></label>';
111 $html .= '<br>';
112 $html .= '<div id="wplng-dictionary-entries">';
113
114 foreach ( $dictionary_entries as $rule_number => $entry ) {
115
116 $html .= '<div';
117 $html .= ' class="wplng-dictionary-entry"';
118 $html .= ' wplng-rule="' . esc_attr( $rule_number ) . '"';
119 $html .= '>';
120
121 $html .= '<div class="wplng-rule-header">';
122
123 $html .= '<div class="wplng-rule-name">';
124 $html .= esc_html__( 'Rule N°', 'wplingua' );
125 $html .= esc_html( $rule_number + 1 );
126 $html .= '</div>'; // ENd .wplng-rule-name
127
128 $html .= '<div class="wplng-rule-action">';
129 $html .= '<a';
130 $html .= ' href="javascript:void(0);"';
131 $html .= ' class="wplng-rule-link-edit"';
132 $html .= ' wplng-rule="' . esc_attr( $rule_number ) . '"';
133 $html .= '>';
134 $html .= esc_html__( 'Edit', 'wplingua' );
135 $html .= '</a> ';
136 $html .= '<a';
137 $html .= ' href="javascript:void(0);"';
138 $html .= ' class="wplng-rule-link-remove"';
139 $html .= ' wplng-rule="' . esc_attr( $rule_number ) . '"';
140 $html .= '>';
141 $html .= esc_html__( 'Remove', 'wplingua' );
142 $html .= '</a>';
143 $html .= '</div>'; // .wplng-rule-action
144
145 $html .= '</div>'; // End .wplng-rule-header
146
147 $html .= '<hr>';
148
149 if ( isset( $entry['rules'] ) ) {
150
151 $html .= '<strong>';
152 $html .= $language_website_html;
153 $html .= esc_html__( 'Always translate: ', 'wplingua' );
154 $html .= '</strong>';
155 $html .= esc_html( $entry['source'] );
156
157 foreach ( $entry['rules'] as $language_id => $rule ) {
158
159 $language = wplng_get_language_by_id( $language_id );
160
161 $html .= '<hr>';
162 $html .= '<strong>';
163 $html .= '<img';
164 $html .= ' src="' . esc_url( $language['flag'] ) . '"';
165 $html .= ' alt="' . esc_attr( $language['name'] ) . '"';
166 $html .= ' class="wplng-flag"';
167 $html .= '>';
168 $html .= esc_html( $language['name'] );
169 $html .= esc_html__( ' - By: ', 'wplingua' );
170 $html .= '</strong>';
171 $html .= esc_html( $rule );
172 }
173 } else {
174 $html .= '<strong>';
175 $html .= esc_html__( 'Never translate: ', 'wplingua' );
176 $html .= '</strong>';
177 $html .= esc_html( $entry['source'] );
178 }
179
180 $html .= '</div>'; // End .wplng-dictionary-entry
181 }
182
183 $html .= '</div>'; // End #wplng-dictionary-entries
184
185 echo $html;
186 }
187
188
189 /**
190 * Print HTML subsection of Option page : wpLingua Dictionary - New entry
191 *
192 * @return void
193 */
194 function wplng_option_page_dictionary_new_entry_html() {
195
196 $html = '';
197
198 /**
199 * Input : Source
200 */
201
202 $language_website = wplng_get_language_website();
203 $language_website_html = '<img';
204 $language_website_html .= ' src="' . esc_url( $language_website['flag'] ) . '"';
205 $language_website_html .= ' alt="' . esc_attr( $language_website['name'] ) . '"';
206 $language_website_html .= ' class="wplng-flag"';
207 $language_website_html .= '>';
208
209 $html .= '<fieldset>';
210 $html .= '<label for="wplng-new-source">';
211 $html .= '<strong>';
212 $html .= $language_website_html;
213 $html .= esc_html__( 'Source text: ', 'wplingua' );
214 $html .= '</strong>';
215 $html .= '</label>';
216 $html .= '<br>';
217 $html .= '<textarea';
218 $html .= ' name="wplng-new-source"';
219 $html .= ' id="wplng-new-source"';
220 $html .= ' class="wplng-adaptive-textarea"';
221 $html .= ' maxlength="256"';
222 $html .= '>';
223 $html .= '</textarea>';
224 $html .= '</fieldset>';
225
226 /**
227 * Input : Never translate
228 */
229
230 $html .= '<fieldset>';
231 $html .= '<input';
232 $html .= ' type="checkbox"';
233 $html .= ' id="wplng-new-never-translate"';
234 $html .= ' name="wplng-new-never-translate"';
235 $html .= '>';
236 $html .= '<label for="wplng-new-never-translate"> ';
237 $html .= esc_html__( 'Never translate', 'wplingua' );
238 $html .= '</label>';
239 $html .= '</fieldset>';
240
241 $language_target = wplng_get_languages_target();
242
243 $html .= '<div id="wplng-new-rules">';
244 foreach ( $language_target as $language ) {
245
246 $name = 'wplng-new-always-translate-' . $language['id'];
247
248 $html .= '<div class="wplng-new-rule" wplng-rule="' . esc_html( $language['id'] ) . '">';
249 $html .= '<hr>';
250 $html .= '<fieldset>';
251 $html .= '<label for="' . esc_attr( $name ) . '">';
252 $html .= '<strong>';
253 $html .= '<img';
254 $html .= ' src="' . esc_url( $language['flag'] ) . '"';
255 $html .= ' alt="' . esc_attr( $language['name'] ) . '"';
256 $html .= ' class="wplng-flag"';
257 $html .= '>';
258 $html .= esc_html( $language['name'] );
259 $html .= esc_html__( ' - Always translate by: ', 'wplingua' );
260 $html .= '</strong>';
261 $html .= '</label>';
262
263 $html .= '<br>';
264
265 $html .= '<textarea';
266 $html .= ' name="' . esc_attr( $name ) . '"';
267 $html .= ' id="' . esc_attr( $name ) . '"';
268 $html .= ' class="wplng-adaptive-textarea"';
269 $html .= ' maxlength="256"';
270 $html .= '>';
271 $html .= '</textarea>';
272
273 $html .= '</fieldset>';
274 $html .= '</div>';
275
276 }
277 $html .= '</div>';
278
279 $html .= '<div id="wplng-new-action-section">';
280
281 $html .= '<a';
282 $html .= ' href="javascript:void(0);"';
283 $html .= ' id="wplng-new-cancel-button"';
284 $html .= ' class="button "';
285 $html .= '>';
286 $html .= esc_html__( 'Cancel', 'wplingua' );
287 $html .= '</a>';
288
289 $html .= '<a';
290 $html .= ' href="javascript:void(0);"';
291 $html .= ' id="wplng-new-add-button"';
292 $html .= ' class="button button-primary"';
293 $html .= '>';
294 $html .= esc_html__( 'Save new entry', 'wplingua' );
295 $html .= '</a>';
296
297 $html .= '</div>';
298
299 echo $html;
300 }
301
302
303 /**
304 * Print HTML subsection of Option page : wpLingua Dictionary - Edit entry
305 *
306 * @return void
307 */
308 function wplng_option_page_dictionary_edit_entry_html() {
309
310 $html = '';
311
312 /**
313 * Input : Source
314 */
315
316 $language_website = wplng_get_language_website();
317 $language_website_html = '<img';
318 $language_website_html .= ' src="' . esc_url( $language_website['flag'] ) . '"';
319 $language_website_html .= ' alt="' . esc_attr( $language_website['name'] ) . '"';
320 $language_website_html .= ' class="wplng-flag"';
321 $language_website_html .= '>';
322
323 $html .= '<fieldset>';
324 $html .= '<label for="wplng-edit-source">';
325 $html .= '<strong>';
326 $html .= $language_website_html;
327 $html .= esc_html__( 'Source text: ', 'wplingua' );
328 $html .= '</strong>';
329 $html .= '</label>';
330 $html .= '<br>';
331 $html .= '<textarea';
332 $html .= ' name="wplng-edit-source"';
333 $html .= ' id="wplng-edit-source"';
334 $html .= ' class="wplng-adaptive-textarea"';
335 $html .= ' maxlength="256"';
336 $html .= '>';
337 $html .= '</textarea>';
338 $html .= '</fieldset>';
339
340 /**
341 * Input : Never translate
342 */
343
344 $html .= '<fieldset>';
345 $html .= '<input';
346 $html .= ' type="checkbox"';
347 $html .= ' id="wplng-edit-never-translate"';
348 $html .= ' name="wplng-edit-never-translate"';
349 $html .= '>';
350 $html .= '<label for="wplng-edit-never-translate"> ';
351 $html .= esc_html__( 'Never translate', 'wplingua' );
352 $html .= '</label>';
353 $html .= '</fieldset>';
354
355 $language_target = wplng_get_languages_target();
356
357 $html .= '<div id="wplng-edit-rules">';
358 foreach ( $language_target as $language ) {
359
360 $name = 'wplng-edit-always-translate-' . $language['id'];
361
362 $html .= '<div class="wplng-edit-rule" wplng-rule="' . esc_html( $language['id'] ) . '">';
363 $html .= '<hr>';
364 $html .= '<fieldset>';
365 $html .= '<label for="' . esc_attr( $name ) . '">';
366 $html .= '<strong>';
367 $html .= '<img';
368 $html .= ' src="' . esc_url( $language['flag'] ) . '"';
369 $html .= ' alt="' . esc_attr( $language['name'] ) . '"';
370 $html .= ' class="wplng-flag"';
371 $html .= '>';
372 $html .= esc_html( $language['name'] );
373 $html .= esc_html__( ' - Always translate by: ', 'wplingua' );
374 $html .= '</strong>';
375 $html .= '</label>';
376
377 $html .= '<br>';
378
379 $html .= '<textarea';
380 $html .= ' name="' . esc_attr( $name ) . '"';
381 $html .= ' id="' . esc_attr( $name ) . '"';
382 $html .= ' class="wplng-adaptive-textarea"';
383 $html .= ' maxlength="256"';
384 $html .= '>';
385 $html .= '</textarea>';
386
387 $html .= '</fieldset>';
388 $html .= '</div>';
389
390 }
391 $html .= '</div>';
392
393 $html .= '<div id="wplng-edit-action-section">';
394
395 $html .= '<a';
396 $html .= ' href="javascript:void(0);"';
397 $html .= ' id="wplng-edit-cancel-button"';
398 $html .= ' class="button "';
399 $html .= '>';
400 $html .= esc_html__( 'Cancel', 'wplingua' );
401 $html .= '</a>';
402
403 $html .= '<a';
404 $html .= ' href="javascript:void(0);"';
405 $html .= ' id="wplng-edit-save-button"';
406 $html .= ' class="button button-primary"';
407 $html .= '>';
408 $html .= esc_html__( 'Save edited entry', 'wplingua' );
409 $html .= '</a>';
410
411 $html .= '</div>';
412
413 echo $html;
414 }
415