File tree Expand file tree Collapse file tree
src/main/java/com/google/cloud/translate/samples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Google Cloud Translate Sample
2+
3+ This sample demonstrates the use of [ Google Cloud Translate
4+ API] [ Translate-Docs ] for translating and detecting language text.
5+
6+ [ Translate-Docs ] : https://cloud.google.com/translate/docs/
7+
8+ ## Java Version
9+
10+ This sample requires you to have
11+ [ Java8] ( https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html ) .
12+
13+ ## Download Maven
14+
15+ This sample uses the [ Apache Maven] [ maven ] build system. Before getting started,
16+ be
17+ sure to [ download] [ maven-download ] and [ install] [ maven-install ] it. When you use
18+ Maven as described here, it will automatically download the needed client
19+ libraries.
20+
21+ [ maven ] : https://maven.apache.org
22+ [ maven-download ] : https://maven.apache.org/download.cgi
23+ [ maven-install ] : https://maven.apache.org/install.html
24+
25+ ## Run the sample
26+
27+ To build the sample, we use Maven.
28+
29+ ``` bash
30+ mvn clean compile assembly:single
31+ ```
32+
33+ We can then run the assembled JAR file with the ` java ` command. The variable
34+ $COMMAND takes two values ` detect' and ` translate'.
35+
36+ ```
37+ MAIN_CLASS=com.google.cloud.translate.samples.TranslateText
38+ JAR_FILE=translate-1.0-SNAPSHOT-jar-with-dependencies.jar
39+ java -cp $JAR_FILE $MAIN_CLASS <detect|translate> <text>
40+ ```
41+
42+ Example Usage:
43+
44+ ```
45+ INPUT="A quick brown fox jumped over a lazy dog."
46+
47+ java -cp $JAR_FILE $MAIN_CLASS detect "$INPUT"
48+ java -cp $JAR_FILE $MAIN_CLASS translate "$INPUT"
49+ ```
Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ public class TranslateText {
3232 */
3333 public static void detectLanguage (String sourceText ) {
3434 List <Detection > detections = TRANSLATE .detect (ImmutableList .of (sourceText ));
35-
3635 System .out .println ("Language(s) detected:" );
3736 for (Detection detection : detections ) {
3837 System .out .println ("\t " +detection );
You can’t perform that action at this time.
0 commit comments