release: v0.1.1
This commit is contained in:
@@ -27,7 +27,7 @@ jobs:
|
||||
id: package
|
||||
run: |
|
||||
set -eu
|
||||
plugin_slug="wp-translate"
|
||||
plugin_slug="btranslate"
|
||||
version="$(grep -E '^ \* Version:' wp-translate.php | sed -E 's/^ \* Version: *//')"
|
||||
archive_name="${plugin_slug}-${version}.zip"
|
||||
|
||||
@@ -40,14 +40,14 @@ jobs:
|
||||
zip -qr "../${archive_name}" "${plugin_slug}"
|
||||
)
|
||||
|
||||
unzip -p "${archive_name}" "${plugin_slug}/wp-translate.php" | grep -q '^ \* Plugin Name: WP Translate$'
|
||||
unzip -p "${archive_name}" "${plugin_slug}/wp-translate.php" | grep -q '^ \* Plugin Name: Btranslate$'
|
||||
|
||||
printf 'archive=%s\n' "${archive_name}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload plugin archive
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: wp-translate-plugin
|
||||
name: btranslate-plugin
|
||||
path: ${{ steps.package.outputs.archive }}
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# WP Translate
|
||||
# Btranslate
|
||||
|
||||
[中文](README.zh-CN.md)|English
|
||||
|
||||
WP Translate is a WordPress plugin skeleton for persistent multilingual content using the Baidu Translate API.
|
||||
Btranslate is a WordPress plugin skeleton for persistent multilingual content using the Baidu Translate API.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -13,15 +13,15 @@ WP Translate is a WordPress plugin skeleton for persistent multilingual content
|
||||
|
||||
## Installation
|
||||
|
||||
1. Copy this directory to `wp-content/plugins/wp-translate`.
|
||||
2. Activate **WP Translate** in WordPress Admin.
|
||||
3. Open **Settings > WP Translate**.
|
||||
1. Copy this directory to `wp-content/plugins/wp-btranslate`.
|
||||
2. Activate **Btranslate** in WordPress Admin.
|
||||
3. Open **Settings > Btranslate**.
|
||||
4. Enter the Baidu credentials, source language, target-language codes, and URL routing mode.
|
||||
5. Save a post or page to schedule translation jobs for every configured target language.
|
||||
|
||||
## Translation Lifecycle
|
||||
|
||||
Translations are generated by the `wpt_process_translation` cron task after a post or page is saved. For content published before the plugin was activated, open **Settings > WP Translate** and use **Translate existing posts and pages** to schedule all published posts and pages. A translation has a deterministic identity based on the source fingerprint, source language, target language, field context, and provider version. The plugin first looks up a completed result in the `{$wpdb->prefix}wpt_translations` table. Only a cache miss causes a request to Baidu.
|
||||
Translations are generated by the `wpt_process_translation` cron task after a post or page is saved. For content published before the plugin was activated, open **Settings > Btranslate** and use **Translate existing posts and pages** to schedule all published posts and pages. A translation has a deterministic identity based on the source fingerprint, source language, target language, field context, and provider version. The plugin first looks up a completed result in the `{$wpdb->prefix}wpt_translations` table. Only a cache miss causes a request to Baidu.
|
||||
|
||||
Changing source text produces a new fingerprint and therefore schedules a new translation without deleting a valid prior translation. Front-end rendering never contacts Baidu; it reads a completed value from the table and otherwise falls back to the source value. WordPress cron must run after queuing content; production sites should configure a real server cron to call WordPress cron regularly.
|
||||
|
||||
@@ -33,6 +33,7 @@ Changing source text produces a new fingerprint and therefore schedules a new tr
|
||||
- Yoast SEO title and description fields.
|
||||
- Rank Math title and description fields.
|
||||
- All in One SEO and SEOPress title and description output filters.
|
||||
- WordPress AI plugin fallback meta description (`wpai_meta_description`).
|
||||
|
||||
Only the listed SEO meta fields and the generated title/description output from supported SEO plugins are sent for translation. Browser titles generated through the WordPress document-title API use the persisted translated post title. Arbitrary metadata, serialized data, credentials, and code are excluded.
|
||||
|
||||
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
# WP Translate
|
||||
# Btranslate
|
||||
|
||||
中文|[English](README.md)
|
||||
|
||||
WP Translate 是一个 WordPress 插件骨架,使用百度翻译 API 持久化管理多语言内容。
|
||||
Btranslate 是一个 WordPress 插件骨架,使用百度翻译 API 持久化管理多语言内容。
|
||||
|
||||
## 要求
|
||||
|
||||
@@ -13,15 +13,15 @@ WP Translate 是一个 WordPress 插件骨架,使用百度翻译 API 持久化
|
||||
|
||||
## 安装
|
||||
|
||||
1. 将此目录复制到 `wp-content/plugins/wp-translate`。
|
||||
2. 在 WordPress 后台启用 **WP Translate**。
|
||||
3. 打开 **设置 > WP Translate**。
|
||||
1. 将此目录复制到 `wp-content/plugins/wp-btranslate`。
|
||||
2. 在 WordPress 后台启用 **Btranslate**。
|
||||
3. 打开 **设置 > Btranslate**。
|
||||
4. 填写百度翻译凭据、源语言、目标语言代码和 URL 路由模式。
|
||||
5. 保存文章或页面,为每种已配置的目标语言安排翻译任务。
|
||||
|
||||
## 翻译生命周期
|
||||
|
||||
保存文章或页面后,`wpt_process_translation` Cron 任务会生成翻译。对于插件启用前已发布的内容,请打开 **设置 > WP Translate**,使用 **翻译现有文章和页面** 为全部已发布文章和页面安排任务。翻译具有确定性标识,标识由源内容指纹、源语言、目标语言、字段上下文和提供程序版本构成。插件会先在 `{$wpdb->prefix}wpt_translations` 表中查找已完成的结果;只有缓存未命中时才会向百度发起请求。
|
||||
保存文章或页面后,`wpt_process_translation` Cron 任务会生成翻译。对于插件启用前已发布的内容,请打开 **设置 > Btranslate**,使用 **翻译现有文章和页面** 为全部已发布文章和页面安排任务。翻译具有确定性标识,标识由源内容指纹、源语言、目标语言、字段上下文和提供程序版本构成。插件会先在 `{$wpdb->prefix}wpt_translations` 表中查找已完成的结果;只有缓存未命中时才会向百度发起请求。
|
||||
|
||||
源文本变更会生成新的指纹,因此会安排新的翻译任务,而不会删除此前有效的翻译。前端渲染不会请求百度 API;它只读取表中已完成的值,若不存在则回退显示源文本。内容入队后必须运行 WordPress Cron;生产环境应配置真实的服务器 Cron,定期调用 WordPress Cron。
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "wp-translate/wp-translate",
|
||||
"name": "wp-btranslate/wp-btranslate",
|
||||
"description": "Persistent multilingual WordPress translations powered by Baidu Translate.",
|
||||
"type": "wordpress-plugin",
|
||||
"license": "proprietary",
|
||||
|
||||
@@ -17,7 +17,7 @@ class WPT_Admin {
|
||||
}
|
||||
|
||||
public function add_settings_page() {
|
||||
add_options_page( __( 'WP Translate', 'wp-translate' ), __( 'WP Translate', 'wp-translate' ), 'manage_options', 'wp-translate', array( $this, 'render_settings_page' ) );
|
||||
add_options_page( __( 'Btranslate', 'wp-btranslate' ), __( 'Btranslate', 'wp-btranslate' ), 'manage_options', 'wp-btranslate', array( $this, 'render_settings_page' ) );
|
||||
}
|
||||
|
||||
public function register_settings() {
|
||||
@@ -56,7 +56,7 @@ class WPT_Admin {
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>WP Translate</h1>
|
||||
<h1>Btranslate</h1>
|
||||
<form action="options.php" method="post">
|
||||
<?php settings_fields( 'wpt_settings' ); ?>
|
||||
<table class="form-table" role="presentation">
|
||||
@@ -165,12 +165,12 @@ class WPT_Admin {
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect( add_query_arg( 'wpt_queued', $scheduled, admin_url( 'options-general.php?page=wp-translate' ) ) );
|
||||
wp_safe_redirect( add_query_arg( 'wpt_queued', $scheduled, admin_url( 'options-general.php?page=wp-btranslate' ) ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function add_plugin_settings_link( $links ) {
|
||||
array_unshift( $links, '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-translate' ) ) . '">设置</a>' );
|
||||
array_unshift( $links, '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-btranslate' ) ) . '">设置</a>' );
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class WPT_Baidu_Provider implements WPT_Translation_Provider {
|
||||
|
||||
public function translate( $source_value, $source_language, $target_language, $context ) {
|
||||
if ( '' === $this->app_id || '' === $this->secret_key ) {
|
||||
return WPT_Translation_Result::failure( 'missing_credentials', __( 'Baidu Translate credentials are not configured.', 'wp-translate' ) );
|
||||
return WPT_Translation_Result::failure( 'missing_credentials', __( 'Baidu Translate credentials are not configured.', 'wp-btranslate' ) );
|
||||
}
|
||||
|
||||
$salt = (string) wp_rand( 100000, 999999 );
|
||||
@@ -45,7 +45,7 @@ class WPT_Baidu_Provider implements WPT_Translation_Provider {
|
||||
|
||||
if ( ! is_array( $body ) || empty( $body['trans_result'] ) || ! is_array( $body['trans_result'] ) ) {
|
||||
$error_code = isset( $body['error_code'] ) ? sanitize_key( $body['error_code'] ) : 'invalid_response';
|
||||
$error_message = isset( $body['error_msg'] ) ? sanitize_text_field( $body['error_msg'] ) : __( 'Baidu Translate returned an invalid response.', 'wp-translate' );
|
||||
$error_message = isset( $body['error_msg'] ) ? sanitize_text_field( $body['error_msg'] ) : __( 'Baidu Translate returned an invalid response.', 'wp-btranslate' );
|
||||
|
||||
return WPT_Translation_Result::failure( $error_code, $error_message );
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class WPT_Content_Controller {
|
||||
add_filter( 'single_term_title', array( $this, 'translate_term_title' ), 20, 2 );
|
||||
add_filter( 'term_description', array( $this, 'translate_term_description' ), 20, 3 );
|
||||
add_filter( 'document_title_parts', array( $this, 'translate_document_title_parts' ), 20 );
|
||||
add_filter( 'wpai_meta_description', array( $this, 'translate_wordpress_ai_meta_description' ), 20 );
|
||||
add_filter( 'wpseo_title', array( $this, 'translate_seo_title' ), 20 );
|
||||
add_filter( 'wpseo_metadesc', array( $this, 'translate_seo_description' ), 20 );
|
||||
add_filter( 'rank_math/frontend/title', array( $this, 'translate_seo_title' ), 20 );
|
||||
@@ -71,6 +72,7 @@ class WPT_Content_Controller {
|
||||
'post_excerpt' => $post->post_excerpt,
|
||||
);
|
||||
$seo_meta_keys = array(
|
||||
'wpai_meta_description',
|
||||
'_yoast_wpseo_title',
|
||||
'_yoast_wpseo_metadesc',
|
||||
'rank_math_title',
|
||||
@@ -214,6 +216,16 @@ class WPT_Content_Controller {
|
||||
return $parts;
|
||||
}
|
||||
|
||||
public function translate_wordpress_ai_meta_description( $description ) {
|
||||
$post_id = get_queried_object_id();
|
||||
|
||||
if ( ! $post_id || '' === $description ) {
|
||||
return $description;
|
||||
}
|
||||
|
||||
return $this->translated_value( $description, 'post:' . $post_id . ':meta:wpai_meta_description' );
|
||||
}
|
||||
|
||||
public function translate_term_object( $term, $taxonomy, $context = '' ) {
|
||||
if ( ! $term instanceof WP_Term || ! in_array( $term->taxonomy, array( 'category', 'post_tag' ), true ) ) {
|
||||
return $term;
|
||||
|
||||
+5
-5
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: WP Translate
|
||||
* Plugin Name: Btranslate
|
||||
* Description: Persistent multilingual WordPress translations powered by Baidu Translate.
|
||||
* Version: 0.1.0
|
||||
* Version: 0.1.1
|
||||
* Requires at least: 6.4
|
||||
* Requires PHP: 8.1
|
||||
* Author: WP Translate
|
||||
* Text Domain: wp-translate
|
||||
* Author: hanyixuanten
|
||||
* Text Domain: wp-btranslate
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
define( 'WPT_VERSION', '0.1.0' );
|
||||
define( 'WPT_VERSION', '0.1.1' );
|
||||
define( 'WPT_FILE', __FILE__ );
|
||||
define( 'WPT_PATH', plugin_dir_path( __FILE__ ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user