Permalink
Browse files

Merge pull request #747 from GlotPress/226-support-locale-variants

226: support locale variants
  • Loading branch information...
toolstack committed Jan 3, 2019
2 parents 4132ed1 + d61e8c0 commit ccdebb9fddc9eebc8e3894817cc52a5a35024e85
@@ -364,6 +364,10 @@ table.translations tr.preview.has-warnings td.original, div#legend div.has-warni
border-left: 2px solid red;
}

table.translations tr.preview.root-translation, #legend .root-translation {
background-color: #EEEEEE;
}

table.translations a.action {
font-size: 100%;
font-style: normal;

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -612,6 +612,10 @@ function gp_get_translation_row_classes( $translation ) {
$classes[] = 'priority-' . gp_array_get( GP::$original->get_static( 'priorities' ), $translation->priority );
$classes[] = $translation->warnings ? 'has-warnings' : 'no-warnings';
if ( property_exists( $translation, 'root_translation_set_id' ) ) {
$classes[] = $translation->translation_set_id === $translation->root_translation_set_id ? 'root-translation' : '';
}
/**
* Filters the list of CSS classes for a translation row
*
@@ -302,7 +302,23 @@ public function for_export( $project, $translation_set, $filters = null ) {
public function for_translation( $project, $translation_set, $page, $filters = array(), $sort = array() ) {
global $wpdb;
$locale = GP_Locales::by_slug( $translation_set->locale );
$locale = GP_Locales::by_slug( $translation_set->locale );
$root_locale = null;
$root_translation_set = null;
$has_root = false;
if ( null !== $locale->variant_root ) {
$root_for_translation = array();
$root_locale = GP_Locales::by_slug( $locale->variant_root );
$root_translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $translation_set->slug, $locale->variant_root );
// Only set the root translation flag if we have a valid root translation set, otherwise there's no point in querying it later.
if ( null !== $root_translation_set && false !== $root_translation_set ) {
$has_root = true;
}
}
$join_type = 'INNER';
@@ -415,8 +431,8 @@ function( $x ) use ( $like ) {
$where[] = 't.translation_0 IS NULL';
}
$join_type = 'LEFT';
$join_on[] = 't.status != "rejected"';
$join_on[] = 't.status != "old"';
$join_on[] = 'status != "rejected"';
$join_on[] = 'status != "old"';
$statuses = array_filter( $statuses, function( $x ) {
return 'untranslated' !== $x ;
} );
@@ -430,7 +446,7 @@ function( $x ) use ( $like ) {
if ( ! empty( $statuses ) ) {
$statuses_where = array();
foreach( $statuses as $single_status ) {
$statuses_where[] = $wpdb->prepare( 't.status = %s', $single_status );
$statuses_where[] = $wpdb->prepare( 'status = %s', $single_status );
}
$statuses_where = '(' . implode( ' OR ', $statuses_where ) . ')';
$join_on[] = $statuses_where;
@@ -469,7 +485,30 @@ function( $x ) use ( $like ) {
'o.date_added as original_added',
);
$join = "$join_type JOIN {$wpdb->gp_translations} AS t ON o.id = t.original_id AND t.translation_set_id = " . (int) $translation_set->id;
if ( $has_root ) {
$fields[] = 'r.id as root_id';
$fields[] = 'r.original_id as root_original_id';
$fields[] = 'r.translation_set_id as root_translation_set_id';
$fields[] = 'r.translation_0 as root_translation_0';
$fields[] = 'r.translation_1 as root_translation_1';
$fields[] = 'r.translation_2 as root_translation_2';
$fields[] = 'r.translation_3 as root_translation_3';
$fields[] = 'r.translation_4 as root_translation_4';
$fields[] = 'r.translation_5 as root_translation_5';
$fields[] = 'r.user_id as root_user_id';
$fields[] = 'r.status as root_status';
$fields[] = 'r.date_added as root_date_added';
$fields[] = 'r.date_modified as root_date_modified';
$fields[] = 'r.warnings as root_warnings';
$fields[] = 'r.user_id_last_modified as root_user_id_last_modified';
}
$join = "$join_type JOIN ( SELECT * FROM {$wpdb->gp_translations} WHERE translation_set_id = " . (int) $translation_set->id . " $join_on ) AS t ON o.id = t.original_id";
$root_join = '';
if ( $has_root ) {
$root_join = "$join_type JOIN ( SELECT * FROM {$wpdb->gp_translations} WHERE translation_set_id = " . (int) $root_translation_set->id . " $join_on ) AS r ON o.id = r.original_id";
}
$orderby = sprintf( $sort_by, $sort_how );
@@ -479,34 +518,37 @@ function( $x ) use ( $like ) {
* Filters the 'for_translation' query SQL clauses.
*
* @since 2.3.0
* @since 2.4.0 Removed $join_on and added $root_join clause. Also added $root_translation_set.
*
* @param array $pieces {
* Translation query SQL clauses.
*
* @type array $fields Fields to select in the query.
* @type string $join JOIN clause of the query.
* @type string $join_on Conditions for the JOIN clause.
* @type string $where WHERE clause of the query.
* @type string $orderby Fields for ORDER BY clause.
* @type string $limit LIMIT clause of the query.
* @type array $fields Fields to select in the query.
* @type string $join JOIN clause of the query.
* @type string $root_join JOIN clause for the root translation set if it exists, otherwise an empty string.
* @type string $where WHERE clause of the query.
* @type string $orderby Fields for ORDER BY clause.
* @type string $limit LIMIT clause of the query.
* }
* @param GP_Translation_Set $translation_set The translation set object being queried.
* @param array $filters An array of search filters.
* @param array $sort An array of sort settings.
* @param GP_Translation_Set $translation_set The translation set object being queried.
* @param array $filters An array of search filters.
* @param array $sort An array of sort settings.
* @param GP_Translation_Set|null $root_translation_set The root translation set object if one exists, otherwise null.
*/
$clauses = apply_filters( 'gp_for_translation_clauses', compact( 'fields', 'join', 'join_on', 'where', 'orderby', 'limit' ), $translation_set, $filters, $sort );
$clauses = apply_filters( 'gp_for_translation_clauses', compact( 'fields', 'join', 'root_join', 'where', 'orderby', 'limit' ), $translation_set, $filters, $sort, $root_translation_set );
$fields = isset( $clauses['fields'] ) ? implode( ', ', $clauses['fields'] ) : '*';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$join_on = isset( $clauses['join_on'] ) ? $clauses['join_on'] : '';
$root_join = isset( $clauses['root_join'] ) ? $clauses['root_join'] : '';
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$orderby = isset( $clauses['orderby'] ) ? 'ORDER BY ' . $clauses['orderby'] : '';
$limit = isset( $clauses['limit'] ) ? $clauses['limit'] : '';
$sql_for_translations = "
SELECT SQL_CALC_FOUND_ROWS $fields
FROM {$wpdb->gp_originals} as o
$join $join_on
$join
$root_join
WHERE $where $orderby $limit";
$rows = $this->many_no_map( $sql_for_translations );
@@ -523,7 +565,28 @@ function( $x ) use ( $like ) {
$this->found_rows = $this->found_rows();
$translations = array();
foreach( (array)$rows as $row ) {
if ( null === $row->id && $has_root ) {
$row->id = $row->root_id;
$row->original_id = $row->root_original_id;
$row->translation_set_id = $row->root_translation_set_id;
$row->translation_0 = $row->root_translation_0;
$row->translation_1 = $row->root_translation_1;
$row->translation_2 = $row->root_translation_2;
$row->translation_3 = $row->root_translation_3;
$row->translation_4 = $row->root_translation_4;
$row->translation_5 = $row->root_translation_5;
$row->user_id = $row->root_user_id;
$row->status = $row->root_status;
$row->date_added = $row->root_date_added;
$row->date_modified = $row->root_date_modified;
$row->warnings = $row->root_warnings;
$row->user_id_last_modified = $row->root_user_id_last_modified;
$row->translation_status = $row->root_status;
$row->translation_added = $row->root_date_added;
}
$row->user = $row->user_last_modified = null;
if ( $row->user_id && 'no-limit' !== $this->per_page ) {
@@ -56,6 +56,32 @@

<?php gp_tmpl_load( 'translation-row-editor-meta-status', get_defined_vars() ); ?>

<?php if ( property_exists( $translation, 'root_translation_set_id' ) ) : ?>
<dl>
<dt><?php _e( 'Root Translation:', 'glotpress' ); // phpcs:ignore WordPress.Security.EscapeOutput. ?></dt>
<?php if ( $translation->translation_set_id === $translation->root_translation_set_id ) : ?>
<dd>
<?php
gp_link(
gp_url_project_locale(
$project,
$root_locale->slug,
$root_translation_set->slug,
array(
'filters[status]' => 'either',
'filters[original_id]' => $translation->original_id,
'filters[translation_id]' => $translation->id,
)
),
$root_translation_set->name_with_locale()
);
?>
</dd>
<?php else : ?>
<dd><?php _e( 'False', 'glotpress' ); // phpcs:ignore WordPress.Security.EscapeOutput. ?></dd>
<?php endif; ?>
</dl>
<?php endif; ?>
<?php if ( $translation->context ) : ?>
<dl>
<dt><?php _e( 'Context:', 'glotpress' ); ?></dt>
@@ -295,21 +295,41 @@
</tr>
</thead>
<?php
if ( $glossary ) {
$glossary_entries = $glossary->get_entries();
$glossary_entries_terms = gp_sort_glossary_entries_terms( $glossary_entries );
}
if ( $glossary ) {
$glossary_entries = $glossary->get_entries();
$glossary_entries_terms = gp_sort_glossary_entries_terms( $glossary_entries );
}
$root_locale = null;
$root_translation_set = null;
$has_root = null;
if ( null !== $locale->variant_root ) {
$root_locale = GP_Locales::by_slug( $locale->variant_root );
$root_translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $translation_set->slug, $locale->variant_root );
// Only set the root tranlsation flag if we have a valid root translation set, otherwise there's no point in querying it later.
if ( null !== $root_translation_set ) {
$has_root = true;
}
}
foreach ( $translations as $translation ) {
$translation->translation_set_id = $translation_set->id;
foreach ( $translations as $translation ) {
if ( ! $translation->translation_set_id ) {
$translation->translation_set_id = $translation_set->id;
}
$can_approve_translation = GP::$permission->current_user_can( 'approve', 'translation', $translation->id, array( 'translation' => $translation ) );
gp_tmpl_load( 'translation-row', get_defined_vars() );
}
?>
<?php if ( ! $translations ) : ?>
<?php
if ( ! $translations ) :
?>
<tr><td colspan="<?php echo $can_approve ? 5 : 4; ?>"><?php _e( 'No translations were found!', 'glotpress' ); ?></td></tr>
<?php endif; ?>
<?php
endif;
?>
</table>
<?php
if ( $can_approve ) {
@@ -321,13 +341,12 @@
<div id="legend" class="secondary clearfix">
<div><strong><?php _e( 'Legend:', 'glotpress' ); ?></strong></div>
<?php
foreach( GP::$translation->get_static( 'statuses' ) as $status ):
if ( 'rejected' == $status ) continue;
foreach ( GP::$translation->get_static( 'statuses' ) as $legend_status ) :
?>
<div class="box status-<?php echo $status; ?>"></div>
<div class="box status-<?php echo esc_attr( $legend_status ); ?>"></div>
<div>
<?php
switch( $status ) {
switch ( $legend_status ) {
case 'current':
_e( 'Current', 'glotpress' );
break;
@@ -340,14 +359,24 @@
case 'old':
_e( 'Old', 'glotpress' );
break;
case 'rejected':
_e( 'Rejected', 'glotpress' );
break;
default:
echo $status;
echo esc_html( $legend_status );
}
?>
</div><?php endforeach; ?>
<div class="box has-warnings"></div>
<div><?php _e( 'With warnings', 'glotpress' ); ?></div>

<?php
if ( $locale->variant_root ) :
?>
<div class="box root-translation"></div>
<div><?php _e( 'Root translation', 'glotpress' ); // phpcs:ignore WordPress.Security.EscapeOutput. ?></div>
<?php
endif
?>
</div>
<p class="clear actionlist secondary">
<?php
Oops, something went wrong.

0 comments on commit ccdebb9

Please sign in to comment.