Skip to content

Commit

Permalink
Add plural and plural forms labels to row previews
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mendonca committed Oct 10, 2022
1 parent 547b273 commit 15dfd03
Showing 1 changed file with 99 additions and 28 deletions.
127 changes: 99 additions & 28 deletions gp-templates/translation-row-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,45 @@
?>

<tr class="preview <?php gp_translation_row_classes( $translation ); ?>" id="preview-<?php echo esc_attr( $translation->row_id ); ?>" row="<?php echo esc_attr( $translation->row_id ); ?>">
<?php if ( $can_approve_translation ) : ?>
<?php
if ( $can_approve_translation ) {
?>
<th scope="row" class="checkbox"><input type="checkbox" name="selected-row[]"/></th>
<?php elseif ( $can_approve ) : ?>
<?php
} elseif ( $can_approve ) {
?>
<th scope="row"></th>
<?php endif; ?>
<?php /* translators: %s: Priority of original */ ?>
<td class="priority" title="<?php echo esc_attr( sprintf( __( 'Priority: %s', 'glotpress' ), gp_array_get( GP::$original->get_static( 'priorities' ), $translation->priority ) ) ); ?>">
<?php
}
?>
<td class="priority" title="<?php echo esc_attr( sprintf( /* translators: %s: Priority of original */ __( 'Priority: %s', 'glotpress' ), gp_array_get( GP::$original->get_static( 'priorities' ), $translation->priority ) ) ); ?>">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $priority_char[ $translation->priority ][0];
?>
</td>
<td class="original">
<span class="original-text"><?php echo prepare_original( $translation_singular ); ?></span>
<?php if ( $translation->context ) : ?>
<?php /* translators: %s: Context of original */ ?>
<span class="context bubble" title="<?php echo esc_attr( sprintf( __( 'Context: %s', 'glotpress' ), $translation->context ) ); ?>"><?php echo esc_html( $translation->context ); ?></span>
<?php endif; ?>
<?php
if ( ! $translation->plural ) {
?>
<span class="original-text"><?php echo prepare_original( $translation_singular ); ?></span>
<?php
} else {
$translation_plural = isset( $translation->plural_glossary_markup ) ? $translation->plural_glossary_markup : prepare_original( esc_translation( $translation->plural ) );
?>
<ul>
<li><small><?php esc_html_e( 'Singular:', 'glotpress' ); ?></small><br><span class="original-text"><?php echo prepare_original( $translation_singular ); ?></span></li>
<li><small><?php esc_html_e( 'Plural:', 'glotpress' ); ?></small><br><span class="original-text"><?php echo prepare_original( $translation_plural ); ?></span></li>
</ul>
<?php
}

if ( $translation->context ) {
?>
<span class="context bubble" title="<?php echo esc_attr( sprintf( /* translators: %s: Context of original */ __( 'Context: %s', 'glotpress' ), $translation->context ) ); ?>"><?php echo esc_html( $translation->context ); ?></span>
<?php
}
?>
</td>
<td class="translation foreign-text">
<?php
Expand All @@ -42,45 +63,95 @@
} elseif ( is_user_logged_in() ) {
$edit_text = __( 'You are not allowed to add a translation.', 'glotpress' );
} else {
/* translators: %s: url */
$edit_text = sprintf( __( 'You <a href="%s">have to log in</a> to add a translation.', 'glotpress' ), esc_url( wp_login_url( gp_url_current() ) ) );
$edit_text = sprintf( /* translators: %s: URL. */ __( 'You <a href="%s">have to log in</a> to add a translation.', 'glotpress' ), esc_url( wp_login_url( gp_url_current() ) ) );
}

$missing_text = "<span class='missing'>$edit_text</span>";
if ( ! count( array_filter( $translation->translations, 'gp_is_not_null' ) ) ) :
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $missing_text;
elseif ( ! $translation->plural ) :
if ( ! count( array_filter( $translation->translations, 'gp_is_not_null' ) ) ) {
echo esc_html( $missing_text );
} elseif ( ! $translation->plural ) {
$singular_translation = esc_translation( $translation->translations[0] );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$singular_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->root_translation_0 ), esc_translation( $translation->translations[0] ) );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<span class="translation-text">' . prepare_original( $singular_translation ) . '</span>';
else :
?>
} elseif ( $translation->plural && 2 === $locale->nplurals && 'n != 1' === $locale->plural_expression ) {
?>
<ul>
<?php foreach ( $translation->translations as $key => $current_translation ) : ?>
<li>
<li>
<small><?php esc_html_e( 'Singular:', 'glotpress' ); ?></small><br>
<?php
if ( gp_is_empty_string( $current_translation ) ) {
if ( ! isset( $translation->translations[0] ) || gp_is_empty_string( $translation->translations[0] ) ) {
echo esc_html( $missing_text );
} else {
$singular_translation = esc_translation( $translation->translations[0] );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$singular_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->root_translation_0 ), esc_translation( $translation->translations[0] ) );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $missing_text;
echo '<span class="translation-text">' . prepare_original( $singular_translation ) . '</span>';
}
?>
</li>
<li>
<small><?php esc_html_e( 'Plural:', 'glotpress' ); ?></small><br>
<?php
if ( ! isset( $translation->translations[1] ) || gp_is_empty_string( $translation->translations[1] ) ) {
echo esc_html( $missing_text );
} else {
$plural_translation = esc_translation( $current_translation );
// Check if has root.
$singular_translation = esc_translation( $translation->translations[1] );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$plural_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->{ 'root_translation_' . $key } ), esc_translation( $current_translation ) );
$singular_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->root_translation_1 ), esc_translation( $translation->translations[1] ) );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<span class="translation-text">' . prepare_original( $plural_translation ) . '</span>';
echo '<span class="translation-text">' . prepare_original( $singular_translation ) . '</span>';
}
?>
</li>
</ul>
<?php
} else {
?>
<ul>
<?php
foreach ( range( 0, $locale->nplurals - 1 ) as $plural_index ) {
$plural_string = implode( ', ', $locale->numbers_for_index( $plural_index ) );
?>
<li>
<small class="with-tooltip" aria-label="<?php /* translators: %s: Plural form. */ printf( esc_attr__( 'This plural form is used for numbers like: %s', 'glotpress' ), esc_attr( $plural_string ) ); ?>">
<?php
printf(
/* translators: %s: Plural form. */
esc_html__( '%s:', 'glotpress' ),
esc_html( $plural_string )
);
?>
</small><br>
<?php
if ( ! isset( $translation->translations[ $plural_index ] ) || gp_is_empty_string( $translation->translations[ $plural_index ] ) ) {
echo esc_html( $missing_text );
} else {
$plural_translation = esc_translation( $translation->translations[ $plural_index ] );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$plural_translation = GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->{ 'root_translation_' . $plural_index } ), esc_translation( $translation->translations[ $plural_index ] ) );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<span class="translation-text">' . prepare_original( $plural_translation ) . '</span>';
}
?>
</li>
<?php endforeach; ?>
<?php
}
?>
</ul>
<?php endif; ?>
<?php
}
?>
</td>
<td class="actions">
<a href="#" class="action edit"><?php _e( 'Details', 'glotpress' ); ?></a>
Expand Down

0 comments on commit 15dfd03

Please sign in to comment.