PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 1.1.0
Translate and Go multilingual – Automatic AI translation – wpLingua v1.1.0
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 1.1.0, at inc/admin/option-page-dictionary.php

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