class-wpml-translation-editor.php
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
if ( ! class_exists( '_WP_Editors', false ) ) {
require ABSPATH . WPINC . '/class-wp-editor.php';
}
class WPML_Translation_Editor extends WPML_WPDB_And_SP_User {
/**
* @var WPML_Element_Translation_Job $job
*/
private $job;
/**
* @param SitePress $sitepress
* @param wpdb $wpdb
* @param WPML_Element_Translation_Job $job
*/
public function __construct(
&$sitepress,
&$wpdb,
$job
) {
parent::__construct( $wpdb, $sitepress );
$this->job = $job;
$this->add_hooks();
$this->enqueue_js();
}
public function add_hooks() {
add_filter( 'tiny_mce_before_init', [ $this, 'filter_original_editor_buttons' ], 10, 2 );
}
/**
* Enqueues the JavaScript used by the TM editor.
*/
public function enqueue_js() {
wp_enqueue_script( 'wpml-tm-editor-scripts' );
wp_localize_script(
'wpml-tm-editor-scripts',
'tmEditorStrings',
$this->get_translation_editor_strings()
);
}
/**
* @return string[]
*/
private function get_translation_editor_strings() {
$translation_memory_endpoint = apply_filters( 'wpml_st_translation_memory_endpoint', '' );
return array(
'dontShowAgain' => __(
"Don't show this again.",
'wpml-translation-management'
),
'learnMore' => __(
'<p>The administrator has disabled term translation from the translation editor. </p>
<p>If your access permissions allow you can change this under "Translation Management" - "Multilingual Content Setup" - "Block translating taxonomy terms that already got translated". </p>
<p>Please note that editing terms from the translation editor will affect all posts that have the respective terms associated.</p>',
'wpml-translation-management'
),
'warning' => __(
"Please be advised that editing this term's translation here will change the value of the term in general. The changes made here, will not only affect this post!",
'wpml-translation-management'
),
'title' => __(
'Terms translation is disabled',
'wpml-translation-management'
),
'confirm' => __(
'You have unsaved work. Are you sure you want to close without saving?',
'wpml-translation-management'
),
'cancel' => __(
'Cancel',
'wpml-translation-management'
),
'save' => __(
'Save',
'wpml-translation-management'
),
'hide_translated' => __(
'Hide completed',
'wpml-translation-management'
),
'save_and_close' => __(
'Save & Close',
'wpml-translation-management'
),
'loading_url' => ICL_PLUGIN_URL . '/res/img/ajax-loader.gif',
'saving' => __(
'Saving...',
'wpml-translation-management'
),
'translation_complete' => __(
'Translation is complete',
'wpml-translation-management'
),
'contentNonce' => wp_create_nonce( 'wpml_save_job_nonce' ),
'translationMemoryNonce' => \WPML\LIB\WP\Nonce::create( $translation_memory_endpoint ),
'translationMemoryEndpoint' => $translation_memory_endpoint,
'source_lang' => __(
'Original',
'wpml-translation-management'
),
'target_lang' => __(
'Translation to',
'wpml-translation-management'
),
'copy_all' => __(
'Copy all fields from original',
'wpml-translation-management'
),
'resign' => __(
'Resign',
'wpml-translation-management'
),
'resign_translation' => __(
'Are you sure you want to resign from this job?',
'wpml-translation-management'
),
'resign_url' => admin_url( 'admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php&icl_tm_action=save_translation&resign=1&job_id=' . $this->job->get_id() . '&nonce=' . wp_create_nonce( 'save_translation' ) ),
'confirmNavigate' => __(
'You have unsaved changes!',
'wpml-translation-management'
),
'copy_from_original' => __(
'Copy from original',
'wpml-translation-management'
),
'show_diff' => __( 'Show differences', 'wpml-translation-management' ),
);
}
public function filter_original_editor_buttons( $config, $editor_id ) {
if ( strpos( $editor_id, '_original' ) > 0 ) {
$config['toolbar1'] = ' ';
$config['toolbar2'] = ' ';
$config['readonly'] = '1';
}
return $config;
}
public function output_editors( $field ) {
echo '<div id="' . $field['field_type'] . '_original_editor" class="original_value mce_editor_origin">';
wp_editor(
$field['field_data'],
$field['field_type'] . '_original',
array(
'textarea_rows' => 4,
'editor_class' => 'wpml_content_tr original_value mce_editor_origin',
'media_buttons' => false,
'quicktags' => array( 'buttons' => 'empty' ),
)
);
echo '</div>';
echo '<div id="' . $field['field_type'] . '_translated_editor" class="mce_editor translated_value">';
wp_editor(
$field['field_data_translated'],
$field['field_type'],
array(
'textarea_rows' => 4,
'editor_class' => 'wpml_content_tr translated_value',
'media_buttons' => true,
'textarea_name' => 'fields[' . $field['field_type'] . '][data]',
)
);
echo '</div>';
}
}