fix: no longer apply filter on posts
because it will, unfortunately, interfere with automatic excerpt generators on various themes
This commit is contained in:
parent
96729df900
commit
85e430da57
@ -1,3 +1,44 @@
|
||||
const controlHtml = `
|
||||
<div class="d-l10n-control-box">
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-translation-mode" class="d-l10n-control-box-item-label">翻译模式</label>
|
||||
<select id="d-l10n-translation-mode">
|
||||
<option value="writer">使用作者翻译</option>
|
||||
<option value="canonical">使用共识性翻译</option>
|
||||
<option value="original">显示原文</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="d-l10n-control-box-vertical-divider"></span>
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-annotation-mode" class="d-l10n-control-box-item-label">注释模式</label>
|
||||
<select id="d-l10n-annotation-mode">
|
||||
<option value="hide">不显示</option>
|
||||
<option value="parenthesis">括号内显示原文</option>
|
||||
<option value="ruby">注音形式显示原文</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>`
|
||||
const controlHtmlEn = `
|
||||
<div class="d-l10n-control-box">
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-translation-mode" class="d-l10n-control-box-item-label">Translation Mode</label>
|
||||
<select id="d-l10n-translation-mode">
|
||||
<option value="writer">Use Writer's Translation</option>
|
||||
<option value="canonical">Use Canonical Translation</option>
|
||||
<option value="original">Show Original</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="d-l10n-control-box-vertical-divider"></span>
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-annotation-mode" class="d-l10n-control-box-item-label">Annotation Mode</label>
|
||||
<select id="d-l10n-annotation-mode">
|
||||
<option value="hide">Hide</option>
|
||||
<option value="parenthesis">Append Original in Parentheses</option>
|
||||
<option value="ruby">Show Original in Ruby</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>`
|
||||
|
||||
function isCjkContext(str) {
|
||||
// since js regex does not support 5-digit hex unicode
|
||||
// we will have to check for the range ourselves
|
||||
@ -37,6 +78,17 @@ function isCjkContext(str) {
|
||||
}
|
||||
|
||||
function setupControls() {
|
||||
const articleBody = document.querySelector('article')
|
||||
if (articleBody == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.documentElement.lang.startsWith('zh')) {
|
||||
articleBody.insertAdjacentHTML('beforebegin', controlHtml)
|
||||
} else {
|
||||
articleBody.insertAdjacentHTML('beforebegin', controlHtmlEn)
|
||||
}
|
||||
|
||||
const translationModeBox = document.getElementById('d-l10n-translation-mode')
|
||||
const annotationModeBox = document.getElementById('d-l10n-annotation-mode')
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Plugin Name: Daniel's Localization Tool
|
||||
* Plugin URI: https://git.dsstudio.com/dousha/wp-l10n-tool
|
||||
* Description: A Simple Localization Tool
|
||||
* Version: 1.0.1
|
||||
* Version: 1.0.2
|
||||
* Author: dousha
|
||||
* Author URI: https://dsstudio.tech/
|
||||
* License: MIT
|
||||
@ -24,7 +24,7 @@ function d_l10n_add_shortcodes(): void
|
||||
function d_l10n_enque_assets(): void
|
||||
{
|
||||
wp_enqueue_style('d-l10n-translate-style', plugins_url('/assets/css/style.css', __FILE__), [], '0.1.1');
|
||||
wp_enqueue_script('d-l10n-translate-script', plugins_url('/assets/js/work.js', __FILE__), [], '0.1.1');
|
||||
wp_enqueue_script('d-l10n-translate-script', plugins_url('/assets/js/work.js', __FILE__), [], '0.1.2');
|
||||
}
|
||||
|
||||
function d_l10n_evaluate_truthiness($val): bool
|
||||
@ -143,62 +143,5 @@ function d_l10n_color_shortcode($attr = array(), $content = null, $tag = ''): ?s
|
||||
return '<span class="d-l10n-color" data-color="' . $color . '">' . $content . '</span>';
|
||||
}
|
||||
|
||||
function d_l10n_add_translation_controls($content): string
|
||||
{
|
||||
$controlHtml = <<<HTML
|
||||
<div class="d-l10n-control-box">
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-translation-mode" class="d-l10n-control-box-item-label">翻译模式</label>
|
||||
<select id="d-l10n-translation-mode">
|
||||
<option value="writer">使用作者翻译</option>
|
||||
<option value="canonical">使用共识性翻译</option>
|
||||
<option value="original">显示原文</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="d-l10n-control-box-vertical-divider"></span>
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-annotation-mode" class="d-l10n-control-box-item-label">注释模式</label>
|
||||
<select id="d-l10n-annotation-mode">
|
||||
<option value="hide">不显示</option>
|
||||
<option value="parenthesis">括号内显示原文</option>
|
||||
<option value="ruby">注音形式显示原文</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$controlHtmlEn = <<<HTML
|
||||
<div class="d-l10n-control-box">
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-translation-mode" class="d-l10n-control-box-item-label">Translation Mode</label>
|
||||
<select id="d-l10n-translation-mode">
|
||||
<option value="writer">Use Writer's Translation</option>
|
||||
<option value="canonical">Use Canonical Translation</option>
|
||||
<option value="original">Show Original</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="d-l10n-control-box-vertical-divider"></span>
|
||||
<div class="d-l10n-control-box-item">
|
||||
<label for="d-l10n-annotation-mode" class="d-l10n-control-box-item-label">Annotation Mode</label>
|
||||
<select id="d-l10n-annotation-mode">
|
||||
<option value="hide">Hide</option>
|
||||
<option value="parenthesis">Append Original in Parentheses</option>
|
||||
<option value="ruby">Show Original in Ruby</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$lang = get_bloginfo('language');
|
||||
if (str_contains($lang, 'zh')) {
|
||||
$content = $controlHtml . $content;
|
||||
} else {
|
||||
$content = $controlHtmlEn . $content;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
add_action('init', 'd_l10n_add_shortcodes');
|
||||
add_action('init', 'd_l10n_enque_assets');
|
||||
add_filter('the_content', 'd_l10n_add_translation_controls');
|
||||
|
Loading…
Reference in New Issue
Block a user