260 lines
13 KiB
JavaScript
260 lines
13 KiB
JavaScript
/**
|
||
* scripts/merge-schedule-form-i18n.mjs
|
||
* 合并排程创建/编辑弹窗与 Dify 快照相关文案至各语言 admin.json
|
||
*/
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||
const localesRoot = path.resolve(__dirname, '../src/locales');
|
||
|
||
const patches = {
|
||
en: {
|
||
form: {
|
||
dsDbType: 'Database type',
|
||
dsHost: 'Host',
|
||
dsHostPlaceholder: 'e.g. 192.168.1.100 or ${SRM_SQLSERVER_HOST}',
|
||
dsPort: 'Port',
|
||
dsDatabase: 'Database',
|
||
dsDatabasePlaceholder: 'Database name',
|
||
dsUsername: 'Username',
|
||
dsPassword: 'Password',
|
||
dsPasswordPlaceholder: 'or ${ENV_VAR}',
|
||
dsDriver: 'ODBC driver',
|
||
dsEncrypt: 'Encrypt',
|
||
dsTrustCert: 'TrustServerCertificate',
|
||
defaultNo: 'Default (no)',
|
||
defaultYes: 'Default (yes)',
|
||
envVarHint: 'Values support {token} format and are resolved from environment variables at runtime (recommended for passwords).',
|
||
envVarToken: '${ENV_VAR_NAME}',
|
||
baseFetchSql: 'Base fetch SQL (base_fetch_sql) — SELECT + FROM + JOIN only, no WHERE',
|
||
fetchWhereConditions: 'WHERE clause (fetch_where_conditions) — edit to test different filters',
|
||
fetchOrderBy: 'Order by (fetch_order_by)',
|
||
detailSql: 'Detail SQL (detail_sql)',
|
||
writebackSql: 'Writeback SQL (writeback_sql)',
|
||
rowIdKey: 'Row ID key (row_id_key)',
|
||
logPrefix: 'Log prefix (log_prefix)',
|
||
aliasOrder: 'Field order (alias_order) — comma-separated',
|
||
detailAliasOrder: 'Detail field order (detail_alias_order) — comma-separated',
|
||
headerLabels: 'Header labels (header_labels) — JSON',
|
||
apiUrl: 'API URL',
|
||
apiMethod: 'HTTP method',
|
||
apiTimeoutSeconds: 'Timeout (seconds)',
|
||
apiHeaders: 'Request headers (Headers) — JSON',
|
||
apiBodyTemplate: 'Request body template (Body)',
|
||
agentLabel: 'Agent',
|
||
agentOptionId: ' (ID: {id})',
|
||
difySystemPrompt: 'Dify System Prompt',
|
||
difySystemPromptHint: 'Available when a Dify Agent is enabled. Saved as system_prompt in the Workflow; LLM nodes must reference this variable.',
|
||
difySystemPromptPlaceholder:
|
||
'e.g. You are a material compliance assistant. Based on record test data, return JSON with dify_result (pass/fail/manual review) and dify_message.',
|
||
},
|
||
difySnapshot: {
|
||
title: 'Dify execution snapshot (audit)',
|
||
agent: 'Agent',
|
||
agentId: ' (ID: {id})',
|
||
difyAppId: 'Dify App ID',
|
||
systemPrompt: 'System Prompt',
|
||
notConfigured: '(Not configured)',
|
||
notConfiguredUseDefault: '(Not configured; using Dify workflow default prompt)',
|
||
notEnabledTest: 'Dify was not enabled for this test',
|
||
notEnabledRun: 'Dify Agent was not enabled for this run',
|
||
},
|
||
testRun: {
|
||
baseFetchSqlReadonly: 'Base fetch SQL (base_fetch_sql) — read-only',
|
||
limitRows: 'Row limit (limit)',
|
||
},
|
||
},
|
||
'zh-CN': {
|
||
form: {
|
||
dsDbType: '数据库类型',
|
||
dsHost: '主机地址',
|
||
dsHostPlaceholder: '如 192.168.1.100 或 ${SRM_SQLSERVER_HOST}',
|
||
dsPort: '端口',
|
||
dsDatabase: '数据库',
|
||
dsDatabasePlaceholder: '数据库名',
|
||
dsUsername: '用户名',
|
||
dsPassword: '密码',
|
||
dsPasswordPlaceholder: '或 ${ENV_VAR}',
|
||
dsDriver: 'ODBC 驱动',
|
||
dsEncrypt: 'Encrypt',
|
||
dsTrustCert: 'TrustServerCertificate',
|
||
defaultNo: '默认 (no)',
|
||
defaultYes: '默认 (yes)',
|
||
envVarHint: '值支持 {token} 格式,运行时自动从环境变量解析(推荐密码使用此方式)',
|
||
envVarToken: '${环境变量名}',
|
||
baseFetchSql: '基础查询 SQL (base_fetch_sql) — SELECT + FROM + JOIN 部分,不含 WHERE',
|
||
fetchWhereConditions: 'WHERE 条件 (fetch_where_conditions) — 可修改以测试不同筛选条件',
|
||
fetchOrderBy: '排序 (fetch_order_by)',
|
||
detailSql: '明细 SQL (detail_sql)',
|
||
writebackSql: '回写 SQL (writeback_sql)',
|
||
rowIdKey: '主键字段 (row_id_key)',
|
||
logPrefix: '日志前缀 (log_prefix)',
|
||
aliasOrder: '字段顺序 (alias_order) — 逗号分隔',
|
||
detailAliasOrder: '明细字段顺序 (detail_alias_order) — 逗号分隔',
|
||
headerLabels: '表头标签 (header_labels) — JSON 格式',
|
||
apiUrl: 'API 地址',
|
||
apiMethod: '请求方法',
|
||
apiTimeoutSeconds: '超时(秒)',
|
||
apiHeaders: '请求头 (Headers) — JSON 格式',
|
||
apiBodyTemplate: '请求体模板 (Body)',
|
||
agentLabel: 'Agent',
|
||
agentOptionId: '(ID: {id})',
|
||
difySystemPrompt: 'Dify System Prompt',
|
||
difySystemPromptHint:
|
||
'仅在启用 Dify Agent 时可配置。保存后将作为 system_prompt 传入 Workflow;编排中 LLM 节点需引用该变量。',
|
||
difySystemPromptPlaceholder:
|
||
'例如:你是物料合规判定助手。根据 record 中的检测数据判定是否合格,仅返回 JSON:dify_result(合格/不合格/人工判定)与 dify_message。',
|
||
},
|
||
difySnapshot: {
|
||
title: 'Dify 执行快照(审计)',
|
||
agent: 'Agent',
|
||
agentId: '(ID: {id})',
|
||
difyAppId: 'Dify App ID',
|
||
systemPrompt: 'System Prompt',
|
||
notConfigured: '(未配置)',
|
||
notConfiguredUseDefault: '(未配置,使用 Dify 编排内默认提示词)',
|
||
notEnabledTest: '本次测试未启用 Dify',
|
||
notEnabledRun: '本次执行未启用 Dify Agent',
|
||
},
|
||
testRun: {
|
||
baseFetchSqlReadonly: '基础查询 SQL (base_fetch_sql) — 只读',
|
||
limitRows: '限制行数 (limit)',
|
||
},
|
||
},
|
||
'zh-TW': {
|
||
form: {
|
||
dsDbType: '資料庫類型',
|
||
dsHost: '主機位址',
|
||
dsHostPlaceholder: '如 192.168.1.100 或 ${SRM_SQLSERVER_HOST}',
|
||
dsPort: '連接埠',
|
||
dsDatabase: '資料庫',
|
||
dsDatabasePlaceholder: '資料庫名稱',
|
||
dsUsername: '使用者名稱',
|
||
dsPassword: '密碼',
|
||
dsPasswordPlaceholder: '或 ${ENV_VAR}',
|
||
dsDriver: 'ODBC 驅動',
|
||
dsEncrypt: 'Encrypt',
|
||
dsTrustCert: 'TrustServerCertificate',
|
||
defaultNo: '預設 (no)',
|
||
defaultYes: '預設 (yes)',
|
||
envVarHint: '值支援 {token} 格式,執行時自動從環境變數解析(建議密碼使用此方式)',
|
||
envVarToken: '${環境變數名}',
|
||
baseFetchSql: '基礎查詢 SQL (base_fetch_sql) — SELECT + FROM + JOIN 部分,不含 WHERE',
|
||
fetchWhereConditions: 'WHERE 條件 (fetch_where_conditions) — 可修改以測試不同篩選條件',
|
||
fetchOrderBy: '排序 (fetch_order_by)',
|
||
detailSql: '明細 SQL (detail_sql)',
|
||
writebackSql: '回寫 SQL (writeback_sql)',
|
||
rowIdKey: '主鍵欄位 (row_id_key)',
|
||
logPrefix: '日誌前綴 (log_prefix)',
|
||
aliasOrder: '欄位順序 (alias_order) — 逗號分隔',
|
||
detailAliasOrder: '明細欄位順序 (detail_alias_order) — 逗號分隔',
|
||
headerLabels: '表頭標籤 (header_labels) — JSON 格式',
|
||
apiUrl: 'API 位址',
|
||
apiMethod: '請求方法',
|
||
apiTimeoutSeconds: '逾時(秒)',
|
||
apiHeaders: '請求標頭 (Headers) — JSON 格式',
|
||
apiBodyTemplate: '請求體模板 (Body)',
|
||
agentLabel: 'Agent',
|
||
agentOptionId: '(ID: {id})',
|
||
difySystemPrompt: 'Dify System Prompt',
|
||
difySystemPromptHint:
|
||
'僅在啟用 Dify Agent 時可配置。保存後將作為 system_prompt 傳入 Workflow;編排中 LLM 節點需引用該變數。',
|
||
difySystemPromptPlaceholder:
|
||
'例如:你是物料合規判定助手。根據 record 中的檢測資料判定是否合格,僅返回 JSON:dify_result(合格/不合格/人工判定)與 dify_message。',
|
||
},
|
||
difySnapshot: {
|
||
title: 'Dify 執行快照(審計)',
|
||
agent: 'Agent',
|
||
agentId: '(ID: {id})',
|
||
difyAppId: 'Dify App ID',
|
||
systemPrompt: 'System Prompt',
|
||
notConfigured: '(未配置)',
|
||
notConfiguredUseDefault: '(未配置,使用 Dify 編排內預設提示詞)',
|
||
notEnabledTest: '本次測試未啟用 Dify',
|
||
notEnabledRun: '本次執行未啟用 Dify Agent',
|
||
},
|
||
testRun: {
|
||
baseFetchSqlReadonly: '基礎查詢 SQL (base_fetch_sql) — 唯讀',
|
||
limitRows: '限制行數 (limit)',
|
||
},
|
||
},
|
||
th: {
|
||
form: {
|
||
dsDbType: 'ประเภทฐานข้อมูล',
|
||
dsHost: 'โฮสต์',
|
||
dsHostPlaceholder: 'เช่น 192.168.1.100 หรือ ${SRM_SQLSERVER_HOST}',
|
||
dsPort: 'พอร์ต',
|
||
dsDatabase: 'ฐานข้อมูล',
|
||
dsDatabasePlaceholder: 'ชื่อฐานข้อมูล',
|
||
dsUsername: 'ชื่อผู้ใช้',
|
||
dsPassword: 'รหัสผ่าน',
|
||
dsPasswordPlaceholder: 'หรือ ${ENV_VAR}',
|
||
dsDriver: 'ไดรเวอร์ ODBC',
|
||
dsEncrypt: 'Encrypt',
|
||
dsTrustCert: 'TrustServerCertificate',
|
||
defaultNo: 'ค่าเริ่มต้น (no)',
|
||
defaultYes: 'ค่าเริ่มต้น (yes)',
|
||
envVarHint: 'รองรับรูปแบบ {token} และจะถูกแก้จากตัวแปรสภาพแวดล้อมขณะรัน (แนะนำสำหรับรหัสผ่าน)',
|
||
envVarToken: '${ชื่อตัวแปรสภาพแวดล้อม}',
|
||
baseFetchSql: 'SQL ดึงข้อมูลพื้นฐาน (base_fetch_sql) — เฉพาะ SELECT + FROM + JOIN ไม่รวม WHERE',
|
||
fetchWhereConditions: 'เงื่อนไข WHERE (fetch_where_conditions) — แก้ไขเพื่อทดสอบตัวกรอง',
|
||
fetchOrderBy: 'เรียงลำดับ (fetch_order_by)',
|
||
detailSql: 'SQL รายละเอียด (detail_sql)',
|
||
writebackSql: 'SQL เขียนกลับ (writeback_sql)',
|
||
rowIdKey: 'คีย์แถว (row_id_key)',
|
||
logPrefix: 'คำนำหน้าบันทึก (log_prefix)',
|
||
aliasOrder: 'ลำดับฟิลด์ (alias_order) — คั่นด้วยจุลภาค',
|
||
detailAliasOrder: 'ลำดับฟิลด์รายละเอียด (detail_alias_order) — คั่นด้วยจุลภาค',
|
||
headerLabels: 'ป้ายหัวตาราง (header_labels) — JSON',
|
||
apiUrl: 'URL ของ API',
|
||
apiMethod: 'วิธี HTTP',
|
||
apiTimeoutSeconds: 'หมดเวลา (วินาที)',
|
||
apiHeaders: 'ส่วนหัวคำขอ (Headers) — JSON',
|
||
apiBodyTemplate: 'เทมเพลต body คำขอ (Body)',
|
||
agentLabel: 'Agent',
|
||
agentOptionId: ' (ID: {id})',
|
||
difySystemPrompt: 'Dify System Prompt',
|
||
difySystemPromptHint:
|
||
'ใช้ได้เมื่อเปิดใช้ Dify Agent จะบันทึกเป็น system_prompt ใน Workflow; โหนด LLM ต้องอ้างอิงตัวแปรนี้',
|
||
difySystemPromptPlaceholder:
|
||
'เช่น คุณเป็นผู้ช่วยตรวจสอบความสอดคล้องของวัสดุ จากข้อมูล record ให้คืน JSON: dify_result (ผ่าน/ไม่ผ่าน/ตรวจด้วยมือ) และ dify_message',
|
||
},
|
||
difySnapshot: {
|
||
title: 'สแนปช็อตการทำงาน Dify (ตรวจสอบ)',
|
||
agent: 'Agent',
|
||
agentId: ' (ID: {id})',
|
||
difyAppId: 'Dify App ID',
|
||
systemPrompt: 'System Prompt',
|
||
notConfigured: '(ยังไม่ได้ตั้งค่า)',
|
||
notConfiguredUseDefault: '(ยังไม่ได้ตั้งค่า ใช้ prompt เริ่มต้นใน Dify workflow)',
|
||
notEnabledTest: 'การทดสอบนี้ไม่ได้เปิดใช้ Dify',
|
||
notEnabledRun: 'การรันนี้ไม่ได้เปิดใช้ Dify Agent',
|
||
},
|
||
testRun: {
|
||
baseFetchSqlReadonly: 'SQL ดึงข้อมูลพื้นฐาน (base_fetch_sql) — อ่านอย่างเดียว',
|
||
limitRows: 'จำกัดจำนวนแถว (limit)',
|
||
},
|
||
},
|
||
};
|
||
|
||
function deepMerge(target, source) {
|
||
for (const [key, value] of Object.entries(source)) {
|
||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||
target[key] = deepMerge(target[key] ?? {}, value);
|
||
} else {
|
||
target[key] = value;
|
||
}
|
||
}
|
||
return target;
|
||
}
|
||
|
||
for (const [locale, patch] of Object.entries(patches)) {
|
||
const filePath = path.join(localesRoot, locale, 'admin.json');
|
||
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||
data.schedule = deepMerge(data.schedule ?? {}, patch);
|
||
fs.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
|
||
console.log(`Updated ${filePath}`);
|
||
}
|