Способы перевода «Triste» на английский с примерами кода

Triste — испанское слово, которое переводится как «грустный». Вот несколько способов перевести слово «triste» на английский язык, используя примеры кода на разных языках программирования:

  1. Python:

    from googletrans import Translator
    def translate_to_english(text):
    translator = Translator(service_urls=['translate.google.com'])
    translation = translator.translate(text, src='es', dest='en')
    return translation.text
    spanish_word = "triste"
    english_translation = translate_to_english(spanish_word)
    print(english_translation)
  2. JavaScript:

    const translate = require('translate');
    async function translateToEnglish(text) {
    const englishTranslation = await translate(text, { from: 'es', to: 'en' });
    return englishTranslation;
    }
    const spanishWord = "triste";
    translateToEnglish(spanishWord)
    .then(englishTranslation => console.log(englishTranslation));
  3. Java:

    import com.mashape.unirest.http.HttpResponse;
    import com.mashape.unirest.http.Unirest;
    import org.json.JSONObject;
    public class Translator {
    public static void main(String[] args) {
        String spanishWord = "triste";
        String englishTranslation = translateToEnglish(spanishWord);
        System.out.println(englishTranslation);
    }
    public static String translateToEnglish(String text) {
        try {
            HttpResponse<String> response = Unirest.get("https://translated-mymemory---translation-memory.p.rapidapi.com/api/get")
                    .queryString("q", text)
                    .queryString("langpair", "es|en")
                    .header("x-rapidapi-key", "YOUR_API_KEY")
                    .header("x-rapidapi-host", "translated-mymemory---translation-memory.p.rapidapi.com")
                    .asString();
            JSONObject jsonObject = new JSONObject(response.getBody());
            return jsonObject.getJSONObject("responseData").getString("translatedText");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    }