Files
4thCafeandClaude Fable 5 7b31cb53be 翻訳機能を追加(チップ下に表示・言語自動検出)
- 各タグチップの2段目に「訳」ボタン+翻訳表示(チップを常時2行化)
- 言語自動検出: 日本語タグ→英訳を表示、英語タグ→何もしない
- バックエンドは Google(deep-translator, APIキー不要)優先 + argostranslate
  (オフライン)フォールバック。エスケープ括弧を除去して翻訳精度向上
- server.py: /prompt_tag_editor/translate ルート、requirements追記

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 03:14:40 +09:00

25 lines
832 B
JavaScript

// translate.js — バックエンド翻訳ルートの呼び出し
// ComfyUI-PromptTagEditor / 4thCafe
import { api } from "../../scripts/api.js";
// tags(文字列配列)を from→to 翻訳して返す。失敗時は null。
export async function translateTags(tags, from = "en", to = "ja") {
try {
const resp = await api.fetchApi("/prompt_tag_editor/translate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ tags, from, to }),
});
if (!resp.ok) {
console.warn("[PromptTagEditor] translate HTTP", resp.status);
return null;
}
const data = await resp.json();
return Array.isArray(data.translations) ? data.translations : null;
} catch (e) {
console.warn("[PromptTagEditor] translate failed:", e);
return null;
}
}