Skip to content

Commit

Permalink
Merge pull request #74 from pedro-mendonca/dev
Browse files Browse the repository at this point in the history
Add conversion diff highlight
  • Loading branch information
pedro-mendonca authored Oct 10, 2022
2 parents 2e83c3a + ebd436a commit 0b874e2
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 83 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The language conversion uses the open source tool [Convert PT AO90](https://gith
* Convert `current` Portuguese (Portugal) root translations and add to the Portuguese (Portugal, AO90) variant translations.
* Delete variant unused translations instead of keeping as `rejected`, `fuzzy`, `old`.
* Delete `current` variant translation if a new root translation (same `original_id`) is added and doesn't need conversion.
* Highlight the differences in the automatically converted texts.

## Requirements

Expand Down Expand Up @@ -90,6 +91,10 @@ Sure! You are welcome to report any issues or add feature suggestions on the [Gi

## Changelog

### 1.2.0

* Highlight the differences in the automatically converted texts.

### 1.1.1

* Update the actual [Convert-PT-AO90](https://github.com/pedro-mendonca/Convert-PT-AO90) tool to v1.3.1.
Expand Down
6 changes: 6 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Highlight conversion difference. */
.translation-text ins {
background-color: #68de7c;
text-decoration: none;
display: inline-block;
}
10 changes: 10 additions & 0 deletions assets/css/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Intentionally empty file.
*
* It exists to stop directory listings on poorly configured servers.
*
* @package GP_Convert_PT_AO90
*/

// Silence is golden.
10 changes: 10 additions & 0 deletions assets/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Intentionally empty file.
*
* It exists to stop directory listings on poorly configured servers.
*
* @package GP_Convert_PT_AO90
*/

// Silence is golden.
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"phpmd/phpmd": "^2.13.0",
"szepeviktor/phpstan-wordpress": "^1.1.3",
"sirbrillig/phpcs-variable-analysis": "^2.11.9"
"sirbrillig/phpcs-variable-analysis": "^2.11.9",
"pedro-mendonca/glotpress-stubs": "3.0.0-alpha.4"
},
"config": {
"optimize-autoloader": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"autoload": {
"classmap": [
"includes/"
]
},
"scripts": {
"lint": [
"@lint:php",
"@compat:php",
"@lint:phpstan",
"@lint:css",
"@lint:md:docs",
"@lint:pkg-json"
],
Expand All @@ -47,6 +54,7 @@
"compat:php": "phpcs -v --standard=phpcompat.xml",
"lint:phpstan": "phpstan analyse -c phpstan.neon --memory-limit=1G",
"lint:phpmd": "phpmd . text phpmd.xml",
"lint:css": "npm run lint:css",
"lint:md:docs": "npm run lint:md:docs",
"lint:pkg-json": "npm run lint:pkg-json",
"scripts-list": "composer run-script --list"
Expand All @@ -59,6 +67,7 @@
"compat:php": "Runs the PHPCompatibilityWP code sniffer.",
"lint:phpstan": "Runs the PHPStan code static analysis.",
"lint:phpmd": "Runs the PHPMD code static analysis.",
"lint:css": "Run npm CSS linter.",
"lint:md:docs": "Run npm MD linter.",
"lint:pkg-json": "Run npm package.json linter.",
"scripts-list": "List all Composer scripts.",
Expand Down
76 changes: 62 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 7 additions & 41 deletions gp-convert-pt-ao90.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,51 +68,17 @@
define( 'GP_CONVERT_PT_AO90_FILE', plugin_basename( __FILE__ ) );


/**
* Register classes autoloader function.
*
* @since 1.0.0
*
* @param callable(string): void
*/
spl_autoload_register( __NAMESPACE__ . '\gp_convert_pt_ao90_class_autoload' );
// Include Composer autoload.
require_once GP_CONVERT_PT_AO90_DIR_PATH . 'vendor/autoload.php';



/**
* Class autoloader.
*
* @since 1.0.0
*
* @param string $class_name Classe name.
* Initialize the plugin.
*
* @return void
*/
function gp_convert_pt_ao90_class_autoload( $class_name ) {

$project_namespace = __NAMESPACE__ . '\\';

// Check if class is in the project namespace.
if ( 0 !== strncmp( $project_namespace, $class_name, strlen( $project_namespace ) ) ) {
return;
}

// Set class file full path.
$class = sprintf(
'%sincludes/class-%s.php',
GP_CONVERT_PT_AO90_DIR_PATH,
str_replace( '_', '-', strtolower( str_replace( $project_namespace, '', $class_name ) ) )
);

if ( ! is_file( $class ) ) {
return;
}

require_once $class;
function gp_convert_pt_ao90_init() {
Portuguese_AO90::init();
}


// Include Composer autoload.
require_once GP_CONVERT_PT_AO90_DIR_PATH . 'vendor/autoload.php';

// Initialize the plugin.
Portuguese_AO90::init();
add_action( 'plugins_loaded', __NAMESPACE__ . '\gp_convert_pt_ao90_init' );
10 changes: 10 additions & 0 deletions gp-templates/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Intentionally empty file.
*
* It exists to stop directory listings on poorly configured servers.
*
* @package GP_Convert_PT_AO90
*/

// Silence is golden.
88 changes: 88 additions & 0 deletions gp-templates/translation-row-preview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Template for the preview part of a single translation row in a translation set display
*
* @package GlotPress
* @subpackage Templates
*/

$priority_char = array(
'-2' => array( '&times;', 'transparent', '#ccc' ),
'-1' => array( '&darr;', 'transparent', 'blue' ),
'0' => array( '', 'transparent', 'white' ),
'1' => array( '&uarr;', 'transparent', 'green' ),
);

?>

<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 ) : ?>
<th scope="row" class="checkbox"><input type="checkbox" name="selected-row[]"/></th>
<?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
// 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; ?>
</td>
<td class="translation foreign-text">
<?php
if ( $can_edit ) {
$edit_text = __( 'Double-click to add', 'glotpress' );
} 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() ) ) );
}

$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 ) :
$singular_translation = esc_translation( $translation->translations[0] );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$singular_translation = prepare_original( 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">' . $singular_translation . '</span>';
else :
?>
<ul>
<?php foreach ( $translation->translations as $key => $current_translation ) : ?>
<li>
<?php
if ( gp_is_empty_string( $current_translation ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $missing_text;
} else {
$plural_translation = esc_translation( $current_translation );
// Check if has root.
if ( isset( $translation->root_id ) ) {
$plural_translation = prepare_original( GP_Convert_PT_AO90\Portuguese_AO90::highlight_diff( esc_translation( $translation->{ 'root_translation_' . $key } ), esc_translation( $current_translation ) ) );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<span class="translation-text">' . $plural_translation . '</span>';
}
?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</td>
<td class="actions">
<a href="#" class="action edit"><?php _e( 'Details', 'glotpress' ); ?></a>
</td>
</tr>
Loading

0 comments on commit 0b874e2

Please sign in to comment.