forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CLI command to add/remove locale translation prompt overrides
- Loading branch information
Showing
10 changed files
with
478 additions
and
21 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java
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,71 @@ | ||
package com.box.l10n.mojito.cli.command; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.box.l10n.mojito.rest.client.AIServiceClient; | ||
import com.box.l10n.mojito.rest.entity.AITranslationLocalePromptOverridesRequest; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Component | ||
@Scope("prototype") | ||
@Parameters( | ||
commandNames = {"ai-repository-locale-prompt-override"}, | ||
commandDescription = | ||
"Create/Update/Delete locale translation AI prompt overrides for a given repository") | ||
public class AIRepositoryLocaleOverrideCommand extends Command { | ||
|
||
static Logger logger = LoggerFactory.getLogger(CreateAIPromptCommand.class); | ||
|
||
@Autowired AIServiceClient aiServiceClient; | ||
|
||
@Parameter( | ||
names = {"--repository-name", "-r"}, | ||
required = true, | ||
description = "Repository name") | ||
String repository; | ||
|
||
@Parameter( | ||
names = {"--ai-prompt-id", "-aid"}, | ||
required = true, | ||
description = "AI prompt id") | ||
Long aiPromptId; | ||
|
||
@Parameter( | ||
names = {"--locales", "-l"}, | ||
required = true, | ||
description = "Locale BCP-47 tags provided in a comma separated list") | ||
String locales; | ||
|
||
@Parameter( | ||
names = {"--disabled"}, | ||
required = false, | ||
description = | ||
"Indicates if the locales are disabled for AI translation. Setting to false means AI translation will be skipped for the relevant locales. Default is false") | ||
boolean disabled = false; | ||
|
||
@Parameter( | ||
names = {"--delete"}, | ||
required = false, | ||
description = "Delete the AI prompt overrides for the given locales") | ||
boolean isDelete = false; | ||
|
||
@Override | ||
protected void execute() throws CommandException { | ||
AITranslationLocalePromptOverridesRequest aiTranslationLocalePromptOverridesRequest = | ||
new AITranslationLocalePromptOverridesRequest( | ||
repository, StringUtils.commaDelimitedListToSet(locales), aiPromptId, disabled); | ||
|
||
if (isDelete) { | ||
aiServiceClient.deleteRepositoryLocalePromptOverrides( | ||
aiTranslationLocalePromptOverridesRequest); | ||
} else { | ||
aiServiceClient.createOrUpdateRepositoryLocalePromptOverrides( | ||
aiTranslationLocalePromptOverridesRequest); | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
.../main/java/com/box/l10n/mojito/rest/entity/AITranslationLocalePromptOverridesRequest.java
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,51 @@ | ||
package com.box.l10n.mojito.rest.entity; | ||
|
||
import java.util.Set; | ||
|
||
public class AITranslationLocalePromptOverridesRequest { | ||
|
||
private String repositoryName; | ||
private Set<String> locales; | ||
private Long aiPromptId; | ||
private boolean disabled; | ||
|
||
public AITranslationLocalePromptOverridesRequest( | ||
String repositoryName, Set<String> locales, Long aiPromptId, boolean disabled) { | ||
this.repositoryName = repositoryName; | ||
this.locales = locales; | ||
this.aiPromptId = aiPromptId; | ||
this.disabled = disabled; | ||
} | ||
|
||
public String getRepositoryName() { | ||
return repositoryName; | ||
} | ||
|
||
public void setRepositoryName(String repositoryName) { | ||
this.repositoryName = repositoryName; | ||
} | ||
|
||
public Set<String> getLocales() { | ||
return locales; | ||
} | ||
|
||
public void setLocales(Set<String> locales) { | ||
this.locales = locales; | ||
} | ||
|
||
public Long getAiPromptId() { | ||
return aiPromptId; | ||
} | ||
|
||
public void setAiPromptId(Long aiPromptId) { | ||
this.aiPromptId = aiPromptId; | ||
} | ||
|
||
public boolean isDisabled() { | ||
return disabled; | ||
} | ||
|
||
public void setDisabled(boolean disabled) { | ||
this.disabled = disabled; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
.../src/main/java/com/box/l10n/mojito/rest/ai/AITranslationLocalePromptOverridesRequest.java
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,45 @@ | ||
package com.box.l10n.mojito.rest.ai; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.Set; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class AITranslationLocalePromptOverridesRequest { | ||
|
||
private String repositoryName; | ||
private Set<String> locales; | ||
private Long aiPromptId; | ||
private boolean disabled; | ||
|
||
public String getRepositoryName() { | ||
return repositoryName; | ||
} | ||
|
||
public void setRepositoryName(String repositoryName) { | ||
this.repositoryName = repositoryName; | ||
} | ||
|
||
public Set<String> getLocales() { | ||
return locales; | ||
} | ||
|
||
public void setLocales(Set<String> locales) { | ||
this.locales = locales; | ||
} | ||
|
||
public Long getAiPromptId() { | ||
return aiPromptId; | ||
} | ||
|
||
public void setAiPromptId(Long aiPromptId) { | ||
this.aiPromptId = aiPromptId; | ||
} | ||
|
||
public boolean isDisabled() { | ||
return disabled; | ||
} | ||
|
||
public void setDisabled(boolean disabled) { | ||
this.disabled = disabled; | ||
} | ||
} |
Oops, something went wrong.