Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.

Commit de5b5a8

Browse files
authored
fix: use setModel as rest api already support it (#330)
1 parent ef7d7c8 commit de5b5a8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

google-cloud-translate/src/main/java/com/google/cloud/translate/spi/v2/HttpTranslateRpc.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap)
9898
@Override
9999
public List<TranslationsResource> translate(List<String> texts, Map<Option, ?> optionMap) {
100100
try {
101-
// TODO use POST as soon as usage of "model" correctly reports an error in non-whitelisted
102-
// projects
103101
String targetLanguage =
104102
firstNonNull(Option.TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage());
105103
final String sourceLanguage = Option.SOURCE_LANGUAGE.getString(optionMap);
@@ -109,7 +107,7 @@ public List<TranslationsResource> translate(List<String> texts, Map<Option, ?> o
109107
.list(texts, targetLanguage)
110108
.setSource(sourceLanguage)
111109
.setKey(options.getApiKey())
112-
.set("model", Option.MODEL.getString(optionMap))
110+
.setModel(Option.MODEL.getString(optionMap))
113111
.setFormat(Option.FORMAT.getString(optionMap))
114112
.execute()
115113
.getTranslations();

google-cloud-translate/src/test/java/com/google/cloud/translate/TranslateImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,19 @@ public void testTranslateListWithOptions() {
368368
verify();
369369
}
370370

371+
@Test
372+
public void testTranslateTextListWithModel() {
373+
String text = "Hallo Welt!";
374+
List<String> texts = ImmutableList.of(text);
375+
EasyMock.expect(
376+
translateRpcMock.translate(texts, ImmutableMap.of(TranslateRpc.Option.MODEL, "nmt")))
377+
.andReturn(ImmutableList.of(TRANSLATION2_PB));
378+
EasyMock.replay(translateRpcMock);
379+
initializeService();
380+
assertEquals(ImmutableList.of(TRANSLATION2), translate.translate(texts, MODEL_OPTION));
381+
verify();
382+
}
383+
371384
@Test
372385
public void testRetryableException() {
373386
EasyMock.expect(translateRpcMock.listSupportedLanguages(EMPTY_RPC_OPTIONS))

0 commit comments

Comments
 (0)