Skip to content

Instantly share code, notes, and snippets.

@0x6d61
Created April 28, 2020 15:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x6d61/cad53803fae713af4418b57f8e87e3aa to your computer and use it in GitHub Desktop.
Save 0x6d61/cad53803fae713af4418b57f8e87e3aa to your computer and use it in GitHub Desktop.
コミットするときに翻訳するやつ
#!/bin/bash
function usage {
echo "usage:git tcommit <commit message>"
exit 2
}
if [ "$1" != "" ]; then
RESULT=$(curl -sS 'https://www2.deepl.com/jsonrpc' \
-H 'authority: www2.deepl.com' \
-H 'sec-fetch-dest: empty' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36' \
-H 'dnt: 1' \
-H 'content-type: text/plain' \
-H 'accept: */*' \
-H 'origin: https://www.deepl.com' \
-H 'sec-fetch-site: same-site' \
-H 'sec-fetch-mode: cors' \
-H 'referer: https://www.deepl.com/translator' \
-H 'accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7' \
-H 'cookie: _ga=GA1.2.1477992976.1585503313; LMTBID=4e4526f6-f474-4a4c-bc2f-67a4c7f0621f|30097036bcfadc16fe18dae7884d6b91; _gid=GA1.2.212711020.1588086065' \
--data-binary '{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"'${1}'","raw_en_context_before":[],"raw_en_context_after":[],"preferred_num_beams":4,"quality":"fast"}],"lang":{"user_preferred_langs":["EN","JA"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"commonJobParams":{},"timestamp":1588086199464},"id":46500010}' --compressed)
TRANSLATION_RESULTS=$(echo $RESULT | jq -r '.result.translations[].beams[].postprocessed_sentence' | head -n 1)
git commit -m "${TRANSLATION_RESULTS}"
else
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment