2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コミット前に英→日翻訳の結果を確認

Posted at

完成品

コミットメッセージ編集後に、そのコミットメッセージを翻訳させて、
英文的におかしくないかを簡易的に確認できる

準備

必要なパッケージ入れる

$ brew install translate-shell

これを入れると、

$ trans en:ja "hello"

で翻訳結果が表示されるようになる

プロジェクトに適用

以下を.git/hooks/commit-msgに設置

# !/bin/sh

txt=`cat "$1" | grep -v '^#' | sed '/^$/d' | head -n 1`
# git now の機能でのコミットならスルー
if [ "`echo "$txt" | grep 'from now'`" ] ; then
  exit 0;
fi

echo '翻訳前:'
echo "$txt"
echo "\n翻訳後:"
trans en:ja -b "$txt"

exec < /dev/tty # これをしないと git hook では read コマンドが使えない
while true; do
  read -p 'これでいいですか? [y/N]: ' Answer
  case $Answer in
    '' | [Yy]* )
      exit 0;
      break;
      ;;
    [Nn]* )
      exit 1;
      break;
      ;;
    * )
      echo "y/Nを入力してください [y/N]: "
  esac
done;

その後

$ chmod +x .git/hooks/commit-msg

参考

nodeのプロジェクトでgit-hookを用いたい場合はgit-hooks-jshuskyを使うと良い気がする

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?