diff --git a/assets/js/work.js b/assets/js/work.js
index 3e36795..e2a31b7 100644
--- a/assets/js/work.js
+++ b/assets/js/work.js
@@ -1,3 +1,44 @@
+const controlHtml = `
+
+
+
+
+
+
+
+
+
+
+
`
+const controlHtmlEn = `
+
+
+
+
+
+
+
+
+
+
+
`
+
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')
diff --git a/shortcode.php b/shortcode.php
index 1de293e..317144b 100644
--- a/shortcode.php
+++ b/shortcode.php
@@ -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 '' . $content . '';
}
-function d_l10n_add_translation_controls($content): string
-{
- $controlHtml = <<
-
-
-
-
-
-
-
-
-
-
- HTML;
-
- $controlHtmlEn = <<
-
-
-
-
-
-
-
-
-
-
- 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');