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