From 97648d798cab95e5249c7a337ec3a93d0c827e36 Mon Sep 17 00:00:00 2001
From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com>
Date: Wed, 29 Jul 2026 21:38:59 +0800
Subject: [PATCH] rename to HTBD and slug to hyx-translator-for-baidu-translate
---
.github/ISSUE_TEMPLATE/issue-en.yml | 4 +-
.github/ISSUE_TEMPLATE/issue.yml | 4 +-
.github/workflows/package-plugin.yml | 6 +-
AGENTS.md | 4 +-
README.md | 40 +-
README.zh-CN.md | 42 +-
assets/js/{btranslate-admin.js => admin.js} | 24 +-
btranslate.php | 45 --
build.sh | 29 +-
hyx-translator-for-baidu-translate.php | 45 ++
includes/class-admin.php | 445 ++++++++++++++++++
...-provider.php => class-baidu-provider.php} | 18 +-
includes/class-btranslate-admin.php | 445 ------------------
...oller.php => class-content-controller.php} | 66 +--
...lator.php => class-content-translator.php} | 8 +-
...e-router.php => class-language-router.php} | 44 +-
...btranslate-plugin.php => class-plugin.php} | 37 +-
...nslate-settings.php => class-settings.php} | 13 +-
...oller.php => class-sitemap-controller.php} | 18 +-
...ity.php => class-translation-identity.php} | 2 +-
...esult.php => class-translation-result.php} | 2 +-
...vice.php => class-translation-service.php} | 10 +-
...-store.php => class-translation-store.php} | 11 +-
...-uninstaller.php => class-uninstaller.php} | 18 +-
...php => interface-translation-provider.php} | 2 +-
...x-translator-for-baidu-translate-zh_CN.po} | 18 +-
...=> hyx-translator-for-baidu-translate.pot} | 114 ++---
readme-zh_CN.txt | 18 +-
readme.txt | 18 +-
uninstall.php | 8 +-
30 files changed, 804 insertions(+), 754 deletions(-)
rename assets/js/{btranslate-admin.js => admin.js} (69%)
delete mode 100644 btranslate.php
create mode 100644 hyx-translator-for-baidu-translate.php
create mode 100644 includes/class-admin.php
rename includes/{class-btranslate-baidu-provider.php => class-baidu-provider.php} (76%)
delete mode 100644 includes/class-btranslate-admin.php
rename includes/{class-btranslate-content-controller.php => class-content-controller.php} (80%)
rename includes/{class-btranslate-content-translator.php => class-content-translator.php} (81%)
rename includes/{class-btranslate-language-router.php => class-language-router.php} (73%)
rename includes/{class-btranslate-plugin.php => class-plugin.php} (55%)
rename includes/{class-btranslate-settings.php => class-settings.php} (80%)
rename includes/{class-btranslate-sitemap-controller.php => class-sitemap-controller.php} (87%)
rename includes/{class-btranslate-translation-identity.php => class-translation-identity.php} (92%)
rename includes/{class-btranslate-translation-result.php => class-translation-result.php} (93%)
rename includes/{class-btranslate-translation-service.php => class-translation-service.php} (65%)
rename includes/{class-btranslate-translation-store.php => class-translation-store.php} (87%)
rename includes/{class-btranslate-uninstaller.php => class-uninstaller.php} (68%)
rename includes/{interface-btranslate-translation-provider.php => interface-translation-provider.php} (78%)
rename languages/{btranslate-zh_CN.po => hyx-translator-for-baidu-translate-zh_CN.po} (87%)
rename languages/{btranslate.pot => hyx-translator-for-baidu-translate.pot} (59%)
diff --git a/.github/ISSUE_TEMPLATE/issue-en.yml b/.github/ISSUE_TEMPLATE/issue-en.yml
index de4a7e9..7880b3e 100644
--- a/.github/ISSUE_TEMPLATE/issue-en.yml
+++ b/.github/ISSUE_TEMPLATE/issue-en.yml
@@ -1,5 +1,5 @@
name: Bug Report and Feature Request
-description: Report a Btranslate issue or suggest a feature or documentation improvement
+description: Report a HTBD issue or suggest a feature or documentation improvement
title: "[Issue]: "
body:
- type: markdown
@@ -32,7 +32,7 @@ body:
- type: input
id: plugin-version
attributes:
- label: Btranslate version
+ label: HTBD version
placeholder: "For example: 0.2.2"
validations:
required: true
diff --git a/.github/ISSUE_TEMPLATE/issue.yml b/.github/ISSUE_TEMPLATE/issue.yml
index 31b9a6c..d0777d2 100644
--- a/.github/ISSUE_TEMPLATE/issue.yml
+++ b/.github/ISSUE_TEMPLATE/issue.yml
@@ -1,5 +1,5 @@
name: 问题反馈与功能建议
-description: 反馈 Btranslate 的问题,或提出功能和文档改进建议
+description: 反馈 HTBD 的问题,或提出功能和文档改进建议
title: "[Issue]: "
body:
- type: markdown
@@ -32,7 +32,7 @@ body:
- type: input
id: plugin-version
attributes:
- label: Btranslate 版本
+ label: HTBD 版本
placeholder: 例如:0.2.2
validations:
required: true
diff --git a/.github/workflows/package-plugin.yml b/.github/workflows/package-plugin.yml
index 6447e2b..bd15887 100644
--- a/.github/workflows/package-plugin.yml
+++ b/.github/workflows/package-plugin.yml
@@ -30,15 +30,15 @@ jobs:
id: package
run: |
set -eu
- version="$(grep -E '^ \* Version:' btranslate.php | sed -E 's/^ \* Version: *//')"
- archive_name="btranslate-${version}.zip"
+ version="$(grep -E '^ \* Version:' hyx-translator-for-baidu-translate.php | sed -E 's/^ \* Version: *//')"
+ archive_name="hyx-translator-for-baidu-translate-${version}.zip"
./build.sh build
printf 'archive=%s\n' "${archive_name}" >> "$GITHUB_OUTPUT"
- name: Upload plugin archive
uses: actions/upload-artifact@v4
with:
- name: btranslate-plugin
+ name: hyx-translator-for-baidu-translate-plugin
path: ${{ steps.package.outputs.archive }}
if-no-files-found: error
retention-days: 30
diff --git a/AGENTS.md b/AGENTS.md
index 9d00d5f..979e9df 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,4 +1,4 @@
-# btranslate Agent Guide
+# hyx-translator-for-baidu-translate Agent Guide
## Project Scope
@@ -45,6 +45,6 @@ Unless a user explicitly requests a refresh, each translatable value must be tra
- Mock Baidu API calls in every test. Tests must not require live credentials or outbound network access.
- Keep changes narrow and avoid unrelated refactors or formatting churn.
- After every file change, review `.github/workflows/package-plugin.yml` and ensure the automated packaging Action includes all runtime files required by the change. Validate the packaging commands locally when practical.
-- Plugin slug and PHP prefix: `btranslate` and `btranslate_`/`BTRANSLATE_`. The current minimum supported PHP version is 8.1 and the current minimum WordPress version is 6.4.
+- Plugin slug and PHP prefix: `hyx-translator-for-baidu-translate` and `htbd_`/`HTBD_`. The custom translation table is `{$wpdb->prefix}hyx_bd_translations`. The current minimum supported PHP version is 8.1 and the current minimum WordPress version is 6.4.
- The repository has no Composer-managed development dependencies or bundled automated test suite. Validate PHP syntax with `find . -path './.git' -prune -o -type f -name '*.php' -print0 | xargs -0 -n1 php -l`. Any future automated tests must mock WordPress API calls and must not require live credentials, external network access, or a WordPress database.
- Document supported languages, routing modes, data retention, translation lifecycle, and known limitations in the README whenever the implementation changes.
diff --git a/README.md b/README.md
index 39a3068..f783abf 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,21 @@
-# Btranslate: A Free and Open-Source WordPress Multilingual Plugin Powered by the Baidu Translate API
+# HTBD: A Free and Open-Source WordPress Multilingual Plugin Powered by the Baidu Translate API
-BTranslate is a multilingual translation plugin for WordPress. It uses the Baidu Translate API to translate posts, pages, and other website content into different languages, with a dedicated URL for each translated version.
+HTBD is a multilingual translation plugin for WordPress. It uses the Baidu Translate API to translate posts, pages, and other website content into different languages, with a dedicated URL for each translated version.
-Translations are stored on the server. Unless a user explicitly refreshes a translation, the same content is translated only once for each target language. This avoids calling the translation API on every page visit, reducing API usage and improving page load performance.
+Translations are stored on the server in `{$wpdb->prefix}hyx_bd_translations`. Unless a user explicitly refreshes a translation, the same content is translated only once for each target language. Existing `{$wpdb->prefix}btranslate_translations` data is migrated when the renamed plugin is activated. This avoids calling the translation API on every page visit, reducing API usage and improving page load performance.
## Project Links
-- GitHub repository: [https://github.com/hanyixuanten/btranslate](https://github.com/hanyixuanten/btranslate)
-- WordPress plugin page: [https://wordpress.org/plugins/btranslate/](https://wordpress.org/plugins/btranslate/)
+- GitHub repository: [https://github.com/hanyixuanten/HTBD](https://github.com/hanyixuanten/HTBD)
+- WordPress plugin page: [https://wordpress.org/plugins/hyx-translator-for-baidu-translate/](https://wordpress.org/plugins/hyx-translator-for-baidu-translate/)
-> **Review status:** BTranslate has not yet been approved for the WordPress.org Plugin Directory, so it cannot currently be installed directly from the WordPress admin plugin marketplace. For now, download it from GitHub and install it manually.
+> **Review status:** HTBD has not yet been approved for the WordPress.org Plugin Directory, so it cannot currently be installed directly from the WordPress admin plugin marketplace. For now, download it from GitHub and install it manually.
## Key Features
### Baidu Translate API Integration
-BTranslate uses the translation API provided by the Baidu Translate Open Platform. Users can configure their own App ID and secret key in WordPress Admin, and the plugin handles request signing, API calls, and error handling.
+HTBD uses the translation API provided by the Baidu Translate Open Platform. Users can configure their own App ID and secret key in WordPress Admin, and the plugin handles request signing, API calls, and error handling.
### Post and Page Translation
@@ -32,7 +32,7 @@ The plugin supports translating the main content of WordPress posts and pages, i
### Multilingual URLs
-BTranslate can generate dedicated URLs for different languages, with support for:
+HTBD can generate dedicated URLs for different languages, with support for:
- Language subdirectories such as `/en/` and `/ja/`
- A separate domain for each language
@@ -57,7 +57,7 @@ When translating content, the plugin makes every effort to preserve:
### Multilingual SEO
-BTranslate provides essential SEO support for multilingual pages, including:
+HTBD provides essential SEO support for multilingual pages, including:
- Multilingual permalinks
- Canonical URLs
@@ -93,29 +93,29 @@ Because the plugin has not yet been approved for the WordPress.org Plugin Direct
#### Method 1: Upload the ZIP Package
-1. Visit the [BTranslate GitHub repository](https://github.com/hanyixuanten/btranslate).
+1. Visit the [HTBD GitHub repository](https://github.com/hanyixuanten/HTBD).
2. Select **Releases**.
-3. Download the **btranslate-*.zip** file from the latest release.
+3. Download the **hyx-translator-for-baidu-translate-*.zip** file from the latest release.
4. Sign in to WordPress Admin.
5. Open **Plugins > Add New Plugin**.
6. Select **Upload Plugin**.
7. Choose the downloaded ZIP file and start the installation.
-8. Activate BTranslate after installation is complete.
+8. Activate HTBD after installation is complete.
#### Method 2: Upload to the Server
-1. Visit the [BTranslate GitHub repository](https://github.com/hanyixuanten/btranslate).
+1. Visit the [HTBD GitHub repository](https://github.com/hanyixuanten/HTBD).
2. Select **Releases**.
-3. Download the **btranslate-*.zip** file from the latest release.
-4. Upload the `btranslate` directory to the WordPress plugin directory: `wp-content/plugins/btranslate/`.
+3. Download the **hyx-translator-for-baidu-translate-*.zip** file from the latest release.
+4. Upload the `hyx-translator-for-baidu-translate` directory to the WordPress plugin directory: `wp-content/plugins/hyx-translator-for-baidu-translate/`.
5. Sign in to WordPress Admin.
6. Open **Plugins > Installed Plugins**.
-7. Find BTranslate and select **Activate**.
+7. Find HTBD and select **Activate**.
### 3. Configure the Plugin
1. Sign in to WordPress Admin.
-2. Open the BTranslate settings page.
+2. Open the HTBD settings page.
3. Enter the **APP ID** and **secret key** provided by the Baidu Translate Open Platform.
4. Set the website's source language.
5. Add the target languages you want to enable.
@@ -128,7 +128,7 @@ After changing language routing settings, open **Settings > Permalinks** in Word
1. Open the post or page you want to translate in WordPress Admin.
2. Save or update the content.
-3. Use the translation feature provided by BTranslate to generate translations for the target languages.
+3. Use the translation feature provided by HTBD to generate translations for the target languages.
4. Wait for the translation tasks to finish.
5. Check each translation at its language-specific URL.
@@ -173,13 +173,13 @@ The plugin prioritizes saved translations. It calls the translation API again on
To report a problem or suggest a feature, visit the GitHub repository:
-[https://github.com/hanyixuanten/btranslate](https://github.com/hanyixuanten/btranslate)
+[https://github.com/hanyixuanten/HTBD](https://github.com/hanyixuanten/HTBD)
When opening an issue, consider including the following information:
- WordPress version
- PHP version
-- BTranslate version
+- HTBD version
- Languages and routing mode in use
- Steps to reproduce the problem
- Error logs with sensitive information removed
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 0230284..fd1a283 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -1,21 +1,21 @@
-# Btranslate:基于百度翻译 API 的免费开源 Wordpress 多语言插件
+# HTBD:基于百度翻译 API 的免费开源 Wordpress 多语言插件
-BTranslate 是一款 WordPress 多语言翻译插件,通过百度翻译开放平台 API,将网站中的文章、页面及其他内容翻译为不同语言,并为译文生成独立的语言访问地址。
+HTBD 是一款 WordPress 多语言翻译插件,通过百度翻译开放平台 API,将网站中的文章、页面及其他内容翻译为不同语言,并为译文生成独立的语言访问地址。
-插件会将翻译结果保存在服务器中。除非用户主动刷新翻译,否则同一内容在同一目标语言下只需翻译一次,无需在每次访问页面时重复调用翻译 API,有助于减少 API 请求量并提高页面加载速度。
+插件会将翻译结果保存在服务器的 `{$wpdb->prefix}hyx_bd_translations` 表中。除非用户主动刷新翻译,否则同一内容在同一目标语言下只需翻译一次。启用改名后的插件时,已有 `{$wpdb->prefix}btranslate_translations` 数据会自动迁移,无需在每次访问页面时重复调用翻译 API,有助于减少 API 请求量并提高页面加载速度。
## 项目地址
-- GitHub 仓库:[https://github.com/hanyixuanten/btranslate](https://github.com/hanyixuanten/btranslate)
-- WordPress 插件主页:[https://wordpress.org/plugins/btranslate/](https://wordpress.org/plugins/btranslate/)
+- GitHub 仓库:[https://github.com/hanyixuanten/HTBD](https://github.com/hanyixuanten/HTBD)
+- WordPress 插件主页:[https://wordpress.org/plugins/hyx-translator-for-baidu-translate/](https://wordpress.org/plugins/hyx-translator-for-baidu-translate/)
-> **审核状态:** BTranslate 目前尚未通过 WordPress.org 插件目录审核,因此暂时无法直接通过 WordPress 后台插件市场安装。现阶段请从 GitHub 仓库下载并手动安装。
+> **审核状态:** HTBD 目前尚未通过 WordPress.org 插件目录审核,因此暂时无法直接通过 WordPress 后台插件市场安装。现阶段请从 GitHub 仓库下载并手动安装。
## 主要功能
### 百度翻译 API 集成
-BTranslate 使用百度翻译开放平台提供的翻译 API。用户可以在 WordPress 后台配置自己的 App ID 和密钥,由插件完成请求签名、翻译调用及错误处理。
+HTBD 使用百度翻译开放平台提供的翻译 API。用户可以在 WordPress 后台配置自己的 App ID 和密钥,由插件完成请求签名、翻译调用及错误处理。
### 文章和页面翻译
@@ -32,7 +32,7 @@ BTranslate 使用百度翻译开放平台提供的翻译 API。用户可以在 W
### 多语言访问地址
-BTranslate 可以为不同语言生成独立的访问地址,支持:
+HTBD 可以为不同语言生成独立的访问地址,支持:
- 语言子目录,例如 `/en/`、`/ja/`
- 不同语言绑定不同域名
@@ -57,7 +57,7 @@ BTranslate 可以为不同语言生成独立的访问地址,支持:
### 多语言 SEO
-BTranslate 为多语言页面提供必要的 SEO 支持,包括:
+HTBD 为多语言页面提供必要的 SEO 支持,包括:
- 多语言固定链接
- Canonical URL
@@ -93,29 +93,29 @@ BTranslate 为多语言页面提供必要的 SEO 支持,包括:
#### 方法一:上传 ZIP 压缩包
-1. 访问 [BTranslate GitHub 仓库](https://github.com/hanyixuanten/btranslate)。
+1. 访问 [HTBD GitHub 仓库](https://github.com/hanyixuanten/HTBD)。
2. 点击 **Releases**。
-3. 从最新版本下载 zip 文件 **btranslate-*.zip**
+3. 从最新版本下载 zip 文件 **hyx-translator-for-baidu-translate-*.zip**
4. 登录 WordPress 管理后台。
5. 打开“插件” → “安装插件”。
6. 点击“上传插件”。
7. 选择下载的 ZIP 文件并开始安装。
-8. 安装完成后启用 BTranslate。
+8. 安装完成后启用 HTBD。
#### 方法二:上传到服务器
-1. 访问 [BTranslate GitHub 仓库](https://github.com/hanyixuanten/btranslate)。
+1. 访问 [HTBD GitHub 仓库](https://github.com/hanyixuanten/HTBD)。
2. 点击 **Releases**。
-3. 从最新版本下载 zip 文件 **btranslate-*.zip**
-4. 将 `btranslate` 目录上传到 WordPress 的插件目录: `wp-content/plugins/btranslate/`
+3. 从最新版本下载 zip 文件 **hyx-translator-for-baidu-translate-*.zip**
+4. 将 `hyx-translator-for-baidu-translate` 目录上传到 WordPress 的插件目录: `wp-content/plugins/hyx-translator-for-baidu-translate/`
5. 登录 WordPress 管理后台。
6. 打开“插件” → “已安装插件”。
-7. 找到 BTranslate 并点击“启用”。
+7. 找到 HTBD 并点击“启用”。
### 三、配置插件
1. 登录 WordPress 管理后台。
-2. 打开 BTranslate 设置页面。
+2. 打开 HTBD 设置页面。
3. 填写百度翻译开放平台提供的 **APP ID** 和 **密钥**。
4. 设置网站的源语言。
5. 添加需要启用的目标语言。
@@ -128,7 +128,7 @@ BTranslate 为多语言页面提供必要的 SEO 支持,包括:
1. 在 WordPress 后台打开需要翻译的文章或页面。
2. 保存或更新内容。
-3. 使用 BTranslate 提供的翻译功能生成目标语言译文。
+3. 使用 HTBD 提供的翻译功能生成目标语言译文。
4. 等待翻译任务完成。
5. 通过对应语言的访问地址检查译文。
@@ -173,15 +173,15 @@ https://example.com/ja/about/
如果在使用过程中遇到问题,或者希望提交功能建议,可以前往 GitHub 仓库反馈:
-[https://github.com/hanyixuanten/btranslate](https://github.com/hanyixuanten/btranslate)
+[https://github.com/hanyixuanten/HTBD](https://github.com/hanyixuanten/HTBD)
提交问题时,建议提供以下信息:
- WordPress 版本
- PHP 版本
-- BTranslate 版本
+- HTBD 版本
- 使用的语言和路由模式
- 问题复现步骤
- 已隐藏敏感信息的错误日志
-欢迎通过 Issue 或 Pull Request 参与 BTranslate 的改进。
+欢迎通过 Issue 或 Pull Request 参与 HTBD 的改进。
diff --git a/assets/js/btranslate-admin.js b/assets/js/admin.js
similarity index 69%
rename from assets/js/btranslate-admin.js
rename to assets/js/admin.js
index 14e88df..ad6735c 100644
--- a/assets/js/btranslate-admin.js
+++ b/assets/js/admin.js
@@ -1,8 +1,8 @@
(function () {
'use strict';
- var domainMode = document.querySelector('#btranslate-routing-mode input[value="domain"]');
- var bindingsRow = document.getElementById('btranslate-domain-bindings-row');
+ var domainMode = document.querySelector('#htbd-routing-mode input[value="domain"]');
+ var bindingsRow = document.getElementById('htbd-domain-bindings-row');
if (domainMode && bindingsRow) {
domainMode.addEventListener('change', function () {
@@ -10,16 +10,16 @@
});
}
- document.querySelectorAll('form[data-btranslate-confirm]').forEach(function (form) {
+ document.querySelectorAll('form[data-htbd-confirm]').forEach(function (form) {
form.addEventListener('submit', function (event) {
- if (!window.confirm(form.getAttribute('data-btranslate-confirm'))) {
+ if (!window.confirm(form.getAttribute('data-htbd-confirm'))) {
event.preventDefault();
}
});
});
- var container = document.getElementById('btranslate-translation-progress');
- if (!container || typeof btranslateAdmin === 'undefined') {
+ var container = document.getElementById('htbd-translation-progress');
+ if (!container || typeof htbdAdmin === 'undefined') {
return;
}
@@ -38,7 +38,7 @@
var percent = document.createElement('strong');
percent.textContent = progress.percent + '%';
summary.appendChild(percent);
- appendText(summary, ' ' + format(btranslateAdmin.i18n.contentItems, [progress.completed, progress.total]));
+ appendText(summary, ' ' + format(htbdAdmin.i18n.contentItems, [progress.completed, progress.total]));
var progressBar = document.createElement('div');
progressBar.style.cssText = 'max-width:480px;height:12px;background:#dcdcde';
@@ -49,12 +49,12 @@
var description = document.createElement('p');
description.className = 'description';
- description.textContent = format(btranslateAdmin.i18n.latestTask, [progress.task_label, progress.posts_completed, progress.posts_total, progress.terms_completed, progress.terms_total]);
+ description.textContent = format(htbdAdmin.i18n.latestTask, [progress.task_label, progress.posts_completed, progress.posts_total, progress.terms_completed, progress.terms_total]);
var children = [summary, progressBar, description];
if (progress.failed_items.length) {
var failedHeading = document.createElement('h3');
- failedHeading.textContent = btranslateAdmin.i18n.failedItems;
+ failedHeading.textContent = htbdAdmin.i18n.failedItems;
children.push(failedHeading);
var failedList = document.createElement('ul');
@@ -65,7 +65,7 @@
var retryLink = document.createElement('a');
retryLink.className = 'button button-small';
retryLink.href = item.retry_url;
- retryLink.textContent = btranslateAdmin.i18n.retranslate;
+ retryLink.textContent = htbdAdmin.i18n.retranslate;
failedItem.appendChild(retryLink);
failedList.appendChild(failedItem);
});
@@ -77,12 +77,12 @@
function renderProgressError() {
var message = document.createElement('p');
- message.textContent = btranslateAdmin.i18n.progressError;
+ message.textContent = htbdAdmin.i18n.progressError;
container.replaceChildren(message);
}
function updateProgress() {
- var url = btranslateAdmin.progressUrl + '?action=btranslate_translation_progress&_ajax_nonce=' + encodeURIComponent(btranslateAdmin.progressNonce);
+ var url = htbdAdmin.progressUrl + '?action=htbd_translation_progress&_ajax_nonce=' + encodeURIComponent(htbdAdmin.progressNonce);
window.fetch(url, { credentials: 'same-origin' })
.then(function (response) {
diff --git a/btranslate.php b/btranslate.php
deleted file mode 100644
index 0a1b685..0000000
--- a/btranslate.php
+++ /dev/null
@@ -1,45 +0,0 @@
-&2
+ exit 1
+ fi
+ if unzip -Z1 "${archive_path}" | grep -Eq '/(interface-btranslate-translation-provider\.php|btranslate-admin\.js)$'; then
+ printf 'Unexpected legacy runtime filename found in archive.\n' >&2
+ exit 1
+ fi
+ if grep -R -q 'BTRANSLATE' "${plugin_dir}" --include='*.php'; then
+ printf 'Unexpected legacy PHP prefix found in archive.\n' >&2
+ exit 1
+ fi
if unzip -Z1 "${archive_path}" | grep -Eq '/README(\.zh-CN)?\.md$'; then
printf 'Unexpected development README found in archive.\n' >&2
exit 1
diff --git a/hyx-translator-for-baidu-translate.php b/hyx-translator-for-baidu-translate.php
new file mode 100644
index 0000000..a95194f
--- /dev/null
+++ b/hyx-translator-for-baidu-translate.php
@@ -0,0 +1,45 @@
+ admin_url( 'admin-ajax.php' ),
+ 'progressNonce' => wp_create_nonce( 'htbd_translation_progress' ),
+ 'i18n' => array(
+ 'contentItems' => __( '(%1$s / %2$s content items)', 'hyx-translator-for-baidu-translate' ),
+ 'latestTask' => __( 'Latest task: %1$s. Posts and pages: %2$s / %3$s; categories and tags: %4$s / %5$s. Updates automatically every 5 seconds.', 'hyx-translator-for-baidu-translate' ),
+ 'failedItems' => __( 'Failed translations', 'hyx-translator-for-baidu-translate' ),
+ 'retranslate' => __( 'Retranslate', 'hyx-translator-for-baidu-translate' ),
+ 'progressError' => __( 'Unable to load translation progress at this time.', 'hyx-translator-for-baidu-translate' ),
+ ),
+ )
+ );
+ }
+
+ public function sanitize_settings( $settings ) {
+ $settings = (array) $settings;
+ $bindings = array();
+ $routing_modes = HTBD_Settings::routing_modes( $settings['routing_mode'] ?? array() );
+ $target_languages = array_values( array_filter( array_map( 'sanitize_key', explode( ',', (string) ( $settings['target_languages'] ?? 'en' ) ) ) ) );
+
+ foreach ( preg_split( '/\r\n|\r|\n/', (string) ( $settings['domain_bindings'] ?? '' ) ) as $line ) {
+ $parts = array_map( 'trim', explode( '=', $line, 2 ) );
+ $domain = 2 === count( $parts ) ? HTBD_Settings::normalize_domain( $parts[0] ) : '';
+ $language = 2 === count( $parts ) ? sanitize_key( $parts[1] ) : '';
+ if ( '' !== $domain && in_array( $language, $target_languages, true ) && ! in_array( $language, $bindings, true ) ) {
+ $bindings[ $domain ] = $language;
+ }
+ }
+
+ return array(
+ 'source_language' => sanitize_key( $settings['source_language'] ?? 'zh' ),
+ 'target_languages' => $target_languages,
+ 'routing_mode' => $routing_modes,
+ 'domain_bindings' => $bindings,
+ 'fallback_language' => sanitize_key( $settings['fallback_language'] ?? 'zh' ),
+ 'baidu_app_id' => sanitize_text_field( $settings['baidu_app_id'] ?? '' ),
+ 'baidu_secret_key' => sanitize_text_field( $settings['baidu_secret_key'] ?? '' ),
+ 'log_requests' => ! empty( $settings['log_requests'] ),
+ );
+ }
+
+ public function render_settings_page() {
+ $settings = HTBD_Settings::get();
+ $bindings = array();
+ foreach ( (array) $settings['domain_bindings'] as $domain => $language ) {
+ $bindings[] = $domain . '=' . $language;
+ }
+ ?>
+
+
HTBD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ array( 'post', 'page' ),
+ 'post_status' => 'publish',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ )
+ );
+
+ }
+
+ if ( 'all' === $scope || 'terms' === $scope ) {
+ $term_ids = get_terms(
+ array(
+ 'taxonomy' => array( 'category', 'post_tag' ),
+ 'hide_empty' => false,
+ 'fields' => 'ids',
+ )
+ );
+ if ( is_wp_error( $term_ids ) ) {
+ $term_ids = array();
+ }
+ }
+
+ $this->update_translation_task( $post_ids, $term_ids, $languages );
+
+ foreach ( $post_ids as $post_id ) {
+ foreach ( $languages as $target_language ) {
+ $this->clear_scheduled_event( 'htbd_process_translation', array( $post_id, $target_language, true ) );
+ wp_schedule_single_event( $next_run, 'htbd_process_translation', array( $post_id, $target_language, true ) );
+ $next_run += 2;
+ ++$scheduled;
+ }
+ }
+
+ foreach ( $term_ids as $term_id ) {
+ foreach ( $languages as $target_language ) {
+ $this->clear_scheduled_event( 'htbd_process_term_translation', array( $term_id, $target_language, true ) );
+ wp_schedule_single_event( $next_run, 'htbd_process_term_translation', array( $term_id, $target_language, true ) );
+ $next_run += 2;
+ ++$scheduled;
+ }
+ }
+
+ wp_safe_redirect( add_query_arg( 'htbd_queued', $scheduled, admin_url( 'options-general.php?page=htbd' ) ) );
+ exit;
+ }
+
+ public function clear_translation_cache() {
+ if ( ! current_user_can( 'manage_options' ) ) {
+ wp_die( esc_html__( 'You do not have permission to perform this action.', 'hyx-translator-for-baidu-translate' ) );
+ }
+
+ check_admin_referer( 'htbd_clear_translation_cache' );
+ $deleted = ( new HTBD_Translation_Store() )->clear();
+
+ if ( false === $deleted ) {
+ wp_die( esc_html__( 'Failed to clear the translation cache.', 'hyx-translator-for-baidu-translate' ) );
+ }
+
+ wp_clear_scheduled_hook( 'htbd_process_translation' );
+ wp_clear_scheduled_hook( 'htbd_process_term_translation' );
+ wp_clear_scheduled_hook( 'htbd_process_seo_output_translation' );
+ delete_option( 'htbd_translation_task' );
+ delete_option( 'htbd_retranslation_batch' );
+
+ wp_safe_redirect( add_query_arg( 'htbd_cache_cleared', 1, admin_url( 'options-general.php?page=htbd' ) ) );
+ exit;
+ }
+
+ private function clear_scheduled_event( $hook, $args ) {
+ while ( false !== ( $timestamp = wp_next_scheduled( $hook, $args ) ) ) {
+ wp_unschedule_event( $timestamp, $hook, $args );
+ }
+ }
+
+ public function add_plugin_settings_link( $links ) {
+ array_unshift( $links, '' . esc_html__( 'Settings', 'hyx-translator-for-baidu-translate' ) . '' );
+
+ return $links;
+ }
+
+ public function translation_progress() {
+ check_ajax_referer( 'htbd_translation_progress' );
+
+ if ( ! current_user_can( 'manage_options' ) ) {
+ wp_send_json_error( array( 'message' => 'forbidden' ), 403 );
+ }
+
+ $task = (array) get_option( 'htbd_translation_task', array() );
+ $post_ids = array_values( array_filter( array_map( 'absint', (array) ( $task['post_ids'] ?? array() ) ) ) );
+ $term_ids = array_values( array_filter( array_map( 'absint', (array) ( $task['term_ids'] ?? array() ) ) ) );
+ $languages = array_values( array_filter( array_map( 'sanitize_key', (array) ( $task['target_languages'] ?? array() ) ) ) );
+ $started_at = isset( $task['started_at'] ) ? sanitize_text_field( $task['started_at'] ) : '';
+ $store = new HTBD_Translation_Store();
+ $counts = $store->get_completed_item_counts( $languages, $post_ids, $term_ids, $started_at );
+ $failures = $this->prepare_failed_items( $store->get_failed_items( $languages, $post_ids, $term_ids, $started_at ) );
+
+ $posts_total = count( $post_ids ) * count( $languages );
+ $terms_total = count( $term_ids ) * count( $languages );
+ $total = $posts_total + $terms_total;
+ $posts_completed = min( $counts['posts'], $posts_total );
+ $terms_completed = min( $counts['terms'], $terms_total );
+ $completed = $posts_completed + $terms_completed;
+ $percent = $total ? (int) floor( ( $completed / $total ) * 100 ) : 100;
+
+ wp_send_json_success(
+ array(
+ 'posts_completed' => $posts_completed,
+ 'posts_total' => $posts_total,
+ 'terms_completed' => $terms_completed,
+ 'terms_total' => $terms_total,
+ 'completed' => $completed,
+ 'total' => $total,
+ 'percent' => $percent,
+ 'batch_started_at' => $started_at,
+ 'task_label' => $this->translation_task_label( $post_ids, $term_ids ),
+ 'failed_items' => $failures,
+ )
+ );
+ }
+
+ public function add_translation_column( $columns ) {
+ $columns['htbd_translation'] = __( 'Translation status', 'hyx-translator-for-baidu-translate' );
+
+ return $columns;
+ }
+
+ public function render_translation_column( $column, $post_id ) {
+ if ( 'htbd_translation' !== $column ) {
+ return;
+ }
+
+ $store = new HTBD_Translation_Store();
+
+ foreach ( HTBD_Settings::target_languages() as $target_language ) {
+ $status = $store->get_post_language_status( $post_id, $target_language );
+ $translated = ! empty( $status['translated_fields'] );
+ $button_text = $translated ? __( 'Retranslate', 'hyx-translator-for-baidu-translate' ) : __( 'Translate', 'hyx-translator-for-baidu-translate' );
+ $action_url = wp_nonce_url(
+ add_query_arg(
+ array(
+ 'action' => 'htbd_translate_post',
+ 'post_id' => $post_id,
+ 'language' => $target_language,
+ 'force' => $translated ? '1' : '0',
+ ),
+ admin_url( 'admin-post.php' )
+ ),
+ 'htbd_translate_post_' . $post_id . '_' . $target_language
+ );
+
+ echo '' . esc_html( strtoupper( $target_language ) ) . ': ';
+ echo $translated ? '' . esc_html__( 'Translated', 'hyx-translator-for-baidu-translate' ) . '' : '' . esc_html__( 'Not translated', 'hyx-translator-for-baidu-translate' ) . '';
+ if ( $translated && ! empty( $status['last_translated_at'] ) ) {
+ echo '
' . esc_html__( 'Last translated:', 'hyx-translator-for-baidu-translate' ) . ' ' . esc_html( get_date_from_gmt( $status['last_translated_at'], 'Y-m-d H:i' ) ) . '';
+ }
+ echo '
' . esc_html( $button_text ) . '
';
+ }
+ }
+
+ public function queue_post_translation() {
+ $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : 0;
+ $target_language = isset( $_GET['language'] ) ? sanitize_key( wp_unslash( $_GET['language'] ) ) : '';
+ $force_refresh = ! empty( $_GET['force'] );
+
+ if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) || ! HTBD_Settings::is_supported_language( $target_language ) || $target_language === HTBD_Settings::get()['source_language'] ) {
+ wp_die( esc_html__( 'Invalid translation request.', 'hyx-translator-for-baidu-translate' ) );
+ }
+
+ check_admin_referer( 'htbd_translate_post_' . $post_id . '_' . $target_language );
+ $this->update_translation_task( array( $post_id ), array(), array( $target_language ) );
+ wp_schedule_single_event( time() + 5, 'htbd_process_translation', array( $post_id, $target_language, $force_refresh ) );
+
+ wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=' . get_post_type( $post_id ) ) );
+ exit;
+ }
+
+ public function retry_failed_translation() {
+ $item_type = isset( $_GET['item_type'] ) ? sanitize_key( wp_unslash( $_GET['item_type'] ) ) : '';
+ $item_id = isset( $_GET['item_id'] ) ? absint( $_GET['item_id'] ) : 0;
+ $target_language = isset( $_GET['language'] ) ? sanitize_key( wp_unslash( $_GET['language'] ) ) : '';
+
+ if ( ! current_user_can( 'manage_options' ) || ! $item_id || ! in_array( $item_type, array( 'post', 'term' ), true ) || ! in_array( $target_language, HTBD_Settings::target_languages(), true ) ) {
+ wp_die( esc_html__( 'Invalid translation request.', 'hyx-translator-for-baidu-translate' ) );
+ }
+
+ check_admin_referer( 'htbd_retry_failed_translation_' . $item_type . '_' . $item_id . '_' . $target_language );
+
+ if ( 'post' === $item_type ) {
+ wp_schedule_single_event( time() + 5, 'htbd_process_translation', array( $item_id, $target_language, true ) );
+ } else {
+ wp_schedule_single_event( time() + 5, 'htbd_process_term_translation', array( $item_id, $target_language, true ) );
+ }
+
+ wp_safe_redirect( admin_url( 'options-general.php?page=htbd' ) );
+ exit;
+ }
+
+ private function prepare_failed_items( $failures ) {
+ $items = array();
+
+ foreach ( (array) $failures as $failure ) {
+ $context_parts = explode( ':', $failure['item_context'], 2 );
+ $item_type = $context_parts[0] ?? '';
+ $item_id = isset( $context_parts[1] ) ? absint( $context_parts[1] ) : 0;
+ $target_language = sanitize_key( $failure['target_language'] ?? '' );
+
+ if ( ! $item_id || ! in_array( $item_type, array( 'post', 'term' ), true ) || '' === $target_language ) {
+ continue;
+ }
+
+ if ( 'post' === $item_type ) {
+ $name = get_the_title( $item_id );
+ } else {
+ $term = get_term( $item_id );
+ $name = $term && ! is_wp_error( $term ) ? $term->name : '';
+ }
+
+ if ( '' === $name ) {
+ $name = sprintf( __( 'Content #%d', 'hyx-translator-for-baidu-translate' ), $item_id );
+ }
+
+ $retry_url = wp_nonce_url(
+ add_query_arg(
+ array(
+ 'action' => 'htbd_retry_failed_translation',
+ 'item_type' => $item_type,
+ 'item_id' => $item_id,
+ 'language' => $target_language,
+ ),
+ admin_url( 'admin-post.php' )
+ ),
+ 'htbd_retry_failed_translation_' . $item_type . '_' . $item_id . '_' . $target_language
+ );
+
+ $items[] = array(
+ 'name' => $name,
+ 'language' => strtoupper( $target_language ),
+ 'retry_url' => $retry_url,
+ );
+ }
+
+ return $items;
+ }
+
+ private function update_translation_task( $post_ids, $term_ids, $target_languages ) {
+ update_option(
+ 'htbd_translation_task',
+ array(
+ 'started_at' => current_time( 'mysql', true ),
+ 'post_ids' => array_values( array_filter( array_map( 'absint', (array) $post_ids ) ) ),
+ 'term_ids' => array_values( array_filter( array_map( 'absint', (array) $term_ids ) ) ),
+ 'target_languages' => array_values( array_filter( array_map( 'sanitize_key', (array) $target_languages ) ) ),
+ ),
+ false
+ );
+ }
+
+ private function translation_task_label( $post_ids, $term_ids ) {
+ if ( ! empty( $post_ids ) && ! empty( $term_ids ) ) {
+ return __( 'Full translation', 'hyx-translator-for-baidu-translate' );
+ }
+
+ if ( 1 === count( $post_ids ) ) {
+ return __( 'Single post translation', 'hyx-translator-for-baidu-translate' );
+ }
+
+ if ( ! empty( $post_ids ) ) {
+ return __( 'Posts and pages translation', 'hyx-translator-for-baidu-translate' );
+ }
+
+ if ( ! empty( $term_ids ) ) {
+ return __( 'Categories and tags translation', 'hyx-translator-for-baidu-translate' );
+ }
+
+ return __( 'No translation task', 'hyx-translator-for-baidu-translate' );
+ }
+}
\ No newline at end of file
diff --git a/includes/class-btranslate-baidu-provider.php b/includes/class-baidu-provider.php
similarity index 76%
rename from includes/class-btranslate-baidu-provider.php
rename to includes/class-baidu-provider.php
index ca1db25..6986cc6 100644
--- a/includes/class-btranslate-baidu-provider.php
+++ b/includes/class-baidu-provider.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Baidu_Provider implements BTRANSLATE_Translation_Provider {
+class HTBD_Baidu_Provider implements HTBD_Translation_Provider {
private $app_id;
private $secret_key;
@@ -19,7 +19,7 @@ class BTRANSLATE_Baidu_Provider implements BTRANSLATE_Translation_Provider {
if ( '' === $this->app_id || '' === $this->secret_key ) {
$this->log_request( $source_value, $source_language, $target_language, $context, 'missing_credentials' );
- return BTRANSLATE_Translation_Result::failure( 'missing_credentials', __( 'Baidu Translate credentials are not configured.', 'btranslate' ) );
+ return HTBD_Translation_Result::failure( 'missing_credentials', __( 'Baidu Translate credentials are not configured.', 'hyx-translator-for-baidu-translate' ) );
}
$salt = (string) wp_rand( 100000, 999999 );
@@ -42,27 +42,27 @@ class BTRANSLATE_Baidu_Provider implements BTRANSLATE_Translation_Provider {
if ( is_wp_error( $response ) ) {
$this->log_request( $source_value, $source_language, $target_language, $context, 'request_failed', $response->get_error_code() );
- return BTRANSLATE_Translation_Result::failure( 'request_failed', $response->get_error_message() );
+ return HTBD_Translation_Result::failure( 'request_failed', $response->get_error_message() );
}
$body = json_decode( wp_remote_retrieve_body( $response ), true );
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.', 'btranslate' );
+ $error_message = isset( $body['error_msg'] ) ? sanitize_text_field( $body['error_msg'] ) : __( 'Baidu Translate returned an invalid response.', 'hyx-translator-for-baidu-translate' );
$this->log_request( $source_value, $source_language, $target_language, $context, 'failed', $error_code );
- return BTRANSLATE_Translation_Result::failure( $error_code, $error_message );
+ return HTBD_Translation_Result::failure( $error_code, $error_message );
}
$translated_parts = wp_list_pluck( $body['trans_result'], 'dst' );
$this->log_request( $source_value, $source_language, $target_language, $context, 'complete' );
- return BTRANSLATE_Translation_Result::success( implode( "\n", $translated_parts ) );
+ return HTBD_Translation_Result::success( implode( "\n", $translated_parts ) );
}
private function log_request( $source_value, $source_language, $target_language, $context, $status, $error_code = '' ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
if ( empty( $settings['log_requests'] ) ) {
return;
@@ -73,12 +73,12 @@ class BTRANSLATE_Baidu_Provider implements BTRANSLATE_Translation_Provider {
'source_language' => sanitize_key( $source_language ),
'target_language' => sanitize_key( $target_language ),
'context' => sanitize_key( $context ),
- 'source_fingerprint' => BTRANSLATE_Translation_Identity::source_fingerprint( (string) $source_value ),
+ 'source_fingerprint' => HTBD_Translation_Identity::source_fingerprint( (string) $source_value ),
'source_length' => strlen( (string) $source_value ),
'status' => sanitize_key( $status ),
'error_code' => sanitize_key( $error_code ),
);
- do_action( 'btranslate_translation_request_logged', $entry );
+ do_action( 'htbd_translation_request_logged', $entry );
}
}
diff --git a/includes/class-btranslate-admin.php b/includes/class-btranslate-admin.php
deleted file mode 100644
index 693dfed..0000000
--- a/includes/class-btranslate-admin.php
+++ /dev/null
@@ -1,445 +0,0 @@
- admin_url( 'admin-ajax.php' ),
- 'progressNonce' => wp_create_nonce( 'btranslate_translation_progress' ),
- 'i18n' => array(
- 'contentItems' => __( '(%1$s / %2$s content items)', 'btranslate' ),
- 'latestTask' => __( 'Latest task: %1$s. Posts and pages: %2$s / %3$s; categories and tags: %4$s / %5$s. Updates automatically every 5 seconds.', 'btranslate' ),
- 'failedItems' => __( 'Failed translations', 'btranslate' ),
- 'retranslate' => __( 'Retranslate', 'btranslate' ),
- 'progressError' => __( 'Unable to load translation progress at this time.', 'btranslate' ),
- ),
- )
- );
- }
-
- public function sanitize_settings( $settings ) {
- $settings = (array) $settings;
- $bindings = array();
- $routing_modes = BTRANSLATE_Settings::routing_modes( $settings['routing_mode'] ?? array() );
- $target_languages = array_values( array_filter( array_map( 'sanitize_key', explode( ',', (string) ( $settings['target_languages'] ?? 'en' ) ) ) ) );
-
- foreach ( preg_split( '/\r\n|\r|\n/', (string) ( $settings['domain_bindings'] ?? '' ) ) as $line ) {
- $parts = array_map( 'trim', explode( '=', $line, 2 ) );
- $domain = 2 === count( $parts ) ? BTRANSLATE_Settings::normalize_domain( $parts[0] ) : '';
- $language = 2 === count( $parts ) ? sanitize_key( $parts[1] ) : '';
- if ( '' !== $domain && in_array( $language, $target_languages, true ) && ! in_array( $language, $bindings, true ) ) {
- $bindings[ $domain ] = $language;
- }
- }
-
- return array(
- 'source_language' => sanitize_key( $settings['source_language'] ?? 'zh' ),
- 'target_languages' => $target_languages,
- 'routing_mode' => $routing_modes,
- 'domain_bindings' => $bindings,
- 'fallback_language' => sanitize_key( $settings['fallback_language'] ?? 'zh' ),
- 'baidu_app_id' => sanitize_text_field( $settings['baidu_app_id'] ?? '' ),
- 'baidu_secret_key' => sanitize_text_field( $settings['baidu_secret_key'] ?? '' ),
- 'log_requests' => ! empty( $settings['log_requests'] ),
- );
- }
-
- public function render_settings_page() {
- $settings = BTRANSLATE_Settings::get();
- $bindings = array();
- foreach ( (array) $settings['domain_bindings'] as $domain => $language ) {
- $bindings[] = $domain . '=' . $language;
- }
- ?>
-
-
Btranslate
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- array( 'post', 'page' ),
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- )
- );
-
- }
-
- if ( 'all' === $scope || 'terms' === $scope ) {
- $term_ids = get_terms(
- array(
- 'taxonomy' => array( 'category', 'post_tag' ),
- 'hide_empty' => false,
- 'fields' => 'ids',
- )
- );
- if ( is_wp_error( $term_ids ) ) {
- $term_ids = array();
- }
- }
-
- $this->update_translation_task( $post_ids, $term_ids, $languages );
-
- foreach ( $post_ids as $post_id ) {
- foreach ( $languages as $target_language ) {
- $this->clear_scheduled_event( 'btranslate_process_translation', array( $post_id, $target_language, true ) );
- wp_schedule_single_event( $next_run, 'btranslate_process_translation', array( $post_id, $target_language, true ) );
- $next_run += 2;
- ++$scheduled;
- }
- }
-
- foreach ( $term_ids as $term_id ) {
- foreach ( $languages as $target_language ) {
- $this->clear_scheduled_event( 'btranslate_process_term_translation', array( $term_id, $target_language, true ) );
- wp_schedule_single_event( $next_run, 'btranslate_process_term_translation', array( $term_id, $target_language, true ) );
- $next_run += 2;
- ++$scheduled;
- }
- }
-
- wp_safe_redirect( add_query_arg( 'btranslate_queued', $scheduled, admin_url( 'options-general.php?page=btranslate' ) ) );
- exit;
- }
-
- public function clear_translation_cache() {
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_die( esc_html__( 'You do not have permission to perform this action.', 'btranslate' ) );
- }
-
- check_admin_referer( 'btranslate_clear_translation_cache' );
- $deleted = ( new BTRANSLATE_Translation_Store() )->clear();
-
- if ( false === $deleted ) {
- wp_die( esc_html__( 'Failed to clear the translation cache.', 'btranslate' ) );
- }
-
- wp_clear_scheduled_hook( 'btranslate_process_translation' );
- wp_clear_scheduled_hook( 'btranslate_process_term_translation' );
- wp_clear_scheduled_hook( 'btranslate_process_seo_output_translation' );
- delete_option( 'btranslate_translation_task' );
- delete_option( 'btranslate_retranslation_batch' );
-
- wp_safe_redirect( add_query_arg( 'btranslate_cache_cleared', 1, admin_url( 'options-general.php?page=btranslate' ) ) );
- exit;
- }
-
- private function clear_scheduled_event( $hook, $args ) {
- while ( false !== ( $timestamp = wp_next_scheduled( $hook, $args ) ) ) {
- wp_unschedule_event( $timestamp, $hook, $args );
- }
- }
-
- public function add_plugin_settings_link( $links ) {
- array_unshift( $links, '' . esc_html__( 'Settings', 'btranslate' ) . '' );
-
- return $links;
- }
-
- public function translation_progress() {
- check_ajax_referer( 'btranslate_translation_progress' );
-
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_send_json_error( array( 'message' => 'forbidden' ), 403 );
- }
-
- $task = (array) get_option( 'btranslate_translation_task', array() );
- $post_ids = array_values( array_filter( array_map( 'absint', (array) ( $task['post_ids'] ?? array() ) ) ) );
- $term_ids = array_values( array_filter( array_map( 'absint', (array) ( $task['term_ids'] ?? array() ) ) ) );
- $languages = array_values( array_filter( array_map( 'sanitize_key', (array) ( $task['target_languages'] ?? array() ) ) ) );
- $started_at = isset( $task['started_at'] ) ? sanitize_text_field( $task['started_at'] ) : '';
- $store = new BTRANSLATE_Translation_Store();
- $counts = $store->get_completed_item_counts( $languages, $post_ids, $term_ids, $started_at );
- $failures = $this->prepare_failed_items( $store->get_failed_items( $languages, $post_ids, $term_ids, $started_at ) );
-
- $posts_total = count( $post_ids ) * count( $languages );
- $terms_total = count( $term_ids ) * count( $languages );
- $total = $posts_total + $terms_total;
- $posts_completed = min( $counts['posts'], $posts_total );
- $terms_completed = min( $counts['terms'], $terms_total );
- $completed = $posts_completed + $terms_completed;
- $percent = $total ? (int) floor( ( $completed / $total ) * 100 ) : 100;
-
- wp_send_json_success(
- array(
- 'posts_completed' => $posts_completed,
- 'posts_total' => $posts_total,
- 'terms_completed' => $terms_completed,
- 'terms_total' => $terms_total,
- 'completed' => $completed,
- 'total' => $total,
- 'percent' => $percent,
- 'batch_started_at' => $started_at,
- 'task_label' => $this->translation_task_label( $post_ids, $term_ids ),
- 'failed_items' => $failures,
- )
- );
- }
-
- public function add_translation_column( $columns ) {
- $columns['btranslate_translation'] = __( 'Translation status', 'btranslate' );
-
- return $columns;
- }
-
- public function render_translation_column( $column, $post_id ) {
- if ( 'btranslate_translation' !== $column ) {
- return;
- }
-
- $store = new BTRANSLATE_Translation_Store();
-
- foreach ( BTRANSLATE_Settings::target_languages() as $target_language ) {
- $status = $store->get_post_language_status( $post_id, $target_language );
- $translated = ! empty( $status['translated_fields'] );
- $button_text = $translated ? __( 'Retranslate', 'btranslate' ) : __( 'Translate', 'btranslate' );
- $action_url = wp_nonce_url(
- add_query_arg(
- array(
- 'action' => 'btranslate_translate_post',
- 'post_id' => $post_id,
- 'language' => $target_language,
- 'force' => $translated ? '1' : '0',
- ),
- admin_url( 'admin-post.php' )
- ),
- 'btranslate_translate_post_' . $post_id . '_' . $target_language
- );
-
- echo '' . esc_html( strtoupper( $target_language ) ) . ': ';
- echo $translated ? '' . esc_html__( 'Translated', 'btranslate' ) . '' : '' . esc_html__( 'Not translated', 'btranslate' ) . '';
- if ( $translated && ! empty( $status['last_translated_at'] ) ) {
- echo '
' . esc_html__( 'Last translated:', 'btranslate' ) . ' ' . esc_html( get_date_from_gmt( $status['last_translated_at'], 'Y-m-d H:i' ) ) . '';
- }
- echo '
' . esc_html( $button_text ) . '
';
- }
- }
-
- public function queue_post_translation() {
- $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : 0;
- $target_language = isset( $_GET['language'] ) ? sanitize_key( wp_unslash( $_GET['language'] ) ) : '';
- $force_refresh = ! empty( $_GET['force'] );
-
- if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) || ! BTRANSLATE_Settings::is_supported_language( $target_language ) || $target_language === BTRANSLATE_Settings::get()['source_language'] ) {
- wp_die( esc_html__( 'Invalid translation request.', 'btranslate' ) );
- }
-
- check_admin_referer( 'btranslate_translate_post_' . $post_id . '_' . $target_language );
- $this->update_translation_task( array( $post_id ), array(), array( $target_language ) );
- wp_schedule_single_event( time() + 5, 'btranslate_process_translation', array( $post_id, $target_language, $force_refresh ) );
-
- wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=' . get_post_type( $post_id ) ) );
- exit;
- }
-
- public function retry_failed_translation() {
- $item_type = isset( $_GET['item_type'] ) ? sanitize_key( wp_unslash( $_GET['item_type'] ) ) : '';
- $item_id = isset( $_GET['item_id'] ) ? absint( $_GET['item_id'] ) : 0;
- $target_language = isset( $_GET['language'] ) ? sanitize_key( wp_unslash( $_GET['language'] ) ) : '';
-
- if ( ! current_user_can( 'manage_options' ) || ! $item_id || ! in_array( $item_type, array( 'post', 'term' ), true ) || ! in_array( $target_language, BTRANSLATE_Settings::target_languages(), true ) ) {
- wp_die( esc_html__( 'Invalid translation request.', 'btranslate' ) );
- }
-
- check_admin_referer( 'btranslate_retry_failed_translation_' . $item_type . '_' . $item_id . '_' . $target_language );
-
- if ( 'post' === $item_type ) {
- wp_schedule_single_event( time() + 5, 'btranslate_process_translation', array( $item_id, $target_language, true ) );
- } else {
- wp_schedule_single_event( time() + 5, 'btranslate_process_term_translation', array( $item_id, $target_language, true ) );
- }
-
- wp_safe_redirect( admin_url( 'options-general.php?page=btranslate' ) );
- exit;
- }
-
- private function prepare_failed_items( $failures ) {
- $items = array();
-
- foreach ( (array) $failures as $failure ) {
- $context_parts = explode( ':', $failure['item_context'], 2 );
- $item_type = $context_parts[0] ?? '';
- $item_id = isset( $context_parts[1] ) ? absint( $context_parts[1] ) : 0;
- $target_language = sanitize_key( $failure['target_language'] ?? '' );
-
- if ( ! $item_id || ! in_array( $item_type, array( 'post', 'term' ), true ) || '' === $target_language ) {
- continue;
- }
-
- if ( 'post' === $item_type ) {
- $name = get_the_title( $item_id );
- } else {
- $term = get_term( $item_id );
- $name = $term && ! is_wp_error( $term ) ? $term->name : '';
- }
-
- if ( '' === $name ) {
- $name = sprintf( __( 'Content #%d', 'btranslate' ), $item_id );
- }
-
- $retry_url = wp_nonce_url(
- add_query_arg(
- array(
- 'action' => 'btranslate_retry_failed_translation',
- 'item_type' => $item_type,
- 'item_id' => $item_id,
- 'language' => $target_language,
- ),
- admin_url( 'admin-post.php' )
- ),
- 'btranslate_retry_failed_translation_' . $item_type . '_' . $item_id . '_' . $target_language
- );
-
- $items[] = array(
- 'name' => $name,
- 'language' => strtoupper( $target_language ),
- 'retry_url' => $retry_url,
- );
- }
-
- return $items;
- }
-
- private function update_translation_task( $post_ids, $term_ids, $target_languages ) {
- update_option(
- 'btranslate_translation_task',
- array(
- 'started_at' => current_time( 'mysql', true ),
- 'post_ids' => array_values( array_filter( array_map( 'absint', (array) $post_ids ) ) ),
- 'term_ids' => array_values( array_filter( array_map( 'absint', (array) $term_ids ) ) ),
- 'target_languages' => array_values( array_filter( array_map( 'sanitize_key', (array) $target_languages ) ) ),
- ),
- false
- );
- }
-
- private function translation_task_label( $post_ids, $term_ids ) {
- if ( ! empty( $post_ids ) && ! empty( $term_ids ) ) {
- return __( 'Full translation', 'btranslate' );
- }
-
- if ( 1 === count( $post_ids ) ) {
- return __( 'Single post translation', 'btranslate' );
- }
-
- if ( ! empty( $post_ids ) ) {
- return __( 'Posts and pages translation', 'btranslate' );
- }
-
- if ( ! empty( $term_ids ) ) {
- return __( 'Categories and tags translation', 'btranslate' );
- }
-
- return __( 'No translation task', 'btranslate' );
- }
-}
\ No newline at end of file
diff --git a/includes/class-btranslate-content-controller.php b/includes/class-content-controller.php
similarity index 80%
rename from includes/class-btranslate-content-controller.php
rename to includes/class-content-controller.php
index 847ecba..b1fadc3 100644
--- a/includes/class-btranslate-content-controller.php
+++ b/includes/class-content-controller.php
@@ -2,20 +2,20 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Content_Controller {
+class HTBD_Content_Controller {
private $store;
private $router;
- public function __construct( BTRANSLATE_Translation_Store $store, BTRANSLATE_Language_Router $router ) {
+ public function __construct( HTBD_Translation_Store $store, HTBD_Language_Router $router ) {
$this->store = $store;
$this->router = $router;
}
public function register() {
add_action( 'save_post', array( $this, 'schedule_post_translation' ), 20, 3 );
- add_action( 'btranslate_process_translation', array( $this, 'translate_post' ), 10, 3 );
- add_action( 'btranslate_process_term_translation', array( $this, 'translate_term' ), 10, 3 );
- add_action( 'btranslate_process_seo_output_translation', array( $this, 'translate_seo_output' ), 10, 4 );
+ add_action( 'htbd_process_translation', array( $this, 'translate_post' ), 10, 3 );
+ add_action( 'htbd_process_term_translation', array( $this, 'translate_term' ), 10, 3 );
+ add_action( 'htbd_process_seo_output_translation', array( $this, 'translate_seo_output' ), 10, 4 );
add_action( 'created_term', array( $this, 'schedule_term_translation' ), 20, 3 );
add_action( 'edited_term', array( $this, 'schedule_term_translation' ), 20, 3 );
add_filter( 'the_title', array( $this, 'translate_title' ), 20, 2 );
@@ -47,24 +47,24 @@ class BTRANSLATE_Content_Controller {
return;
}
- foreach ( BTRANSLATE_Settings::target_languages() as $target_language ) {
- if ( ! wp_next_scheduled( 'btranslate_process_translation', array( $post_id, $target_language ) ) ) {
- wp_schedule_single_event( time() + 10, 'btranslate_process_translation', array( $post_id, $target_language ) );
+ foreach ( HTBD_Settings::target_languages() as $target_language ) {
+ if ( ! wp_next_scheduled( 'htbd_process_translation', array( $post_id, $target_language ) ) ) {
+ wp_schedule_single_event( time() + 10, 'htbd_process_translation', array( $post_id, $target_language ) );
}
}
}
public function translate_post( $post_id, $target_language, $force_refresh = false ) {
$post = get_post( $post_id );
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
- if ( ! $post || 'publish' !== $post->post_status || ! BTRANSLATE_Settings::is_supported_language( $target_language ) ) {
+ if ( ! $post || 'publish' !== $post->post_status || ! HTBD_Settings::is_supported_language( $target_language ) ) {
return;
}
- $service = new BTRANSLATE_Translation_Service(
+ $service = new HTBD_Translation_Service(
$this->store,
- new BTRANSLATE_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
+ new HTBD_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
);
$fields = array(
@@ -91,7 +91,7 @@ class BTRANSLATE_Content_Controller {
if ( '' !== $value ) {
$context = 'post:' . $post_id . ':' . $field;
if ( 'post_content' === $field ) {
- ( new BTRANSLATE_Content_Translator( $service ) )->translate( $value, $settings['source_language'], $target_language, $context, $force_refresh );
+ ( new HTBD_Content_Translator( $service ) )->translate( $value, $settings['source_language'], $target_language, $context, $force_refresh );
} else {
$service->get_or_translate( $value, $settings['source_language'], $target_language, $context, $force_refresh );
}
@@ -107,24 +107,24 @@ class BTRANSLATE_Content_Controller {
return;
}
- foreach ( BTRANSLATE_Settings::target_languages() as $target_language ) {
- if ( ! wp_next_scheduled( 'btranslate_process_term_translation', array( $term_id, $target_language, false ) ) ) {
- wp_schedule_single_event( time() + 10, 'btranslate_process_term_translation', array( $term_id, $target_language, false ) );
+ foreach ( HTBD_Settings::target_languages() as $target_language ) {
+ if ( ! wp_next_scheduled( 'htbd_process_term_translation', array( $term_id, $target_language, false ) ) ) {
+ wp_schedule_single_event( time() + 10, 'htbd_process_term_translation', array( $term_id, $target_language, false ) );
}
}
}
public function translate_term( $term_id, $target_language, $force_refresh = false ) {
$term = get_term( $term_id );
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
- if ( ! $term || is_wp_error( $term ) || ! in_array( $term->taxonomy, array( 'category', 'post_tag' ), true ) || ! BTRANSLATE_Settings::is_supported_language( $target_language ) ) {
+ if ( ! $term || is_wp_error( $term ) || ! in_array( $term->taxonomy, array( 'category', 'post_tag' ), true ) || ! HTBD_Settings::is_supported_language( $target_language ) ) {
return;
}
- $service = new BTRANSLATE_Translation_Service(
+ $service = new HTBD_Translation_Service(
$this->store,
- new BTRANSLATE_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
+ new HTBD_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
);
if ( '' !== $term->name ) {
@@ -136,15 +136,15 @@ class BTRANSLATE_Content_Controller {
}
public function translate_seo_output( $post_id, $source_value, $target_language, $context ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
- if ( ! get_post( $post_id ) || ! BTRANSLATE_Settings::is_supported_language( $target_language ) || '' === $source_value ) {
+ if ( ! get_post( $post_id ) || ! HTBD_Settings::is_supported_language( $target_language ) || '' === $source_value ) {
return;
}
- $service = new BTRANSLATE_Translation_Service(
+ $service = new HTBD_Translation_Service(
$this->store,
- new BTRANSLATE_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
+ new HTBD_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] )
);
$service->get_or_translate( $source_value, $settings['source_language'], $target_language, $context );
@@ -160,18 +160,18 @@ class BTRANSLATE_Content_Controller {
return $this->escaped_translated_value( $content, 'post:' . $post_id . ':post_content' );
}
- $segments = BTRANSLATE_Content_Translator::segments( $content );
+ $segments = HTBD_Content_Translator::segments( $content );
if ( false === $segments ) {
return $content;
}
$text_index = 0;
foreach ( $segments as $index => $segment ) {
- if ( BTRANSLATE_Content_Translator::is_tag( $segment ) || '' === trim( $segment ) ) {
+ if ( HTBD_Content_Translator::is_tag( $segment ) || '' === trim( $segment ) ) {
continue;
}
- $whitespace = BTRANSLATE_Content_Translator::surrounding_whitespace( $segment );
+ $whitespace = HTBD_Content_Translator::surrounding_whitespace( $segment );
$translated = $this->escaped_translated_value( $whitespace['text'], 'post:' . $post_id . ':post_content:text:' . $text_index );
$segments[ $index ] = $whitespace['leading'] . $translated . $whitespace['trailing'];
++$text_index;
@@ -306,15 +306,15 @@ class BTRANSLATE_Content_Controller {
}
private function translated_value( $source_value, $context ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
$target_language = $this->router->current_language();
if ( $target_language === $settings['source_language'] || '' === $source_value ) {
return $source_value;
}
- $provider = new BTRANSLATE_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] );
- $identity_key = BTRANSLATE_Translation_Identity::key( $source_value, $settings['source_language'], $target_language, $context, $provider->get_version() );
+ $provider = new HTBD_Baidu_Provider( $settings['baidu_app_id'], $settings['baidu_secret_key'] );
+ $identity_key = HTBD_Translation_Identity::key( $source_value, $settings['source_language'], $target_language, $context, $provider->get_version() );
$translation = $this->store->find_valid( $identity_key );
return ! empty( $translation['translated_value'] ) ? $translation['translated_value'] : $source_value;
@@ -327,7 +327,7 @@ class BTRANSLATE_Content_Controller {
}
private function translated_or_schedule_seo_output( $source_value, $post_id, $field_context ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
$target_language = $this->router->current_language();
$context = 'post:' . $post_id . ':' . $field_context;
@@ -341,8 +341,8 @@ class BTRANSLATE_Content_Controller {
}
$event_args = array( $post_id, $source_value, $target_language, $context );
- if ( ! wp_next_scheduled( 'btranslate_process_seo_output_translation', $event_args ) ) {
- wp_schedule_single_event( time() + 5, 'btranslate_process_seo_output_translation', $event_args );
+ if ( ! wp_next_scheduled( 'htbd_process_seo_output_translation', $event_args ) ) {
+ wp_schedule_single_event( time() + 5, 'htbd_process_seo_output_translation', $event_args );
}
return $source_value;
diff --git a/includes/class-btranslate-content-translator.php b/includes/class-content-translator.php
similarity index 81%
rename from includes/class-btranslate-content-translator.php
rename to includes/class-content-translator.php
index 84f14fa..987250f 100644
--- a/includes/class-btranslate-content-translator.php
+++ b/includes/class-content-translator.php
@@ -2,17 +2,17 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Content_Translator {
+class HTBD_Content_Translator {
private $service;
- public function __construct( BTRANSLATE_Translation_Service $service ) {
+ public function __construct( HTBD_Translation_Service $service ) {
$this->service = $service;
}
public function translate( $content, $source_language, $target_language, $context, $force_refresh = false ) {
$segments = self::segments( $content );
if ( false === $segments ) {
- return BTRANSLATE_Translation_Result::failure( 'content_parse_failed', 'Unable to protect links before translation.' );
+ return HTBD_Translation_Result::failure( 'content_parse_failed', 'Unable to protect links before translation.' );
}
$text_index = 0;
@@ -29,7 +29,7 @@ class BTRANSLATE_Content_Translator {
++$text_index;
}
- return BTRANSLATE_Translation_Result::success( $content );
+ return HTBD_Translation_Result::success( $content );
}
public static function segments( $content ) {
diff --git a/includes/class-btranslate-language-router.php b/includes/class-language-router.php
similarity index 73%
rename from includes/class-btranslate-language-router.php
rename to includes/class-language-router.php
index 5216f12..2d20268 100644
--- a/includes/class-btranslate-language-router.php
+++ b/includes/class-language-router.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Language_Router {
+class HTBD_Language_Router {
private $request_language = '';
public function register() {
@@ -17,13 +17,13 @@ class BTRANSLATE_Language_Router {
}
public function query_vars( $query_vars ) {
- $query_vars[] = 'btranslate_language';
+ $query_vars[] = 'htbd_language';
return $query_vars;
}
public function strip_language_prefix( $do_parse_request, $wp, $extra_query_vars ) {
- if ( ! $do_parse_request || ! BTRANSLATE_Settings::is_routing_mode_enabled( 'subdirectory' ) || empty( $_SERVER['REQUEST_URI'] ) ) {
+ if ( ! $do_parse_request || ! HTBD_Settings::is_routing_mode_enabled( 'subdirectory' ) || empty( $_SERVER['REQUEST_URI'] ) ) {
return $do_parse_request;
}
@@ -40,7 +40,7 @@ class BTRANSLATE_Language_Router {
$segments = explode( '/', $relative, 2 );
$language = sanitize_key( $segments[0] );
- if ( ! in_array( $language, BTRANSLATE_Settings::subdirectory_languages(), true ) ) {
+ if ( ! in_array( $language, HTBD_Settings::subdirectory_languages(), true ) ) {
return $do_parse_request;
}
@@ -53,30 +53,30 @@ class BTRANSLATE_Language_Router {
}
public function resolve_domain_language( $wp ) {
- $settings = BTRANSLATE_Settings::get();
- $host = isset( $_SERVER['HTTP_HOST'] ) ? BTRANSLATE_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
+ $settings = HTBD_Settings::get();
+ $host = isset( $_SERVER['HTTP_HOST'] ) ? HTBD_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
$bindings = (array) $settings['domain_bindings'];
if ( '' !== $this->request_language ) {
- $wp->query_vars['btranslate_language'] = $this->request_language;
+ $wp->query_vars['htbd_language'] = $this->request_language;
}
- if ( BTRANSLATE_Settings::is_routing_mode_enabled( 'domain' ) && '' !== $host && isset( $bindings[ $host ] ) && BTRANSLATE_Settings::is_supported_language( $bindings[ $host ] ) ) {
+ if ( HTBD_Settings::is_routing_mode_enabled( 'domain' ) && '' !== $host && isset( $bindings[ $host ] ) && HTBD_Settings::is_supported_language( $bindings[ $host ] ) ) {
if ( '' !== $this->request_language ) {
$wp->query_vars = array( 'error' => '404' );
return;
}
- $wp->query_vars['btranslate_language'] = sanitize_key( $bindings[ $host ] );
+ $wp->query_vars['htbd_language'] = sanitize_key( $bindings[ $host ] );
}
}
public function current_language() {
- $settings = BTRANSLATE_Settings::get();
- $language = get_query_var( 'btranslate_language' );
+ $settings = HTBD_Settings::get();
+ $language = get_query_var( 'htbd_language' );
- if ( $language && BTRANSLATE_Settings::is_supported_language( $language ) ) {
+ if ( $language && HTBD_Settings::is_supported_language( $language ) ) {
return sanitize_key( $language );
}
@@ -84,14 +84,14 @@ class BTRANSLATE_Language_Router {
}
public function localized_url( $url, $language = '' ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
$language = '' === $language ? $this->current_language() : sanitize_key( $language );
- if ( $language === $settings['source_language'] || ! BTRANSLATE_Settings::is_supported_language( $language ) ) {
+ if ( $language === $settings['source_language'] || ! HTBD_Settings::is_supported_language( $language ) ) {
return $url;
}
- if ( BTRANSLATE_Settings::is_routing_mode_enabled( 'domain' ) && $this->request_uses_domain( $language ) ) {
+ if ( HTBD_Settings::is_routing_mode_enabled( 'domain' ) && $this->request_uses_domain( $language ) ) {
$domain = array_search( $language, (array) $settings['domain_bindings'], true );
$parts = wp_parse_url( $url );
@@ -105,7 +105,7 @@ class BTRANSLATE_Language_Router {
}
}
- if ( ! BTRANSLATE_Settings::is_routing_mode_enabled( 'subdirectory' ) ) {
+ if ( ! HTBD_Settings::is_routing_mode_enabled( 'subdirectory' ) ) {
return $url;
}
@@ -130,15 +130,15 @@ class BTRANSLATE_Language_Router {
}
private function request_uses_domain( $language ) {
- $host = isset( $_SERVER['HTTP_HOST'] ) ? BTRANSLATE_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
- $bindings = (array) BTRANSLATE_Settings::get()['domain_bindings'];
+ $host = isset( $_SERVER['HTTP_HOST'] ) ? HTBD_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
+ $bindings = (array) HTBD_Settings::get()['domain_bindings'];
return '' !== $host && isset( $bindings[ $host ] ) && sanitize_key( $bindings[ $host ] ) === $language;
}
private function source_origin_parts( $parts ) {
- $host = isset( $_SERVER['HTTP_HOST'] ) ? BTRANSLATE_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
- $bindings = (array) BTRANSLATE_Settings::get()['domain_bindings'];
+ $host = isset( $_SERVER['HTTP_HOST'] ) ? HTBD_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
+ $bindings = (array) HTBD_Settings::get()['domain_bindings'];
if ( '' === $host || ! isset( $bindings[ $host ] ) ) {
return $parts;
@@ -164,7 +164,7 @@ class BTRANSLATE_Language_Router {
private function localized_path( $path, $language ) {
$home_path = $this->home_path();
$relative = $this->relative_path( $path );
- $languages = array_map( 'preg_quote', BTRANSLATE_Settings::target_languages() );
+ $languages = array_map( 'preg_quote', HTBD_Settings::target_languages() );
if ( ! empty( $languages ) ) {
$relative = preg_replace( '#^(?:' . implode( '|', $languages ) . ')(?=/|$)#', $language, $relative, 1 );
@@ -180,7 +180,7 @@ class BTRANSLATE_Language_Router {
private function source_path( $path ) {
$home_path = $this->home_path();
$relative = $this->relative_path( $path );
- $languages = array_map( 'preg_quote', BTRANSLATE_Settings::target_languages() );
+ $languages = array_map( 'preg_quote', HTBD_Settings::target_languages() );
if ( ! empty( $languages ) ) {
$relative = preg_replace( '#^(?:' . implode( '|', $languages ) . ')(?=/|$)/?#', '', $relative, 1 );
diff --git a/includes/class-btranslate-plugin.php b/includes/class-plugin.php
similarity index 55%
rename from includes/class-btranslate-plugin.php
rename to includes/class-plugin.php
index d827d78..5c7921c 100644
--- a/includes/class-btranslate-plugin.php
+++ b/includes/class-plugin.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Plugin {
+class HTBD_Plugin {
private static $instance;
private $router;
private $sitemap_controller;
@@ -10,13 +10,13 @@ class BTRANSLATE_Plugin {
private $admin;
private function __construct() {
- $this->router = new BTRANSLATE_Language_Router();
- $this->sitemap_controller = new BTRANSLATE_Sitemap_Controller( $this->router );
- $this->content_controller = new BTRANSLATE_Content_Controller( new BTRANSLATE_Translation_Store(), $this->router );
- $this->admin = new BTRANSLATE_Admin();
+ $this->router = new HTBD_Language_Router();
+ $this->sitemap_controller = new HTBD_Sitemap_Controller( $this->router );
+ $this->content_controller = new HTBD_Content_Controller( new HTBD_Translation_Store(), $this->router );
+ $this->admin = new HTBD_Admin();
add_action( 'init', array( $this, 'register' ) );
- add_action( 'update_option_btranslate_settings', array( $this, 'refresh_rewrite_rules' ), 10, 2 );
+ add_action( 'update_option_htbd_settings', array( $this, 'refresh_rewrite_rules' ), 10, 2 );
$this->admin->register();
}
@@ -29,9 +29,16 @@ class BTRANSLATE_Plugin {
}
public static function activate() {
- BTRANSLATE_Translation_Store::install();
+ HTBD_Translation_Store::install();
+ wp_clear_scheduled_hook( 'btranslate_process_translation' );
+ wp_clear_scheduled_hook( 'btranslate_process_term_translation' );
+ wp_clear_scheduled_hook( 'btranslate_process_seo_output_translation' );
+ $legacy_settings = get_option( 'btranslate_settings', null );
+ if ( null !== $legacy_settings && false === get_option( 'htbd_settings', false ) ) {
+ add_option( 'htbd_settings', $legacy_settings, '', false );
+ }
add_option(
- 'btranslate_settings',
+ 'htbd_settings',
array(
'source_language' => 'zh',
'target_languages' => array( 'en' ),
@@ -42,15 +49,15 @@ class BTRANSLATE_Plugin {
'',
false
);
- $router = new BTRANSLATE_Language_Router();
+ $router = new HTBD_Language_Router();
$router->register_rewrite_rules();
flush_rewrite_rules();
}
public static function deactivate() {
- wp_clear_scheduled_hook( 'btranslate_process_translation' );
- wp_clear_scheduled_hook( 'btranslate_process_term_translation' );
- wp_clear_scheduled_hook( 'btranslate_process_seo_output_translation' );
+ wp_clear_scheduled_hook( 'htbd_process_translation' );
+ wp_clear_scheduled_hook( 'htbd_process_term_translation' );
+ wp_clear_scheduled_hook( 'htbd_process_seo_output_translation' );
flush_rewrite_rules();
}
@@ -59,15 +66,15 @@ class BTRANSLATE_Plugin {
$this->sitemap_controller->register();
$this->content_controller->register();
- if ( get_option( 'btranslate_flush_rewrite_rules', false ) ) {
- delete_option( 'btranslate_flush_rewrite_rules' );
+ if ( get_option( 'htbd_flush_rewrite_rules', false ) ) {
+ delete_option( 'htbd_flush_rewrite_rules' );
flush_rewrite_rules();
}
}
public function refresh_rewrite_rules( $old_value, $new_value ) {
if ( (array) $old_value !== (array) $new_value ) {
- update_option( 'btranslate_flush_rewrite_rules', 1, false );
+ update_option( 'htbd_flush_rewrite_rules', 1, false );
}
}
}
\ No newline at end of file
diff --git a/includes/class-btranslate-settings.php b/includes/class-settings.php
similarity index 80%
rename from includes/class-btranslate-settings.php
rename to includes/class-settings.php
index c82992b..e963607 100644
--- a/includes/class-btranslate-settings.php
+++ b/includes/class-settings.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Settings {
+class HTBD_Settings {
public static function get() {
$defaults = array(
'source_language' => 'zh',
@@ -15,7 +15,16 @@ class BTRANSLATE_Settings {
'log_requests' => false,
);
- $settings = wp_parse_args( (array) get_option( 'btranslate_settings', array() ), $defaults );
+ $stored_settings = get_option( 'htbd_settings', false );
+ if ( false === $stored_settings ) {
+ $legacy_settings = get_option( 'btranslate_settings', false );
+ if ( false !== $legacy_settings ) {
+ $stored_settings = $legacy_settings;
+ add_option( 'htbd_settings', $legacy_settings, '', false );
+ }
+ }
+
+ $settings = wp_parse_args( (array) $stored_settings, $defaults );
$settings['routing_mode'] = self::routing_modes( $settings['routing_mode'] );
return $settings;
diff --git a/includes/class-btranslate-sitemap-controller.php b/includes/class-sitemap-controller.php
similarity index 87%
rename from includes/class-btranslate-sitemap-controller.php
rename to includes/class-sitemap-controller.php
index b4d3832..64d722a 100644
--- a/includes/class-btranslate-sitemap-controller.php
+++ b/includes/class-sitemap-controller.php
@@ -2,11 +2,11 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Sitemap_Controller {
+class HTBD_Sitemap_Controller {
private $router;
private $target_language = '';
- public function __construct( BTRANSLATE_Language_Router $router ) {
+ public function __construct( HTBD_Language_Router $router ) {
$this->router = $router;
}
@@ -15,7 +15,7 @@ class BTRANSLATE_Sitemap_Controller {
}
public function intercept_request( $do_parse_request, $wp, $extra_query_vars ) {
- $settings = BTRANSLATE_Settings::get();
+ $settings = HTBD_Settings::get();
$language = $this->requested_language( $this->request_path(), $settings );
if ( '' === $language ) {
@@ -52,7 +52,7 @@ class BTRANSLATE_Sitemap_Controller {
}
private function source_sitemap_xml( $source_url ) {
- $cache_key = 'btranslate_sitemap_' . md5( $source_url );
+ $cache_key = 'htbd_sitemap_' . md5( $source_url );
$cached = get_transient( $cache_key );
if ( is_string( $cached ) && '' !== $cached ) {
@@ -98,18 +98,18 @@ class BTRANSLATE_Sitemap_Controller {
$path = '/' . ltrim( (string) $path, '/' );
}
- if ( BTRANSLATE_Settings::is_routing_mode_enabled( 'domain' ) && '/sitemap.xml' === untrailingslashit( $path ) ) {
- $host = isset( $_SERVER['HTTP_HOST'] ) ? BTRANSLATE_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
+ if ( HTBD_Settings::is_routing_mode_enabled( 'domain' ) && '/sitemap.xml' === untrailingslashit( $path ) ) {
+ $host = isset( $_SERVER['HTTP_HOST'] ) ? HTBD_Settings::normalize_domain( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
$bindings = (array) $settings['domain_bindings'];
$language = isset( $bindings[ $host ] ) ? sanitize_key( $bindings[ $host ] ) : '';
- if ( in_array( $language, BTRANSLATE_Settings::target_languages(), true ) ) {
+ if ( in_array( $language, HTBD_Settings::target_languages(), true ) ) {
return $language;
}
}
- if ( BTRANSLATE_Settings::is_routing_mode_enabled( 'subdirectory' ) ) {
- foreach ( BTRANSLATE_Settings::subdirectory_languages() as $language ) {
+ if ( HTBD_Settings::is_routing_mode_enabled( 'subdirectory' ) ) {
+ foreach ( HTBD_Settings::subdirectory_languages() as $language ) {
$language = sanitize_key( $language );
if ( '/' . $language . '/sitemap.xml' === untrailingslashit( $path ) ) {
diff --git a/includes/class-btranslate-translation-identity.php b/includes/class-translation-identity.php
similarity index 92%
rename from includes/class-btranslate-translation-identity.php
rename to includes/class-translation-identity.php
index 5574050..12e5817 100644
--- a/includes/class-btranslate-translation-identity.php
+++ b/includes/class-translation-identity.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Translation_Identity {
+class HTBD_Translation_Identity {
public static function source_fingerprint( $source_value ) {
return hash( 'sha256', (string) $source_value );
}
diff --git a/includes/class-btranslate-translation-result.php b/includes/class-translation-result.php
similarity index 93%
rename from includes/class-btranslate-translation-result.php
rename to includes/class-translation-result.php
index 4242496..c5a44f8 100644
--- a/includes/class-btranslate-translation-result.php
+++ b/includes/class-translation-result.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Translation_Result {
+class HTBD_Translation_Result {
public $success;
public $value;
public $error_code;
diff --git a/includes/class-btranslate-translation-service.php b/includes/class-translation-service.php
similarity index 65%
rename from includes/class-btranslate-translation-service.php
rename to includes/class-translation-service.php
index d9d50ee..162d70b 100644
--- a/includes/class-btranslate-translation-service.php
+++ b/includes/class-translation-service.php
@@ -2,23 +2,23 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Translation_Service {
+class HTBD_Translation_Service {
private $store;
private $provider;
- public function __construct( BTRANSLATE_Translation_Store $store, BTRANSLATE_Translation_Provider $provider ) {
+ public function __construct( HTBD_Translation_Store $store, HTBD_Translation_Provider $provider ) {
$this->store = $store;
$this->provider = $provider;
}
public function get_or_translate( $source_value, $source_language, $target_language, $context, $force_refresh = false ) {
$source_value = (string) $source_value;
- $source_fingerprint = BTRANSLATE_Translation_Identity::source_fingerprint( $source_value );
- $identity_key = BTRANSLATE_Translation_Identity::key( $source_value, $source_language, $target_language, $context, $this->provider->get_version() );
+ $source_fingerprint = HTBD_Translation_Identity::source_fingerprint( $source_value );
+ $identity_key = HTBD_Translation_Identity::key( $source_value, $source_language, $target_language, $context, $this->provider->get_version() );
$existing = $this->store->find_valid( $identity_key );
if ( ! $force_refresh && ! empty( $existing['translated_value'] ) ) {
- return BTRANSLATE_Translation_Result::success( $existing['translated_value'] );
+ return HTBD_Translation_Result::success( $existing['translated_value'] );
}
$result = $this->provider->translate( $source_value, $source_language, $target_language, $context );
diff --git a/includes/class-btranslate-translation-store.php b/includes/class-translation-store.php
similarity index 87%
rename from includes/class-btranslate-translation-store.php
rename to includes/class-translation-store.php
index c73ad6d..57f5768 100644
--- a/includes/class-btranslate-translation-store.php
+++ b/includes/class-translation-store.php
@@ -2,11 +2,11 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Translation_Store {
+class HTBD_Translation_Store {
public static function table_name() {
global $wpdb;
- return $wpdb->prefix . 'btranslate_translations';
+ return $wpdb->prefix . 'hyx_bd_translations';
}
public static function install() {
@@ -15,6 +15,13 @@ class BTRANSLATE_Translation_Store {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$table_name = self::table_name();
+ $legacy_table = $wpdb->prefix . 'btranslate_translations';
+ $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Checks the plugin-owned table during activation.
+ $legacy_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $legacy_table ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Checks for the legacy plugin-owned table during activation.
+ if ( $legacy_exists === $legacy_table && $table_exists !== $table_name ) {
+ $wpdb->query( $wpdb->prepare( 'RENAME TABLE %i TO %i', $legacy_table, $table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Migrates persisted translations to the renamed table.
+ }
+
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$table_name} (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
diff --git a/includes/class-btranslate-uninstaller.php b/includes/class-uninstaller.php
similarity index 68%
rename from includes/class-btranslate-uninstaller.php
rename to includes/class-uninstaller.php
index 1694364..7de373d 100644
--- a/includes/class-btranslate-uninstaller.php
+++ b/includes/class-uninstaller.php
@@ -2,8 +2,12 @@
defined( 'ABSPATH' ) || exit;
-class BTRANSLATE_Uninstaller {
+class HTBD_Uninstaller {
private const OPTION_NAMES = array(
+ 'htbd_settings',
+ 'htbd_flush_rewrite_rules',
+ 'htbd_translation_task',
+ 'htbd_retranslation_batch',
'btranslate_settings',
'btranslate_flush_rewrite_rules',
'btranslate_translation_task',
@@ -11,6 +15,9 @@ class BTRANSLATE_Uninstaller {
);
private const CRON_HOOKS = array(
+ 'htbd_process_translation',
+ 'htbd_process_term_translation',
+ 'htbd_process_seo_output_translation',
'btranslate_process_translation',
'btranslate_process_term_translation',
'btranslate_process_seo_output_translation',
@@ -50,7 +57,12 @@ class BTRANSLATE_Uninstaller {
delete_option( $option_name );
}
- $table_name = $wpdb->prefix . 'btranslate_translations';
- $wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );
+ $table_names = array(
+ $wpdb->prefix . 'hyx_bd_translations',
+ $wpdb->prefix . 'btranslate_translations',
+ );
+ foreach ( $table_names as $table_name ) {
+ $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table_name ) );
+ }
}
}
\ No newline at end of file
diff --git a/includes/interface-btranslate-translation-provider.php b/includes/interface-translation-provider.php
similarity index 78%
rename from includes/interface-btranslate-translation-provider.php
rename to includes/interface-translation-provider.php
index 029097b..7e26bd7 100644
--- a/includes/interface-btranslate-translation-provider.php
+++ b/includes/interface-translation-provider.php
@@ -2,7 +2,7 @@
defined( 'ABSPATH' ) || exit;
-interface BTRANSLATE_Translation_Provider {
+interface HTBD_Translation_Provider {
public function get_version();
public function translate( $source_value, $source_language, $target_language, $context );
diff --git a/languages/btranslate-zh_CN.po b/languages/hyx-translator-for-baidu-translate-zh_CN.po
similarity index 87%
rename from languages/btranslate-zh_CN.po
rename to languages/hyx-translator-for-baidu-translate-zh_CN.po
index 0bf1ab1..6290f0c 100644
--- a/languages/btranslate-zh_CN.po
+++ b/languages/hyx-translator-for-baidu-translate-zh_CN.po
@@ -1,13 +1,13 @@
-# Simplified Chinese translations for Btranslate.
-# Copyright (C) 2026 Btranslate contributors
-# This file is distributed under the same license as the Btranslate package.
+# Simplified Chinese translations for HTBD.
+# Copyright (C) 2026 HTBD contributors
+# This file is distributed under the same license as the hyx-translator-for-baidu-translate package.
msgid ""
msgstr ""
-"Project-Id-Version: Btranslate 0.2.2\n"
+"Project-Id-Version: hyx-translator-for-baidu-translate 0.2.2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-07-28 14:41+0800\n"
"PO-Revision-Date: 2026-07-28 14:45+0800\n"
-"Last-Translator: Btranslate contributors\n"
+"Last-Translator: HTBD contributors\n"
"Language-Team: Chinese (Simplified)\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
@@ -15,8 +15,8 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
-msgid "Btranslate"
-msgstr "Btranslate"
+msgid "HTBD"
+msgstr "HTBD"
#, php-format
msgid "(%1$s / %2$s content items)"
@@ -74,8 +74,8 @@ msgstr "请求日志"
msgid "Log each Baidu Translate request"
msgstr "记录每次百度翻译请求"
-msgid "When enabled, fires the btranslate_translation_request_logged action with the language, field, text fingerprint, length, and result status. Credentials, source text, translated text, and full API responses are never included."
-msgstr "启用后触发 btranslate_translation_request_logged 操作,提供语言、字段、文本指纹、长度和结果状态;不会提供密钥、原文、译文或完整 API 响应。"
+msgid "When enabled, fires the htbd_translation_request_logged action with the language, field, text fingerprint, length, and result status. Credentials, source text, translated text, and full API responses are never included."
+msgstr "启用后触发 htbd_translation_request_logged 操作,提供语言、字段、文本指纹、长度和结果状态;不会提供密钥、原文、译文或完整 API 响应。"
msgid "Retranslate content"
msgstr "重新翻译内容"
diff --git a/languages/btranslate.pot b/languages/hyx-translator-for-baidu-translate.pot
similarity index 59%
rename from languages/btranslate.pot
rename to languages/hyx-translator-for-baidu-translate.pot
index 4788d90..bc8e000 100644
--- a/languages/btranslate.pot
+++ b/languages/hyx-translator-for-baidu-translate.pot
@@ -1,12 +1,12 @@
# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR Btranslate contributors
-# This file is distributed under the same license as the Btranslate package.
+# Copyright (C) YEAR HTBD contributors
+# This file is distributed under the same license as the hyx-translator-for-baidu-translate package.
# FIRST AUTHOR , YEAR.
#
#, fuzzy
msgid ""
msgstr ""
-"Project-Id-Version: Btranslate 0.2.2\n"
+"Project-Id-Version: hyx-translator-for-baidu-translate 0.2.2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-07-28 14:41+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
@@ -17,204 +17,204 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: includes/class-btranslate-admin.php:22
-msgid "Btranslate"
+#: includes/class-admin.php:22
+msgid "HTBD"
msgstr ""
-#: includes/class-btranslate-admin.php:48
+#: includes/class-admin.php:48
#, php-format
msgid "(%1$s / %2$s content items)"
msgstr ""
-#: includes/class-btranslate-admin.php:49
+#: includes/class-admin.php:49
#, php-format
msgid ""
"Latest task: %1$s. Posts and pages: %2$s / %3$s; categories and tags: %4$s / "
"%5$s. Updates automatically every 5 seconds."
msgstr ""
-#: includes/class-btranslate-admin.php:50
+#: includes/class-admin.php:50
msgid "Unable to load translation progress at this time."
msgstr ""
msgid "Failed translations"
msgstr ""
-#: includes/class-btranslate-admin.php:95
+#: includes/class-admin.php:95
msgid "Source language"
msgstr ""
-#: includes/class-btranslate-admin.php:95
+#: includes/class-admin.php:95
msgid "Use a Baidu Translate language code, for example zh."
msgstr ""
-#: includes/class-btranslate-admin.php:96
+#: includes/class-admin.php:96
msgid "Target languages"
msgstr ""
-#: includes/class-btranslate-admin.php:96
+#: includes/class-admin.php:96
msgid "Separate multiple language codes with commas, for example en,ja."
msgstr ""
-#: includes/class-btranslate-admin.php:97
+#: includes/class-admin.php:97
msgid "URL mode"
msgstr ""
-#: includes/class-btranslate-admin.php:97
+#: includes/class-admin.php:97
msgid "Subdirectory"
msgstr ""
-#: includes/class-btranslate-admin.php:97
+#: includes/class-admin.php:97
msgid "Domain"
msgstr ""
-#: includes/class-btranslate-admin.php:98
+#: includes/class-admin.php:98
msgid "Domain bindings"
msgstr ""
-#: includes/class-btranslate-admin.php:98
+#: includes/class-admin.php:98
msgid ""
"Enter one domain=language code pair per line, for example en.example.com=en. "
"Do not include https://, a path, or a port."
msgstr ""
-#: includes/class-btranslate-admin.php:99
+#: includes/class-admin.php:99
msgid "Baidu application ID"
msgstr ""
-#: includes/class-btranslate-admin.php:100
+#: includes/class-admin.php:100
msgid "Baidu secret key"
msgstr ""
msgid "After saving settings for the first time, manually run \"Retranslate all content\" below."
msgstr ""
-#: includes/class-btranslate-admin.php:101
+#: includes/class-admin.php:101
msgid "Request logging"
msgstr ""
-#: includes/class-btranslate-admin.php:101
+#: includes/class-admin.php:101
msgid "Log each Baidu Translate request"
msgstr ""
-#: includes/class-btranslate-admin.php:101
+#: includes/class-admin.php:101
msgid ""
-"When enabled, fires the btranslate_translation_request_logged action with "
+"When enabled, fires the htbd_translation_request_logged action with "
"the language, field, text fingerprint, length, and result status. "
"Credentials, source text, translated text, and full API responses are never "
"included."
msgstr ""
-#: includes/class-btranslate-admin.php:106
+#: includes/class-admin.php:106
msgid "Retranslate content"
msgstr ""
-#: includes/class-btranslate-admin.php:107
+#: includes/class-admin.php:107
msgid ""
"Queue all published posts, pages, categories, and tags for translation again."
msgstr ""
-#: includes/class-btranslate-admin.php:108
+#: includes/class-admin.php:108
msgid "This will retranslate all content and use your API quota. Continue?"
msgstr ""
-#: includes/class-btranslate-admin.php:111
+#: includes/class-admin.php:111
msgid "Retranslate all content"
msgstr ""
-#: includes/class-btranslate-admin.php:113
+#: includes/class-admin.php:113
msgid "You can also retranslate a single content type."
msgstr ""
-#: includes/class-btranslate-admin.php:114
+#: includes/class-admin.php:114
msgid ""
"This will retranslate all posts and pages and use your API quota. Continue?"
msgstr ""
-#: includes/class-btranslate-admin.php:118
+#: includes/class-admin.php:118
msgid "Translate all posts"
msgstr ""
-#: includes/class-btranslate-admin.php:120
+#: includes/class-admin.php:120
msgid ""
"This will retranslate all categories and tags and use your API quota. "
"Continue?"
msgstr ""
-#: includes/class-btranslate-admin.php:124
+#: includes/class-admin.php:124
msgid "Translate all categories and tags"
msgstr ""
-#: includes/class-btranslate-admin.php:127
+#: includes/class-admin.php:127
msgid "Translation cache"
msgstr ""
-#: includes/class-btranslate-admin.php:128
+#: includes/class-admin.php:128
msgid ""
"After clearing the cache, the front end temporarily displays source content. "
"Baidu Translate API calls resume when content is translated again."
msgstr ""
-#: includes/class-btranslate-admin.php:129
+#: includes/class-admin.php:129
msgid ""
"This will delete all saved translations, cancel pending translation tasks, "
"and reset progress. Continue?"
msgstr ""
-#: includes/class-btranslate-admin.php:132
+#: includes/class-admin.php:132
msgid "Clear translation cache"
msgstr ""
-#: includes/class-btranslate-admin.php:135
+#: includes/class-admin.php:135
msgid "Translation progress"
msgstr ""
-#: includes/class-btranslate-admin.php:137
+#: includes/class-admin.php:137
msgid "Loading translation progress..."
msgstr ""
-#: includes/class-btranslate-admin.php:145
-#: includes/class-btranslate-admin.php:211
+#: includes/class-admin.php:145
+#: includes/class-admin.php:211
msgid "You do not have permission to perform this action."
msgstr ""
-#: includes/class-btranslate-admin.php:151
+#: includes/class-admin.php:151
msgid "Invalid translation scope."
msgstr ""
-#: includes/class-btranslate-admin.php:218
+#: includes/class-admin.php:218
msgid "Failed to clear the translation cache."
msgstr ""
-#: includes/class-btranslate-admin.php:238
+#: includes/class-admin.php:238
msgid "Settings"
msgstr ""
-#: includes/class-btranslate-admin.php:281
+#: includes/class-admin.php:281
msgid "Translation status"
msgstr ""
-#: includes/class-btranslate-admin.php:296
+#: includes/class-admin.php:296
msgid "Retranslate"
msgstr ""
-#: includes/class-btranslate-admin.php:296
+#: includes/class-admin.php:296
msgid "Translate"
msgstr ""
-#: includes/class-btranslate-admin.php:311
+#: includes/class-admin.php:311
msgid "Translated"
msgstr ""
-#: includes/class-btranslate-admin.php:311
+#: includes/class-admin.php:311
msgid "Not translated"
msgstr ""
-#: includes/class-btranslate-admin.php:313
+#: includes/class-admin.php:313
msgid "Last translated:"
msgstr ""
-#: includes/class-btranslate-admin.php:325
+#: includes/class-admin.php:325
msgid "Invalid translation request."
msgstr ""
@@ -222,30 +222,30 @@ msgstr ""
msgid "Content #%d"
msgstr ""
-#: includes/class-btranslate-admin.php:351
+#: includes/class-admin.php:351
msgid "Full translation"
msgstr ""
-#: includes/class-btranslate-admin.php:355
+#: includes/class-admin.php:355
msgid "Single post translation"
msgstr ""
-#: includes/class-btranslate-admin.php:359
+#: includes/class-admin.php:359
msgid "Posts and pages translation"
msgstr ""
-#: includes/class-btranslate-admin.php:363
+#: includes/class-admin.php:363
msgid "Categories and tags translation"
msgstr ""
-#: includes/class-btranslate-admin.php:366
+#: includes/class-admin.php:366
msgid "No translation task"
msgstr ""
-#: includes/class-btranslate-baidu-provider.php:22
+#: includes/class-baidu-provider.php:22
msgid "Baidu Translate credentials are not configured."
msgstr ""
-#: includes/class-btranslate-baidu-provider.php:52
+#: includes/class-baidu-provider.php:52
msgid "Baidu Translate returned an invalid response."
msgstr ""
diff --git a/readme-zh_CN.txt b/readme-zh_CN.txt
index 38d7db2..bdb4b04 100644
--- a/readme-zh_CN.txt
+++ b/readme-zh_CN.txt
@@ -1,6 +1,6 @@
-=== Btranslate ===
+=== HTBD ===
Contributors: hanyixuanten
-Homepage: https://github.com/hanyixuanten/btranslate
+Homepage: https://github.com/hanyixuanten/HTBD
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.1
@@ -12,31 +12,31 @@ License URI: https://www.gnu.org/licenses/gpl-3.0.html
== Description ==
-Btranslate 使用百度翻译 API 翻译 WordPress 内容,并将每个翻译结果持久化保存以供重复使用。插件支持语言子目录 URL 和语言域名绑定。
+HTBD 使用百度翻译 API 翻译 WordPress 内容,并将每个翻译结果持久化保存以供重复使用。插件支持语言子目录 URL 和语言域名绑定。
WordPress 后台界面会跟随当前 WordPress 语言:默认显示英文,WordPress 设为 `zh_CN` 时使用插件内置的简体中文翻译。
-支持的内容包括已发布文章和页面的标题、正文、摘要、图片替代文本、分类、标签及部分 SEO 字段。插件只为 `publish` 状态的文章和页面自动安排翻译。完成的翻译保存在插件自建数据表中;前端渲染只读取已保存的翻译,不会动态请求翻译服务。
+支持的内容包括已发布文章和页面的标题、正文、摘要、图片替代文本、分类、标签及部分 SEO 字段。插件只为 `publish` 状态的文章和页面自动安排翻译。完成的翻译保存在 `{$wpdb->prefix}hyx_bd_translations` 自建数据表中;启用改名后的插件时,已有 `{$wpdb->prefix}btranslate_translations` 数据会自动迁移。前端渲染只读取已保存的翻译,不会动态请求翻译服务。
子目录路由支持 `/en/example-post/` 等路径。域名路由可将配置的主机名映射到目标语言。翻译失败不会中断页面请求;没有有效译文时会回退显示源语言内容。
== Installation ==
-1. 将 `btranslate` 目录上传到 `/wp-content/plugins/`。
-2. 在 WordPress 的“插件”页面启用 Btranslate。
-3. 打开“设置 > Btranslate”,配置百度翻译凭据、源语言、目标语言和路由模式。
+1. 将 `hyx-translator-for-baidu-translate` 目录上传到 `/wp-content/plugins/`。
+2. 在 WordPress 的“插件”页面启用 HTBD。
+3. 打开“设置 > HTBD”,配置百度翻译凭据、源语言、目标语言和路由模式。
4. 第一次保存设置后,手动执行“重新翻译所有内容”,为已有内容安排翻译任务。
5. 此后保存文章或页面时,插件会自动安排翻译任务。
== External Services ==
-Btranslate 连接由百度提供的百度翻译开放平台 API,以翻译 WordPress 内容。没有该外部服务,插件无法生成新的翻译。站点管理员需要百度翻译账户、应用 ID 和密钥;百度可能根据管理员选择的服务方案实施请求配额或收取使用费用。
+HTBD 连接由百度提供的百度翻译开放平台 API,以翻译 WordPress 内容。没有该外部服务,插件无法生成新的翻译。站点管理员需要百度翻译账户、应用 ID 和密钥;百度可能根据管理员选择的服务方案实施请求配额或收取使用费用。
已发布文章或页面保存后、支持的分类或标签创建或编辑后,或者管理员明确安排或刷新翻译时,计划任务会请求该 API。前端页面访问只读取已保存的翻译,不会请求百度。已有有效持久化翻译时也不会请求百度,除非管理员明确执行重新翻译。
每次翻译请求会发送待翻译文本、配置的源语言和目标语言代码、百度应用 ID、随机盐值和请求签名。根据待翻译内容,文本可能包含已发布文章或页面的标题、正文、摘要、指定 SEO 标题和描述、附件图片替代文本,以及分类或标签的名称和描述。作为 HTTPS 请求的一部分,百度也能看到来源服务器 IP 等标准网络信息。密钥只在本地用于生成签名,不会作为独立请求字段发送。
-Btranslate 将百度返回的译文保存在 WordPress 数据库中,但不保存完整百度响应。发送给百度的数据受百度自身条款和隐私规则约束:
+HTBD 将百度返回的译文保存在 WordPress 数据库中,但不保存完整百度响应。发送给百度的数据受百度自身条款和隐私规则约束:
* 百度翻译 API 文档:https://fanyi-api.baidu.com/doc/23
* 百度翻译开放平台服务协议:https://fanyi-api.baidu.com/doc/6
diff --git a/readme.txt b/readme.txt
index c1d58fd..cff8b7d 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,6 +1,6 @@
-=== Btranslate ===
+=== HTBD ===
Contributors: hanyixuanten
-Homepage: https://github.com/hanyixuanten/btranslate
+Homepage: https://github.com/hanyixuanten/HTBD
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.1
@@ -12,30 +12,30 @@ Persistent multilingual WordPress translations powered by the Baidu Translate AP
== Description ==
-Btranslate translates supported WordPress content with the Baidu Translate API and persists each translation for reuse. It supports language-specific subdirectory URLs and domain bindings.
+HTBD translates supported WordPress content with the Baidu Translate API and persists each translation for reuse. It supports language-specific subdirectory URLs and domain bindings.
The WordPress admin interface follows the current WordPress locale. English is the default, and a bundled Simplified Chinese translation is used when WordPress is set to `zh_CN`.
-Supported values include published post and page titles, content, excerpts, image alternative text, categories, tags, and selected SEO fields. Automatic translation is only scheduled for posts and pages with the `publish` status. Completed translations are stored in the plugin's custom database table. Front-end rendering reuses stored values and never calls the translation provider dynamically.
+Supported values include published post and page titles, content, excerpts, image alternative text, categories, tags, and selected SEO fields. Automatic translation is only scheduled for posts and pages with the `publish` status. Completed translations are stored in the `{$wpdb->prefix}hyx_bd_translations` custom database table. Existing `{$wpdb->prefix}btranslate_translations` data is migrated when the renamed plugin is activated. Front-end rendering reuses stored values and never calls the translation provider dynamically.
Subdirectory routing supports paths such as `/en/example-post/`. Domain routing maps configured hostnames to target languages. Translation failures are non-fatal and fall back to source-language content.
== Installation ==
-1. Upload the `btranslate` directory to `/wp-content/plugins/`.
-2. Activate Btranslate through the Plugins screen in WordPress.
-3. Open Settings > Btranslate and configure the Baidu credentials, languages, and routing mode.
+1. Upload the `hyx-translator-for-baidu-translate` directory to `/wp-content/plugins/`.
+2. Activate HTBD through the Plugins screen in WordPress.
+3. Open Settings > HTBD and configure the Baidu credentials, languages, and routing mode.
4. After saving settings for the first time, manually run Retranslate all content to queue existing content.
== External Services ==
-Btranslate connects to the Baidu Translate Open Platform API, a service provided by Baidu, to translate WordPress content. The plugin cannot generate new translations without this service. A Baidu Translate account, application ID, and secret key are required. Baidu may apply request quotas or usage charges according to the service plan selected by the site administrator.
+HTBD connects to the Baidu Translate Open Platform API, a service provided by Baidu, to translate WordPress content. The plugin cannot generate new translations without this service. A Baidu Translate account, application ID, and secret key are required. Baidu may apply request quotas or usage charges according to the service plan selected by the site administrator.
The API is contacted by scheduled tasks after a published post or page is saved, after a supported category or tag is created or edited, or after an administrator explicitly queues or refreshes translations. Front-end page views reuse stored translations and do not contact Baidu. The plugin also makes no Baidu request when valid persisted translations are already available, unless an administrator explicitly requests a refresh.
For each translation request, the plugin sends the text being translated, the configured source and target language codes, the Baidu application ID, a random salt, and a request signature. Depending on the content being translated, the text may contain published post or page titles, body text, excerpts, selected SEO title and description values, attached image alternative text, and category or tag names and descriptions. Standard network information, including the originating server IP address, is also visible to Baidu as part of the HTTPS request. The secret key is used locally to create the signature and is not sent as a separate request field.
-Btranslate stores the returned translated text in the WordPress database but does not store complete Baidu response payloads. Data sent to Baidu is subject to Baidu's own terms and privacy practices:
+HTBD stores the returned translated text in the WordPress database but does not store complete Baidu response payloads. Data sent to Baidu is subject to Baidu's own terms and privacy practices:
* Baidu Translate API documentation: https://fanyi-api.baidu.com/doc/23
* Baidu Translate Open Platform service agreement: https://fanyi-api.baidu.com/doc/6
diff --git a/uninstall.php b/uninstall.php
index e1f7a7f..157902b 100644
--- a/uninstall.php
+++ b/uninstall.php
@@ -1,14 +1,14 @@