fix(i18n): refine Chinese prose and prompt validation

This commit is contained in:
Tianyi Cui
2026-07-15 20:39:24 +08:00
parent 168a3b9fe7
commit 3383c20c63
12 changed files with 42 additions and 26 deletions

View File

@@ -82,6 +82,10 @@ export function renderTranslationPrompt(document: string, input: TranslationProm
source_filename_zh: sourceFilenameZh,
}
const template = extractTranslationPrompt(document)
const placeholderFreeTemplate = template.replace(PLACEHOLDER, '')
if (placeholderFreeTemplate.includes('{{') || placeholderFreeTemplate.includes('}}')) {
throw new Error('translation prompt: template contains malformed placeholder syntax')
}
const names = [...template.matchAll(PLACEHOLDER)].map(match => match[1] ?? '')
const unknown = names.filter(name => !TRANSLATION_PROMPT_PLACEHOLDERS.includes(name as TranslationPromptPlaceholder))
if (unknown.length > 0) throw new Error(`translation prompt: unsupported placeholder(s): ${[...new Set(unknown)].join(', ')}`)