Last active
March 22, 2022 11:25
-
-
Save brdloush/15432eeb261460a6a6fd0e6817a3ca50 to your computer and use it in GitHub Desktop.
babashka script for translating from english to multiple languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(ns translate | |
(:require [clojure.java.shell :refer [sh]] | |
[clojure.string :as str])) | |
(def langs ["en" "cs" "de" "it" "ro" "hu" "ru"]) | |
(defn translate [s langs] | |
(let [langs-arg (str ":" (str/join "+" langs)) | |
cli-command ["trans" "--brief" langs-arg s] | |
{:keys [out]} (apply sh cli-command) | |
translations (str/split-lines out)] | |
(->> (interleave (map keyword langs) translations) | |
(partition 2) | |
(map vec) | |
(into {})))) | |
(if-let [[message] *command-line-args*] | |
(let [translations (translate message langs)] | |
(println "Hello, please could I ask you to check following translations? Thanks :polite:\n") | |
(->> translations | |
(run! (fn [[lang translated]] | |
(println (format "%s: \"%s\"" (-> lang name str/upper-case) translated)))))) | |
(println "usage: translate.clj \"Dobrý den\"")) |
Author
brdloush
commented
Mar 22, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment