PluginProbe
Polylang / 3.7.1
Polylang v3.7.1
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | settings/table-string.php +49 -40 3.0.23.7.1 View file →
@@ -73,14 +73,14 @@
73 73 add_action( 'mlang_action_string-translation', array( $this, 'save_translations' ) );
74 74 }
75 75
76 76 /**
77 - * Displays the item information in a column ( default case )
77 + * Displays the item information in a column (default case).
78 78 *
79 79 * @since 0.6
80 80 *
81 - * @param array $item
82 - * @param string $column_name
81 + * @param array $item Data related to the current string.
82 + * @param string $column_name The current column name.
83 83 * @return string
84 84 */
85 85 public function column_default( $item, $column_name ) {
86 86 return $item[ $column_name ];
@@ -86,13 +86,13 @@
86 86 return $item[ $column_name ];
87 87 }
88 88
89 89 /**
90 - * Displays the checkbox in first column
90 + * Displays the checkbox in first column.
91 91 *
92 92 * @since 1.1
93 93 *
94 - * @param array $item
94 + * @param array $item Data related to the current string.
95 95 * @return string
96 96 */
97 97 public function column_cb( $item ) {
98 98 return sprintf(
@@ -99,36 +99,40 @@
99 99 '<label class="screen-reader-text" for="cb-select-%1$s">%2$s</label><input id="cb-select-%1$s" type="checkbox" name="strings[]" value="%1$s" %3$s />',
100 100 esc_attr( $item['row'] ),
101 101 /* translators: accessibility text, %s is a string potentially in any language */
102 102 sprintf( __( 'Select %s', 'polylang' ), format_to_edit( $item['string'] ) ),
103 - empty( $item['icl'] ) ? 'disabled' : '' // Only strings registered with WPML API can be removed
103 + empty( $item['icl'] ) ? 'disabled' : '' // Only strings registered with WPML API can be removed.
104 104 );
105 105 }
106 106
107 107 /**
108 - * Displays the string to translate
108 + * Displays the string to translate.
109 109 *
110 110 * @since 1.0
111 111 *
112 - * @param array $item
112 + * @param array $item Data related to the current string.
113 113 * @return string
114 114 */
115 115 public function column_string( $item ) {
116 - return format_to_edit( $item['string'] ); // Don't interpret special chars for the string column
116 + return format_to_edit( $item['string'] ); // Don't interpret special chars for the string column.
117 117 }
118 118
119 119 /**
120 - * Displays the translations to edit
120 + * Displays the translations to edit.
121 121 *
122 122 * @since 0.6
123 123 *
124 - * @param array $item
124 + * @param array $item Data related to the current string.
125 125 * @return string
126 126 */
127 127 public function column_translations( $item ) {
128 - $languages = array_combine( wp_list_pluck( $this->languages, 'slug' ), wp_list_pluck( $this->languages, 'name' ) );
129 - $out = '';
128 + $out = '';
129 + $languages = array();
130 130
131 + foreach ( $this->languages as $language ) {
132 + $languages[ $language->slug ] = $language->name;
133 + }
134 +
131 135 foreach ( $item['translations'] as $key => $translation ) {
132 136 $input_type = $item['multiline'] ?
133 137 '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' :
134 138 '<input type="text" name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />';
@@ -136,9 +140,9 @@
136 140 '<div class="translation"><label for="%1$s-%2$s">%3$s</label>' . $input_type . '</div>' . "\n",
137 141 esc_attr( $key ),
138 142 esc_attr( $item['row'] ),
139 143 esc_html( $languages[ $key ] ),
140 - format_to_edit( $translation ) // Don't interpret special chars
144 + format_to_edit( $translation ) // Don't interpret special chars.
141 145 );
142 146 }
143 147
144 148 return $out;
@@ -191,16 +195,18 @@
191 195 * Search for a string in translations. Case insensitive.
192 196 *
193 197 * @since 2.6
194 198 *
195 - * @param PLL_MO[] $mos An array of PLL_MO objects.
196 - * @param string $s Searched string.
199 + * @param PLL_Language[] $languages An array of language objects.
200 + * @param string $s Searched string.
197 201 * @return string[] Found strings.
198 202 */
199 - protected function search_in_translations( $mos, $s ) {
203 + protected function search_in_translations( $languages, $s ) {
200 204 $founds = array();
201 205
202 - foreach ( $mos as $mo ) {
206 + foreach ( $languages as $language ) {
207 + $mo = new PLL_MO();
208 + $mo->import_from_db( $language );
203 209 foreach ( wp_list_pluck( $mo->entries, 'translations' ) as $string => $translation ) {
204 210 if ( false !== stripos( $translation[0], $s ) ) {
205 211 $founds[] = $string;
206 212 }
@@ -210,14 +216,14 @@
210 216 return array_unique( $founds );
211 217 }
212 218
213 219 /**
214 - * Sort items
220 + * Sorts registered string items.
215 221 *
216 222 * @since 0.6
217 223 *
218 - * @param object $a The first object to compare
219 - * @param object $b The second object to compare
224 + * @param array $a The first item to compare.
225 + * @param array $b The second item to compare.
220 226 * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b.
221 227 */
222 228 protected function usort_reorder( $a, $b ) {
223 229 if ( ! empty( $_GET['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
@@ -231,9 +237,9 @@
231 237 return 0;
232 238 }
233 239
234 240 /**
235 - * Prepares the list of items for displaying
241 + * Prepares the list of registered strings for display.
236 242 *
237 243 * @since 0.6
238 244 *
239 245 * @return void
@@ -245,15 +251,8 @@
245 251 } else {
246 252 $languages = $this->languages;
247 253 }
248 254
249 - // Load translations
250 - $mo = array();
251 - foreach ( $languages as $language ) {
252 - $mo[ $language->slug ] = new PLL_MO();
253 - $mo[ $language->slug ]->import_from_db( $language );
254 - }
255 -
256 255 $data = $this->strings;
257 256
258 257 // Filter by selected group
259 258 if ( -1 !== $this->selected_group ) {
@@ -264,9 +263,9 @@
264 263 $s = empty( $_GET['s'] ) ? '' : wp_unslash( $_GET['s'] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
265 264
266 265 if ( ! empty( $s ) ) {
267 266 // Search in translations
268 - $in_translations = $this->search_in_translations( $mo, $s );
267 + $in_translations = $this->search_in_translations( $languages, $s );
269 268
270 269 foreach ( $data as $key => $row ) {
271 270 if ( stripos( $row['name'], $s ) === false && stripos( $row['string'], $s ) === false && ! in_array( $row['string'], $in_translations ) ) {
272 271 unset( $data[ $key ] );
@@ -287,9 +286,9 @@
287 286 $this->set_pagination_args(
288 287 array(
289 288 'total_items' => $total_items,
290 289 'per_page' => $per_page,
291 - 'total_pages' => ceil( $total_items / $per_page ),
290 + 'total_pages' => (int) ceil( $total_items / $per_page ),
292 291 )
293 292 );
294 293
295 294 // Translate strings
@@ -294,11 +293,13 @@
294 293
295 294 // Translate strings
296 295 // Kept for the end as it is a slow process
297 296 foreach ( $languages as $language ) {
297 + $mo = new PLL_MO();
298 + $mo->import_from_db( $language );
298 299 foreach ( $this->items as $key => $row ) {
299 - $this->items[ $key ]['translations'][ $language->slug ] = $mo[ $language->slug ]->translate( $row['string'] );
300 - $this->items[ $key ]['row'] = $key; // Store the row number for convenience
300 + $this->items[ $key ]['translations'][ $language->slug ] = $mo->translate_if_any( $row['string'] );
301 + $this->items[ $key ]['row'] = $key; // Store the row number for convenience
301 302 }
302 303 }
303 304 }
304 305
@@ -366,9 +367,9 @@
366 367 }
367 368
368 369 /**
369 370 * Saves the strings translations in DB
370 - * Optionaly clean the DB
371 + * Optionally clean the DB
371 372 *
372 373 * @since 1.9
373 374 *
374 375 * @return void
@@ -381,26 +382,34 @@
381 382 if ( empty( $_POST['translation'][ $language->slug ] ) || ! is_array( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch )
382 383 continue;
383 384 }
384 385
386 + $translations = array_map( 'trim', (array) wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
387 +
385 388 $mo = new PLL_MO();
386 389 $mo->import_from_db( $language );
387 390
388 - $translations = array_map( 'trim', wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
389 391 foreach ( $translations as $key => $translation ) {
390 392 /**
391 - * Filter the string translation before it is saved in DB
392 - * Allows to sanitize strings registered with pll_register_string
393 + * Filters the string translation before it is saved in DB.
394 + * Allows to sanitize strings registered with pll_register_string().
393 395 *
394 396 * @since 1.6
395 397 * @since 2.7 The translation passed to the filter is unslashed.
398 + * @since 3.7 Add original string as 4th parameter.
396 399 *
397 400 * @param string $translation The string translation.
398 401 * @param string $name The name as defined in pll_register_string.
399 402 * @param string $context The context as defined in pll_register_string.
403 + * @param string $original The original string to translate.
400 404 */
401 - $translation = apply_filters( 'pll_sanitize_string_translation', $translation, $this->strings[ $key ]['name'], $this->strings[ $key ]['context'] );
402 - $mo->add_entry( $mo->make_entry( $this->strings[ $key ]['string'], $translation ) );
405 + $translation = apply_filters( 'pll_sanitize_string_translation', $translation, $this->strings[ $key ]['name'], $this->strings[ $key ]['context'], $this->strings[ $key ]['string'] );
406 + $mo->add_entry(
407 + $mo->make_entry(
408 + $this->strings[ $key ]['string'],
409 + $translation
410 + )
411 + );
403 412 }
404 413
405 414 // Clean database ( removes all strings which were registered some day but are no more )
406 415 if ( ! empty( $_POST['clean'] ) ) {
@@ -413,9 +422,9 @@
413 422
414 423 isset( $new_mo ) ? $new_mo->export_to_db( $language ) : $mo->export_to_db( $language );
415 424 }
416 425
417 - add_settings_error( 'general', 'pll_strings_translations_updated', __( 'Translations updated.', 'polylang' ), 'updated' );
426 + pll_add_notice( new WP_Error( 'pll_strings_translations_updated', __( 'Translations updated.', 'polylang' ), 'success' ) );
418 427
419 428 /**
420 429 * Fires after the strings translations are saved in DB
421 430 *