From 6290dff3d904aefcf9ba5a0dc74c3449c9f03b68 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Thu, 11 Apr 2024 22:09:05 +0300
Subject: [PATCH] #2065 Add option to translate text before classification
---
public/scripts/extensions/expressions/index.js | 8 ++++++++
public/scripts/extensions/expressions/settings.html | 4 ++++
public/scripts/extensions/translate/index.js | 2 ++
3 files changed, 14 insertions(+)
diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js
index 4ee04f552..d4573554a 100644
--- a/public/scripts/extensions/expressions/index.js
+++ b/public/scripts/extensions/expressions/index.js
@@ -977,6 +977,10 @@ async function getExpressionLabel(text) {
return getFallbackExpression();
}
+ if (extension_settings.expressions.translate && typeof window['translate'] === 'function') {
+ text = await window['translate'](text, 'en');
+ }
+
text = sampleClassifyText(text);
try {
@@ -1717,6 +1721,10 @@ async function fetchImagesNoCache() {
$('#expressions_show_default').on('input', onExpressionsShowDefaultInput);
$('#expression_upload_pack_button').on('click', onClickExpressionUploadPackButton);
$('#expressions_show_default').prop('checked', extension_settings.expressions.showDefault).trigger('input');
+ $('#expression_translate').prop('checked', extension_settings.expressions.translate).on('input', function () {
+ extension_settings.expressions.translate = !!$(this).prop('checked');
+ saveSettingsDebounced();
+ });
$('#expression_local').prop('checked', extension_settings.expressions.local).on('input', function () {
extension_settings.expressions.local = !!$(this).prop('checked');
moduleWorker();
diff --git a/public/scripts/extensions/expressions/settings.html b/public/scripts/extensions/expressions/settings.html
index 4abc49fcc..b0b3b0bd3 100644
--- a/public/scripts/extensions/expressions/settings.html
+++ b/public/scripts/extensions/expressions/settings.html
@@ -10,6 +10,10 @@
Local server classification
+