Skip to content

Commit 43eb74e

Browse files
committed
Add option to include related strings in translation prompts
With hope of improving context for better translation. To be validated, as it could also add noise. The option --related-strings support 2 types for now: - USAGES: strings that appear together in the same source file typically, but whatever if in the usage field basically. Can be used to easily group strings from an email template - ID_PREFIX: typically the ID prefix is used in code to group strings in relevant groups. Use the prefix before the first "dot" to look up relating strings Currently limit at 10000 char for the related strings, that could be an option later.
1 parent 7bb99bf commit 43eb74e

File tree

5 files changed

+252
-63
lines changed

5 files changed

+252
-63
lines changed

cli/src/main/java/com/box/l10n/mojito/cli/command/RepositoryAiTranslationCommand.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ public class RepositoryAiTranslationCommand extends Command {
103103
"ID of an existing job to try to re-import; If a job stopped because a transient error, try to import remaining data")
104104
Long retryImportJobId;
105105

106+
@Parameter(
107+
names = "--related-strings",
108+
arity = 1,
109+
description =
110+
"Related-string mode. NONE (default) = none, "
111+
+ "USAGES = same usage context, "
112+
+ "ID_PREFIX = same key prefix")
113+
String relatedStrings = "NONE";
114+
106115
@Autowired CommandHelper commandHelper;
107116

108117
@Autowired RepositoryAiTranslateClient repositoryAiTranslateClient;
@@ -172,7 +181,8 @@ public void execute() throws CommandException {
172181
textUnitIds,
173182
useBatch,
174183
useModel,
175-
promptSuffix));
184+
promptSuffix,
185+
relatedStrings));
176186

177187
PollableTask pollableTask = protoAiTranslateResponse.pollableTask();
178188
consoleWriter.a("Running, task id: ").fg(Color.MAGENTA).a(pollableTask.getId()).println();

restclient/src/main/java/com/box/l10n/mojito/rest/client/RepositoryAiTranslateClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public record ProtoAiTranslateRequest(
4444
List<Long> tmTextUnitIds,
4545
boolean useBatch,
4646
String useModel,
47-
String promptSuffix) {}
47+
String promptSuffix,
48+
String relatedStringsType) {}
4849

4950
public record ProtoAiTranslateResponse(PollableTask pollableTask) {}
5051

webapp/src/main/java/com/box/l10n/mojito/rest/textunit/AiTranslateWS.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public ProtoAiTranslateResponse aiTranslate(
4646
protoAiTranslateRequest.tmTextUnitIds(),
4747
protoAiTranslateRequest.useBatch(),
4848
protoAiTranslateRequest.useModel(),
49-
protoAiTranslateRequest.promptSuffix()));
49+
protoAiTranslateRequest.promptSuffix(),
50+
protoAiTranslateRequest.relatedStringsType()));
5051

5152
return new ProtoAiTranslateResponse(pollableFuture.getPollableTask());
5253
}
@@ -58,7 +59,8 @@ public record ProtoAiTranslateRequest(
5859
List<Long> tmTextUnitIds,
5960
boolean useBatch,
6061
String useModel,
61-
String promptSuffix) {}
62+
String promptSuffix,
63+
String relatedStringsType) {}
6264

6365
public record ProtoAiTranslateResponse(PollableTask pollableTask) {}
6466

0 commit comments

Comments
 (0)