Created
January 18, 2024 03:18
-
-
Save themactep/0966ab5816d24f6617c7a8c9b7ce8f4d to your computer and use it in GitHub Desktop.
Translate Chinese text file to English.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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