# Translate





#### deep-cli

https://github.com/eggplants/deepl-cli

```bash
# Pas besoin d'API Key

$ deepl --fr fr --to en -s <<'A'
bonjour
A
Hello
```

#### deep-cli

https://github.com/kojix2/deepl-cli

##### Translate text

```bash
export DEEPL_AUTH_KEY=your_api_key_here

❯ deepl -i "bonjour" -t EN
Hello

❯ deepl -i "bonjour" -f FR -t EN
Hello

❯ echo "Hello" | deepl -t FR
Bonjour

❯ wp --help | deepl -t FR | less

❯ man git | deepl -t FR | less

❯ deepl --paste -t DE

❯ deepl -t FR foo.txt
```

##### Translate documents

```bash
❯ deepl doc your.pdf -t pt
# The translated document will be saved as your_PT.pdf
```

##### Liste les languages disponibles

```
# Source
❯ deepl -f 

# Target
❯ deepl -t
```

##### Environment Variables

| Name              | Description                      |
| ----------------- | -------------------------------- |
| DEEPL_AUTH_KEY    | DeepL API authentication key     |
| DEEPL_TARGET_LANG | Default target language          |
| DEEPL_USER_AGENT  | User-Agent                       |
| EDITOR            | Text editor for editing glossary |



#### translate shell

https://github.com/soimort/translate-shell

```bash
# transfert to locale
$ trans -b dog
chien

$ trans dog
dog
/dôɡ/

(♂) chien
(♀) chienne

Définitions de dog
[ English -> Français ]

nom
    (le) chien
        dog, hound, cock, hanger
    (le) mâle
        male, buck, bull, cock, stag, dog
    (la) fille moche
        dog

verbe
    suivre de près
        monitor, dog
    suivre comme un chien
        dog

dog
    chien

# translate to target
$ trans -b :de dog
Hund

$ trans -b -t de dog
Hund

# translate from source
$ trans -b en: dog
chien

$ trans -b -s en dog
chien

```



API DeepL

https://www.deepl.com/docs-api/introduction/

```bash
$ curl -X POST 'https://api-free.deepl.com/v2/translate' \
--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \
--data-urlencode 'text=Hello, world!' \
--data-urlencode 'target_lang=DE' 

{"translations":[{"detected_source_language":"EN","text":"Hallo, Welt!"}]}%
```

```bash
translate() {

	deepl=$(curl -s -X POST 'https://api-free.deepl.com/v2/translate' \
		--header "Authorization: DeepL-Auth-Key $DEEPL_KEY" \
		--data-urlencode "text=$2" \
		--data-urlencode "target_lang=$1"
		)
	echo "$deepl" | jq -r .'translations[].text'
}

translate "DE" "il fait beau !"
```

