mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix(i18n): preserve native placeholders and whitespace
This commit is contained in:
@@ -608,6 +608,7 @@ function buildSystemPrompt(targetLocale: string, glossary: readonly GlossaryEntr
|
||||
"- The JSON must be an object whose keys exactly match the provided ids.",
|
||||
"- Translate all English prose; keep code, URLs, product names, CLI commands, config keys, and env vars in English.",
|
||||
"- Preserve placeholders exactly, including {count}, {time}, {shown}, {total}, and similar tokens.",
|
||||
"- Preserve Swift interpolation expressions such as \\(name) exactly, including the backslash and parentheses.",
|
||||
"- Preserve punctuation, ellipses, arrows, and casing when they are part of literal UI text.",
|
||||
"- Preserve Markdown, inline code, HTML tags, and slash commands when present.",
|
||||
"- Use fluent, neutral product UI language.",
|
||||
|
||||
@@ -62,6 +62,19 @@ const EXCLUDED_PATH_RE =
|
||||
/(?:^|[\\/])(?:Tests?|UITests?|test|Preview(?:s)?)(?:$|[\\/])/u;
|
||||
const EXCLUDED_FILE_RE = /(?:Tests?|UITests?|Previews?|Testing)\.(?:swift|kt|kts)$/u;
|
||||
|
||||
function hasUnbalancedSwiftInterpolation(source: string): boolean {
|
||||
let depth = 0;
|
||||
for (let index = 0; index < source.length; index += 1) {
|
||||
if (source[index] === "\\" && source[index + 1] === "(") {
|
||||
depth += 1;
|
||||
index += 1;
|
||||
} else if (depth > 0 && source[index] === ")") {
|
||||
depth -= 1;
|
||||
}
|
||||
}
|
||||
return depth !== 0;
|
||||
}
|
||||
|
||||
function lineNumber(source: string, offset: number): number {
|
||||
return source.slice(0, offset).split("\n").length;
|
||||
}
|
||||
@@ -75,7 +88,7 @@ function decodeLiteral(raw: string): string {
|
||||
}
|
||||
|
||||
function normalizeSource(source: string): string {
|
||||
return source.replace(/\s+/gu, " ").trim();
|
||||
return source.replace(/[ \t]+/gu, " ").trim();
|
||||
}
|
||||
|
||||
function addCandidate(
|
||||
@@ -90,7 +103,11 @@ function addCandidate(
|
||||
if (!normalized || !/\p{L}/u.test(normalized)) {
|
||||
return;
|
||||
}
|
||||
if (normalized.length > 500 || normalized.includes("${") || normalized.includes("\\(")) {
|
||||
if (
|
||||
normalized.length > 500 ||
|
||||
normalized.includes("${") ||
|
||||
hasUnbalancedSwiftInterpolation(normalized)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
entries.push({ kind, line, path: repoPath, source: normalized, surface });
|
||||
|
||||
Reference in New Issue
Block a user