New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included @tomgs work for the translation script in a gradle file #89

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+154 −0
Diff settings

Always

Just for now

Included @tomgs work for the translation script in a gradle file

  • Loading branch information...
Will Baumann
Will Baumann committed Oct 9, 2018
commit 21a7c0c0f656b7cdbb9b67c969c52ee0c363abe7
Copy path View file
@@ -191,4 +191,18 @@ task secretsExtraction << {
println ""
}
task translateToIOS << {
description "Twine-translate Android .xml locale files to iOS, check for differences in iOS GitHub repo, create pull request for the iOS repo with the new translations if need be"
exec {
workingDir rootDir
executable "chmod"
args = ["+x", "${rootDir}/scripts/barebones-locale-tool.sh"]
// Note: Used for Travis execution.
}
exec {
workingDir rootDir
executable "${rootDir}/scripts/barebones-locale-tool.sh"
}
}
preBuild.dependsOn secretsExtraction
Copy path View file
@@ -0,0 +1,140 @@
#!/bin/bash
# Some preliminary work
printf "\nSome Setup\n"
echo "----------------"
# Create some files and folders
if [ ! -e twine.txt ]; then
touch twine.txt
chmod 777 twine.txt
printf "Created twine.txt file with 777 unix permissions.\n"
else
printf "twine.txt already exists - check why, delete it and repeat.\n"
fi
if [ -e twine-log.txt ]; then
touch twine-log.txt
fi
chmod 777 twine-log.txt
printf "Created twine-log.txt file with 777 unix permissions.\n"
if [ ! -d iOSValues ]; then
mkdir iOSValues
printf "Created iOSValues folder for translated iOS locales. \n"
fi
# Check required packages are installed
hub=`hub --version | grep "hub"`
twine=`twine --version | grep "Twine"`
if [ -z "$hub" ]; then
echo "hub (https://github.com/github/hub) is required for the proper function of this script. Please install it and re-run this gradle task."
exit 1
else
echo "hub (https://github.com/github/hub) is installed, carrying on."
fi
if [ -z "$twine" ]; then
echo "twine (https://github.com/scelis/twine) is required for the proper function of this script. Please install it and re-run this gradle task."
exit 1
else
echo "twine (https://github.com/scelis/twine) is installed, carrying on."
fi
# Clone iOS repo
if [ ! -d SmartReceiptsiOS ]; then
git clone https://github.com/wbaumann/SmartReceiptsiOS.git
printf "Successfully cloned iOS repo.\n"
else
printf "Already cloned iOS repo - check why, delete it and repeat.\n"
fi
# Twine-ify everyhting
# First get all the language codes by parsing folder names
list=`find ../app/src/main/res -maxdepth 1 -type d -name '*values-*' -exec basename {} \;`
printf "\nStarting Conversions\n"
echo "-----------------------"
for dir in $list
do
# Then Slurp Android locale Files
if [ -e ../app/src/main/res/${dir}/strings.xml ]; then
twine consume-localization-file twine.txt ../app/src/main/res/${dir}/strings.xml --format android --consume-all --consume-comments --developer-language en >> twine-log.txt
fi
if [ -e ../app/src/main/res/${dir}/preferences.xml ]; then
twine consume-localization-file twine.txt ../app/src/main/res/${dir}/preferences.xml --format android --consume-all --consume-comments --developer-language en >> twine-log.txt
fi
# Create iOS locale files
lang=`echo ${dir} | cut -f2 -d-`
# Avoiding values-sw600dp and values-large folders - they're not really locale files
if [ ${lang} != "sw600dp" ] && [ ${lang} != "large" ]; then
# "Tranlsating" into iOS
newDir="iOSValues/${lang}.lproj"
echo "New Language - ${lang} - Starting Now \n" >> twine-log.txt
mkdir ${newDir}
printf "Created iOS value folder for languge: ${lang}\n"
twine generate-localization-file twine.txt ${newDir}/SharedLocalizable.strings --lang ${lang} >> twine-log.txt
echo "End of Language\n" >> twine-log.txt
printf "Converted language file for: ${lang} from Android -> iOS\n"
# Run diffs to check for differences
git diff --no-index --word-diff ${newDir}/SharedLocalizable.strings SmartReceiptsiOS/SmartReceipts/Supporting\ Files/${lang}.lproj/SharedLocalizable.strings > ${lang}-diff.txt
eval $command
# If file size is not 0, then there was a difference between the two files - move files
if [ -s ${lang}-diff.txt ]; then
printf "Found differences between SharedLocalizable.strings files for languge: ${lang}\n"
mv ${newDir}/SharedLocalizable.strings SmartReceiptsiOS/SmartReceipts/Supporting\ Files/${lang}.lproj/SharedLocalizable.strings >> ${lang}-diff.txt
printf "Copied new file to repository.\n"
fi
# Clean diff files
rm ${lang}-diff.txt
fi
done
# Fix twine's dumb us.lproj folder issue
printf "Copied new file to repository.\n"
mv SmartReceiptsiOS/SmartReceipts/Supporting\ Files/us.lproj/SharedLocalizable.strings SmartReceiptsiOS/SmartReceipts/Supporting\ Files/en.lproj/SharedLocalizable.strings
printf "Moving us.lproj strings file -> en.lproj.\n"
rm -rf SmartReceiptsiOS/SmartReceipts/Supporting\ Files/us.lproj
printf "Removed us.lproj.\n"
## Push changes to repo
cd SmartReceiptsIOS
echo "Forking repository into https://github.com/twine-botty-bot/SmartReceiptsiOS"
hub fork
echo "Adding new fork as remote"
git remote add fork https://github.com/twine-botty-bot/SmartReceiptsiOS.git
echo "Adding & committing new langauge files"
git add .
git commit -m "New Translation Files From Twine - Android -> iOS"
echo "Pushing changes into fork"
echo "twine-botty-bot tjt6VbG5d5jP" | git push fork master
echo "Creating pull request in wbaumann/SmartReceiptsiOS"
git status
hub pull-request -f -m "New Translation Files From Twine - Android -> iOS"
echo "^ This is the new pull request ^"
echo "Deleting fork"
hub delete -y twine-botty-bot/SmartReceiptsiOS
# If twine.txt is empty, then the import failed. Else - probable success
echo "Going up a folder, back to /scripts"
cd ..
if [ ! -s twine.txt ];
then
printf "The twine.txt file is empty, hence the import failed! Did you check the strings.xml & preferences.xml files exist?\n"
else
printf "twine.txt file seems fine.\n"
fi
# Clean up after yourself - delete everything
printf "\nCleaning Up!\n"
echo "----------------"
rm twine.txt
printf "Removed twine.txt\n"
rm -Rf iOSValues
printf "Removed the iOSValues folder\n"
rm -Rf SmartReceiptsiOS
printf "Removed the cloned git repo for SmartReceiptsiOS\n"
printf "Make sure to check twine-log.txt for any errors that twine sent out.\n"
ProTip! Use n and p to navigate between commits in a pull request.