|
| 1 | +// Copyright 2023 DeepL SE (https://www.deepl.com) |
| 2 | +// Use of this source code is governed by an MIT |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | +package com.deepl.deepltestapp; |
| 5 | +import com.deepl.api.*; |
| 6 | +import java.lang.System.*; |
| 7 | + |
| 8 | +/** |
| 9 | + * Hello world translation example |
| 10 | + * |
| 11 | + */ |
| 12 | +public class App { |
| 13 | + /** |
| 14 | + * Hello world example - insert your API key to test the library. |
| 15 | + */ |
| 16 | + public static void main( String[] args ) throws InterruptedException, DeepLException { |
| 17 | + String authKey = "f63c02c5-f056-..."; // Replace with your key |
| 18 | + Translator translator = new Translator(authKey); |
| 19 | + TextResult result = |
| 20 | + translator.translateText("Hello, world!", null, "fr"); |
| 21 | + System.out.println(result.getText()); // "Bonjour, le monde !" |
| 22 | + } |
| 23 | + |
| 24 | + ///////////////////////////////////////////////////////////////////////////////////// |
| 25 | + /// These methods are for a test using DeepLs CI pipeline, ignore. |
| 26 | + |
| 27 | + public static String getEnvironmentVariableValue(String envVar) { |
| 28 | + return System.getenv(envVar); |
| 29 | + } |
| 30 | + |
| 31 | + public static String getAuthKeyFromEnvironmentVariables() { |
| 32 | + return getEnvironmentVariableValue("DEEPL_AUTH_KEY"); |
| 33 | + } |
| 34 | + |
| 35 | + public static String getServerUrlFromEnvironmentVariables() { |
| 36 | + return getEnvironmentVariableValue("DEEPL_SERVER_URL"); |
| 37 | + } |
| 38 | + |
| 39 | + public static String translateHelloWorld() throws InterruptedException, DeepLException { |
| 40 | + Translator translator = new Translator(getAuthKeyFromEnvironmentVariables(), |
| 41 | + (new TranslatorOptions()).setServerUrl(getServerUrlFromEnvironmentVariables())); |
| 42 | + TextResult result = |
| 43 | + translator.translateText("Hello, world!", null, "fr"); |
| 44 | + String translatedText = result.getText(); |
| 45 | + return translatedText; |
| 46 | + } |
| 47 | +} |
0 commit comments