Skip to content

Instantly share code, notes, and snippets.

@kiyui
Created May 21, 2017 16:45
Show Gist options
  • Save kiyui/c3e6f1c875f1017bbb3f78ef53ba2de4 to your computer and use it in GitHub Desktop.
Save kiyui/c3e6f1c875f1017bbb3f78ef53ba2de4 to your computer and use it in GitHub Desktop.
PHP Translator
#!/bin/sh
# Simple shell script example to show how to translate
# PHP files from Chinese to English based on a simple
# REGEX match.
# Requires: https://github.com/soimort/translate-shel://github.com/soimort/translate-shell
alias match_han="grep -oP \"((?!')[\p{Han}\d]+(?:(?!').)*)\""
translate() {
php_files=$(find . -name "*.php")
for php_file in $php_files
do
matches=$(cat $php_file | match_han)
for match in $matches
do
translation=$(trans -b $match)
sed -si "s/'$match'/'$translation'/g" $php_file
done
done
}
translate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment