Created
May 21, 2017 16:45
-
-
Save kiyui/c3e6f1c875f1017bbb3f78ef53ba2de4 to your computer and use it in GitHub Desktop.
PHP Translator
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/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