fix: the current translating is always 100
This commit is contained in:
@@ -73,7 +73,7 @@ Before production use, add WordPress PHPUnit integration tests with mocked `wp_r
|
||||
|
||||
The Posts and Pages lists show a status column for every target language, including the latest successful translation time and a translation action. The Settings page also provides **重新翻译所有内容**. It shows a confirmation warning before scheduling a forced refresh of published posts, pages, categories, and tags; this bypasses persisted translations and consumes Baidu API quota.
|
||||
|
||||
The Settings page also shows a live progress panel. It refreshes every five seconds and counts completed post/page and category/tag items for every configured target language. Progress reads only local WordPress and translation-table data; it does not send additional requests to Baidu.
|
||||
The Settings page also shows a live progress panel. It refreshes every five seconds and counts completed post/page and category/tag items for every configured target language. When **重新翻译所有内容** starts a batch, progress resets and counts only translations completed after that batch began, so historical translations do not make a new batch appear complete. Progress reads only local WordPress and translation-table data; it does not send additional requests to Baidu.
|
||||
|
||||
## Known Limitations
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class WPT_Admin {
|
||||
var progress = response.data;
|
||||
container.innerHTML = '<p><strong>' + progress.percent + '%</strong>(' + progress.completed + ' / ' + progress.total + ' 个内容项)</p>' +
|
||||
'<div style="max-width:480px;height:12px;background:#dcdcde"><div style="height:12px;width:' + progress.percent + '%;background:#2271b1"></div></div>' +
|
||||
'<p class="description">文章和页面:' + progress.posts_completed + ' / ' + progress.posts_total + ';分类和标签:' + progress.terms_completed + ' / ' + progress.terms_total + '。每 5 秒自动更新。</p>';
|
||||
'<p class="description">文章和页面:' + progress.posts_completed + ' / ' + progress.posts_total + ';分类和标签:' + progress.terms_completed + ' / ' + progress.terms_total + '。显示最近一次全量重翻批次的进度,每 5 秒自动更新。</p>';
|
||||
})
|
||||
.catch(function () {
|
||||
container.innerHTML = '<p>暂时无法读取翻译进度。</p>';
|
||||
@@ -119,6 +119,14 @@ class WPT_Admin {
|
||||
}
|
||||
|
||||
check_admin_referer( 'wpt_queue_existing_translations' );
|
||||
$batch_started_at = current_time( 'mysql', true );
|
||||
update_option(
|
||||
'wpt_retranslation_batch',
|
||||
array(
|
||||
'started_at' => $batch_started_at,
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
$post_ids = get_posts(
|
||||
array(
|
||||
@@ -184,7 +192,9 @@ class WPT_Admin {
|
||||
);
|
||||
$term_count = is_wp_error( $terms ) ? 0 : count( $terms );
|
||||
$languages = WPT_Settings::target_languages();
|
||||
$counts = ( new WPT_Translation_Store() )->get_completed_item_counts( $languages );
|
||||
$batch = (array) get_option( 'wpt_retranslation_batch', array() );
|
||||
$started_at = isset( $batch['started_at'] ) ? sanitize_text_field( $batch['started_at'] ) : '';
|
||||
$counts = ( new WPT_Translation_Store() )->get_completed_item_counts( $languages, $started_at );
|
||||
|
||||
$posts_total = $post_count * count( $languages );
|
||||
$terms_total = $term_count * count( $languages );
|
||||
@@ -203,6 +213,7 @@ class WPT_Admin {
|
||||
'completed' => $completed,
|
||||
'total' => $total,
|
||||
'percent' => $percent,
|
||||
'batch_started_at' => $started_at,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class WPT_Translation_Store {
|
||||
return $wpdb->get_row( $sql, ARRAY_A );
|
||||
}
|
||||
|
||||
public function get_completed_item_counts( $target_languages ) {
|
||||
public function get_completed_item_counts( $target_languages, $since = '' ) {
|
||||
global $wpdb;
|
||||
|
||||
$target_languages = array_values( array_filter( array_map( 'sanitize_key', (array) $target_languages ) ) );
|
||||
@@ -100,17 +100,22 @@ class WPT_Translation_Store {
|
||||
|
||||
$table_name = self::table_name();
|
||||
$placeholders = implode( ',', array_fill( 0, count( $target_languages ), '%s' ) );
|
||||
$since_clause = '' === $since ? '' : ' AND updated_at >= %s';
|
||||
$query_args = $target_languages;
|
||||
if ( '' !== $since ) {
|
||||
$query_args[] = $since;
|
||||
}
|
||||
$post_sql = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT CONCAT(target_language, '|', SUBSTRING_INDEX(field_context, ':', 2)))
|
||||
FROM {$table_name}
|
||||
WHERE status = 'complete' AND target_language IN ({$placeholders}) AND field_context LIKE 'post:%'",
|
||||
$target_languages
|
||||
WHERE status = 'complete' AND target_language IN ({$placeholders}) AND field_context LIKE 'post:%'{$since_clause}",
|
||||
$query_args
|
||||
);
|
||||
$term_sql = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT CONCAT(target_language, '|', SUBSTRING_INDEX(field_context, ':', 2)))
|
||||
FROM {$table_name}
|
||||
WHERE status = 'complete' AND target_language IN ({$placeholders}) AND field_context LIKE 'term:%'",
|
||||
$target_languages
|
||||
WHERE status = 'complete' AND target_language IN ({$placeholders}) AND field_context LIKE 'term:%'{$since_clause}",
|
||||
$query_args
|
||||
);
|
||||
|
||||
return array(
|
||||
|
||||
Reference in New Issue
Block a user