public String translate(String text, String sourceLanguage, String targetLanguage)
            throws TikaException, IOException {
        String configPath = config.getProperty(
                "translator.marian." + sourceLanguage + "_" + targetLanguage + ".config");
        String serverSocket = config.getProperty(
                "translator.marian." + sourceLanguage + "_" + targetLanguage + ".server");

        if (!isAvailable(sourceLanguage, targetLanguage)) {
            return text;
        }

        if (!StringUtils.isEmpty(configPath) && !StringUtils.isEmpty(serverSocket)) {
            LOG.info("Both local and server configurations exist for " + sourceLanguage + " to " +
                    targetLanguage + "\nDefaulting to use local engine.");
        }

        StringBuilder translation = new StringBuilder();
        File tmpFile = Files.createTempFile(INPUT_TMP_NAME, ".tmp").toFile();
        tmpFile.deleteOnExit();
        try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(tmpFile),
                Charset.defaultCharset())) {
            out.append(text).append('\n').close();
        }
        File tmpTranslatedFile = Files.createTempFile(OUTPUT_TMP_NAME, ".tmp").toFile();
        tmpTranslatedFile.deleteOnExit();

        try {
            String preProcessScript = config.getProperty("translator.marian.preprocess");
            executeScript(preProcessScript, tmpFile);

            if (!StringUtils.isEmpty(configPath)) {
                processWithLocalMarian(configPath, tmpFile, tmpTranslatedFile);
            } else {
                processWithMarianServer(serverSocket, tmpFile, tmpTranslatedFile);
            }

            String postProcessScript = config.getProperty("translator.marian.postprocess");
            executeScript(postProcessScript, tmpTranslatedFile);

            try (BufferedReader fileReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(tmpTranslatedFile),
                            Charset.defaultCharset()))) {
                fileReader.lines().forEach(translation::append);
            }

        } catch (InterruptedException e) {
            throw new TikaException("Failed perform translation", e);
        }

        if (!tmpFile.delete() || !tmpTranslatedFile.delete()) {
            throw new IOException("Failed to delete temporary files.");
        }

        return translation.toString();
    }
Translate method with specific source and target languages.

@param text           The text to translate.
@param sourceLanguage The language to translate from (for example, "en").
@param targetLanguage The desired language to translate to (for example, "hi").
@return The translated text.
@throws TikaException on any error performing translation.
@throws IOException   on any I/O error performing translation.
tika-translate/src/main/java/org/apache/tika/language/translate/impl/MarianTranslator.java