-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * JSON parser * YAML parser * XML parser * xCode parser * Parsers * wip * wip * wip * wip * sync * commands * wip * wip
- Loading branch information
Showing
87 changed files
with
8,369 additions
and
1,843 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { projectSettings } from "@/db/schema"; | ||
import type { PromptOptions } from "./types"; | ||
|
||
const baseRequirements = ` | ||
Translation Requirements: | ||
- Maintain exact file structure, indentation, and formatting | ||
- Provide natural, culturally-adapted translations that sound native | ||
- Keep all technical identifiers unchanged | ||
- Keep consistent capitalization, spacing, and line breaks | ||
- Respect existing whitespace and newline patterns | ||
`; | ||
|
||
export function createFinalPrompt( | ||
text: string, | ||
options: PromptOptions, | ||
settings?: Partial<typeof projectSettings.$inferSelect>, | ||
) { | ||
const basePrompt = `You are a professional translator working with JSON files. | ||
Task: Translate the content below from ${options.sourceLocale} to ${options.targetLocale}. | ||
${baseRequirements}`; | ||
|
||
const tuningInstructions = settings | ||
? [ | ||
// Style and tone settings | ||
settings.formality && `- Use ${settings.formality} language style`, | ||
settings.toneOfVoice && | ||
`- Maintain a ${settings.toneOfVoice} tone of voice`, | ||
settings.emotiveIntent && | ||
`- Convey a ${settings.emotiveIntent} emotional tone`, | ||
|
||
// Brand-specific settings | ||
settings.brandName && | ||
`- Use "${settings.brandName}" consistently for brand references`, | ||
settings.brandVoice && | ||
`- Follow brand voice guidelines: ${settings.brandVoice}`, | ||
|
||
// Technical settings | ||
settings.lengthControl && | ||
`- Apply ${settings.lengthControl} length control`, | ||
settings.domainExpertise && | ||
`- Use terminology appropriate for ${settings.domainExpertise} domain`, | ||
settings.terminology && | ||
`- Follow specific terminology: ${settings.terminology}`, | ||
|
||
// Feature flags | ||
settings.translationMemory && | ||
"- Maintain consistency with previous translations", | ||
settings.qualityChecks && | ||
"- Ensure high-quality output with proper grammar and spelling", | ||
settings.contextDetection && | ||
"- Consider surrounding context for accurate translations", | ||
settings.inclusiveLanguage && | ||
"- Use inclusive and non-discriminatory language", | ||
settings.idioms && "- Adapt idioms appropriately for target culture", | ||
] | ||
.filter(Boolean) | ||
.join("\n") | ||
: ""; | ||
|
||
return `${basePrompt}${ | ||
tuningInstructions | ||
? `\nAdditional Requirements:\n${tuningInstructions}` | ||
: "" | ||
}\n\n${text}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { openai } from "@ai-sdk/openai"; | ||
import { generateObject } from "ai"; | ||
import { z } from "zod"; | ||
import { createFinalPrompt } from "./prompt"; | ||
import type { PromptOptions } from "./types"; | ||
|
||
function getPrompt( | ||
content: Array<{ key: string; sourceText: string }>, | ||
options: PromptOptions, | ||
) { | ||
const codeblocks = content | ||
.map(({ key, sourceText }) => { | ||
return `\`\`\`json | ||
${sourceText} | ||
\`\`\``; | ||
}) | ||
.join("\n\n"); | ||
|
||
return createFinalPrompt(codeblocks, options); | ||
} | ||
|
||
export async function translate( | ||
content: Array<{ key: string; sourceText: string }>, | ||
options: PromptOptions, | ||
) { | ||
const prompt = getPrompt(content, options); | ||
|
||
const { object } = await generateObject({ | ||
model: openai("gpt-4o-mini"), | ||
prompt, | ||
mode: "json", | ||
schema: z.object({ | ||
content: z.array(z.string()), | ||
}), | ||
}); | ||
|
||
return object.content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { projectSettings } from "@/db/schema"; | ||
|
||
export type PromptOptions = { | ||
sourceLocale: string; | ||
targetLocale: string; | ||
settings?: Partial<typeof projectSettings.$inferSelect>; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.