Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added supportedd languages for target language #354

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Translate API Features:
java -jar $JAR_FILE langsupport
```

* List the languages supported for given target language
```
java -jar $JAR_FILE langsupport $TARGET_LANG
```

* Detect input text language
```
java -jar $JAR_FILE detect "$INPUT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import com.google.cloud.translate.Detection;
import com.google.cloud.translate.Language;
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.Translate.LanguageListOption;
import com.google.cloud.translate.Translate.TranslateOption;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
import com.google.common.collect.ImmutableList;

import java.io.PrintStream;
import java.util.List;
import java.util.Optional;

public class TranslateText {
/**
Expand Down Expand Up @@ -84,10 +86,12 @@ public static void translateTextWithOptions(
* Displays a list of supported languages and codes.
*
* @param out print stream
* @param tgtLang optional target language
*/
public static void displaySupportedLanguages(PrintStream out) {
public static void displaySupportedLanguages(PrintStream out, Optional<String> tgtLang) {
Translate translate = createTranslateService();
List<Language> languages = translate.listSupportedLanguages();
LanguageListOption target = LanguageListOption.targetLanguage(tgtLang.orElse("en"));
List<Language> languages = translate.listSupportedLanguages(target);

for (Language language : languages) {
out.printf("Name: %s, Code: %s\n", language.name(), language.code());
Expand Down Expand Up @@ -137,7 +141,12 @@ public static void main(String[] args) {
TranslateText.translateText(text, System.out);
}
} else if (command.equals("langsupport")) {
TranslateText.displaySupportedLanguages(System.out);
try {
String target = args[1];
TranslateText.displaySupportedLanguages(System.out, Optional.of(target));
} catch (ArrayIndexOutOfBoundsException ex) {
TranslateText.displaySupportedLanguages(System.out, Optional.empty());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
* Unit tests for {@link Analyze}.
* Unit tests for {@link TranslateText}.
*/
@RunWith(JUnit4.class)
public class TranslateTextTest {
Expand Down Expand Up @@ -56,7 +57,39 @@ public class TranslateTextTest {
PrintStream out = new PrintStream(bout);

// Act
TranslateText.displaySupportedLanguages(out);
TranslateText.displaySupportedLanguages(out, Optional.empty());

// Assert
String got = bout.toString();
for (String language : languages) {
assertThat(got).contains(language);
}
}

@Test public void testSupportedLanguagesTargetFrench() throws Exception {
//Supported languages
List<String> languages = Arrays.asList(
"Afrikaans", "Albanais", "Allemand", "Amharique", "Anglais", "Arabe", "Arménien",
"Azéri", "Basque", "Bengali", "Biélorusse", "Birman", "Bosniaque", "Bulgare", "Catalan",
"Cebuano", "Chichewa", "Chinois (simplifié)", "Chinois (traditionnel)", "Cingalais",
"Coréen", "Corse", "Créole haïtien", "Croate", "Danois", "Espagnol", "Espéranto",
"Estonien", "Finnois", "Français", "Frison", "Gaélique (Écosse)", "Galicien",
"Gallois", "Géorgien", "Grec", "Gujarati", "Haoussa", "Hawaïen", "Hébreu", "Hindi",
"Hmong", "Hongrois", "Igbo", "Indonésien", "Irlandais", "Islandais", "Italien",
"Japonais", "Javanais", "Kannada", "Kazakh", "Khmer", "Kirghiz", "Kurde", "Laotien",
"Latin", "Letton", "Lituanien", "Luxembourgeois", "Macédonien", "Malaisien", "Malayalam",
"Malgache", "Maltais", "Maori", "Marathi", "Mongol", "Néerlandais", "Népalais", "Norvégien",
"Ouzbek", "Pachtô", "Panjabi", "Persan", "Polonais", "Portugais", "Roumain", "Russe",
"Samoan", "Serbe", "Sesotho", "Shona", "Sindhî", "Slovaque", "Slovène", "Somali",
"Soundanais", "Suédois", "Swahili", "Tadjik", "Tagalog", "Tamoul", "Tchèque", "Telugu",
"Thaï", "Turc", "Ukrainien", "Urdu", "Vietnamien", "Xhosa", "Yiddish", "Yorouba","Zoulou");

// Arrange
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);

// Act
TranslateText.displaySupportedLanguages(out, Optional.of("fr"));

// Assert
String got = bout.toString();
Expand Down