Create wrapper script around soimort/translate-shell

translate-shell

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/bash
export TTY

( hs "$(basename "$0")" "$@" "#" "<==" "$(ps -o comm= $PPID)" 0</dev/null ) &>/dev/null

# translate-shell -s en -t fr "$@"

stdin_exists() {
    ! [ -t 0 ] && ! test "$(readlink /proc/$$/fd/0)" = /dev/null
}

if stdin_exists; then
    ins="$(cat)"
    set -- "$@" "$ins"
fi

$MYGIT/soimort/translate-shell/translate -brief "$@"

Create the entries in org-template-gen

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
french) {
    echo "#+BEGIN_SRC text -n :f \"translate-shell -s fr -t en\" :async :results verbatim code"
    cat "$input_fp" | postprocess
    echo -n "#+END_SRC"
}
;;

english) {
    echo "#+BEGIN_SRC text -n :f \"translate-shell -s en -t fr\" :async :results verbatim code"
    cat "$input_fp" | postprocess
    echo -n "#+END_SRC"
}
;;

Create the entries in hydra-org-template

1
2
("E" (hot-expand "<s" "french") "french")
("F" (hot-expand "<s" "english") "english")

Demonstration

asciinema recording

1
2
3
I learned some French so that I can talk to
you during tennis. I hope I know enough so you
will not get bored.
J'ai appris un peu de français pour pouvoir parler
vous pendant le tennis. J'espère en savoir assez pour que vous
ne s'ennuiera pas.
1
Bonjour, Madame.
Hello Madam.