Skip to content

Instantly share code, notes, and snippets.

@themactep
Created January 18, 2024 03:18
Show Gist options
  • Save themactep/0966ab5816d24f6617c7a8c9b7ce8f4d to your computer and use it in GitHub Desktop.
Save themactep/0966ab5816d24f6617c7a8c9b7ce8f4d to your computer and use it in GitHub Desktop.
Translate Chinese text file to English.
#!/bin/bash
#
# cn2en.sh
# Translate Chinese text file to English.
#
# 2020-09-06, Paul Philippov <[email protected]>
if ! command -v trans >/dev/null; then
echo "Translate Shell is required. https://www.soimort.org/translate-shell/"
echo "wget git.io/trans && chmod +x ./trans"
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 <Text file in Chinese>"
exit 2
fi
infile=$1
cnfile="${infile%.*}.cn.${infile##*.}"
enfile="${infile%.*}.en.${infile##*.}"
cat "$infile" | iconv -f gb2312 -t utf8 - > "$cnfile"
[ $? -ne 0 ] && cp "$infile" "$cnfile"
trans -brief zh:en < "$cnfile" > "$enfile"
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment