| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Displays the translations fields for terms |
| 5 |
*/ |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Don't access directly |
| 9 |
}; |
| 10 |
|
| 11 |
if ( isset( $term_id ) ) { |
| 12 |
// Edit term form ?> |
| 13 |
<th scope="row"><?php esc_html_e( 'Translations', 'polylang' ); ?></th> |
| 14 |
<td> |
| 15 |
<?php |
| 16 |
} |
| 17 |
else { |
| 18 |
// Add term form |
| 19 |
?> |
| 20 |
<p><?php esc_html_e( 'Translations', 'polylang' ); ?></p> |
| 21 |
<?php |
| 22 |
} |
| 23 |
?> |
| 24 |
<table class="widefat term-translations" id="<?php echo isset( $term_id ) ? 'edit' : 'add'; ?>-term-translations"> |
| 25 |
<?php |
| 26 |
foreach ( $this->model->get_languages_list() as $language ) { |
| 27 |
if ( $language->term_id == $lang->term_id ) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
|
| 31 |
// Look for any existing translation in this language |
| 32 |
// Take care not to propose a self link |
| 33 |
$translation = 0; |
| 34 |
if ( isset( $term_id ) && ( $translation_id = $this->model->term->get_translation( $term_id, $language ) ) && $translation_id != $term_id ) { |
| 35 |
$translation = get_term( $translation_id, $taxonomy ); |
| 36 |
} |
| 37 |
if ( ! empty( $from_term_id ) && ( $translation_id = $this->model->term->get( $from_term_id, $language ) ) && ! $this->model->term->get_translation( $translation_id, $lang ) ) { |
| 38 |
$translation = get_term( $translation_id, $taxonomy ); |
| 39 |
} |
| 40 |
|
| 41 |
if ( isset( $term_id ) ) { // Do not display the add new link in add term form ( $term_id not set !!! ) |
| 42 |
$link = $add_link = $this->links->new_term_translation_link( $term_id, $taxonomy, $post_type, $language ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( $translation ) { |
| 46 |
$link = $this->links->edit_term_translation_link( $translation->term_id, $taxonomy, $post_type ); |
| 47 |
} |
| 48 |
?> |
| 49 |
<tr> |
| 50 |
<th class = "pll-language-column"> |
| 51 |
<span class = "pll-translation-flag"><?php echo $language->flag ? $language->flag : esc_html( $language->slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?></span> |
| 52 |
<?php |
| 53 |
printf( |
| 54 |
'<span class="pll-language-name%1$s">%2$s</span>', |
| 55 |
isset( $term_id ) ? '' : ' screen-reader-text', |
| 56 |
esc_html( $language->name ) |
| 57 |
); |
| 58 |
?> |
| 59 |
</th> |
| 60 |
<?php |
| 61 |
if ( isset( $term_id ) ) { |
| 62 |
?> |
| 63 |
<td class = "hidden"><?php echo $add_link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td> |
| 64 |
<td class = "pll-edit-column"><?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput ?></td> |
| 65 |
<?php |
| 66 |
} |
| 67 |
?> |
| 68 |
<td class = "pll-translation-column"> |
| 69 |
<?php |
| 70 |
printf( |
| 71 |
'<label class="screen-reader-text" for="tr_lang_%1$s">%2$s</label> |
| 72 |
<input type="hidden" class="htr_lang" name="term_tr_lang[%1$s]" id="htr_lang_%1$s" value="%3$s" /> |
| 73 |
<span lang="%6$s" dir="%7$s"><input type="text" class="tr_lang" id="tr_lang_%1$s" value="%4$s"%5$s /></span>', |
| 74 |
esc_attr( $language->slug ), |
| 75 |
/* translators: accessibility text */ |
| 76 |
esc_html__( 'Translation', 'polylang' ), |
| 77 |
( empty( $translation ) ? 0 : esc_attr( $translation->term_id ) ), |
| 78 |
( empty( $translation ) ? '' : esc_attr( $translation->name ) ), |
| 79 |
disabled( empty( $disabled ), false, false ), |
| 80 |
esc_attr( $language->get_locale( 'display' ) ), |
| 81 |
( $language->is_rtl ? 'rtl' : 'ltr' ) |
| 82 |
); |
| 83 |
?> |
| 84 |
</td> |
| 85 |
</tr> |
| 86 |
<?php |
| 87 |
} // End foreach |
| 88 |
?> |
| 89 |
</table> |
| 90 |
<?php |
| 91 |
|
| 92 |
if ( isset( $term_id ) ) { |
| 93 |
// Edit term form |
| 94 |
?> |
| 95 |
</td> |
| 96 |
<?php |
| 97 |
} |
| 98 |
|