Skip to content

Commit 6257ed1

Browse files
committed
feat: Enhance translation object structure to include placeholders in generated JSON
1 parent e32e20a commit 6257ed1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/commands/other/translate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = async function translateHtml(html, languages, options = {}) {
7878
async function generateTranslationObject(html, model, languages) {
7979
const langList = languages.map((l) => `"${l}"`).join(", ");
8080
const prompt = `
81-
You are an expert web localization AI. Given the following HTML file, extract all translatable content (titles, meta tags, headers, buttons, video/image alt/title, labels, aria-label, and all aria-* attributes) and generate a JSON object in the following format:
81+
You are an expert web localization AI. Given the following HTML file, extract all translatable content (titles, meta tags, headers, buttons, video/image alt/title, labels, aria-label, all aria-* attributes, and placeholders) and generate a JSON object in the following format:
8282
8383
{
8484
"translations": [
@@ -100,7 +100,8 @@ You are an expert web localization AI. Given the following HTML file, extract al
100100
"label": { ${langList} },
101101
"aria-label": { ${langList} },
102102
"aria-*": { ${langList} },
103-
"title": { ${langList} }
103+
"title": { ${langList} },
104+
"placeholder": { ${langList} }
104105
}
105106
},
106107
// Example for structured data translation:
@@ -117,7 +118,7 @@ You are an expert web localization AI. Given the following HTML file, extract al
117118
]
118119
}
119120
120-
Do not add any extra keys or key names not shown in this structure. Only use the keys: name, directory, path, content-type, translations, selector, innerHTML, attributes, alt, label, aria-label, aria-*, title, and the language codes (${languages.join(
121+
Do not add any extra keys or key names not shown in this structure. Only use the keys: name, directory, path, content-type, translations, selector, innerHTML, attributes, alt, label, aria-label, aria-*, title, placeholder, and the language codes (${languages.join(
121122
", "
122123
)}).
123124
@@ -137,7 +138,7 @@ ${html}
137138
jsonText = jsonText
138139
.replace(/^```json\s*([\s\S]*?)\s*```$/i, "$1")
139140
.trim();
140-
return JSON.parse(jsonText);
141+
return JSON.parse(jsonText).translations;
141142
} catch (err) {
142143
console.error(`AI error:`, err);
143144
return null;

0 commit comments

Comments
 (0)