[Android Software Development] sparkster84:
Hi, guys. These days I have been translating a couple of chinese applications and I noticed is a very messy process if you don't have the correct tools to help you, so I created a simple bash script file to help us to translate.

The script just create a backup of the original apk file, and after that it creates the correct language dir if needed, it copies the original strings.xml if needed and automatically opens it to edit. After that, it recompiles and signs the package, and deletes all the garbage.

First of all, you need these files:

# - aapt

# - apktool.jar

# - emacs (you can use other editor)

# - correct framework

# (you can find it in your rom package

# rom-package/system/framework/framework-res.apk)

# - java

# - privatekey (*.pk8)

# - publickey.x509 (*.pem)

# - signapk.jar

# - unzip

# - zip

emacs, java, zip and unzip can be easily found with your favourite linux package system. The framework is in the correct directory into your favourite rom, and the other files can be found in their respectives packages, but don't worry, here you have the "easy way" ;)

http://www.megaupload.com/?d=S2DXBO32

Well, when you have it installed, you just need to set the first parameter of the script (main_dir) and it should work, because the rest of the paths are relative. Enjoy ;).

EDIT: ups, I almost forget it. The syntax is "translate-apk.sh package.apk language-id".

Form example, to translate into french: translate-apk.sh package.apk fr

#!/bin/bash

#CAUTION: needed packages:
# - aapt
# - apktool.jar
# - emacs (you can use other editor)
# - correct framework
# (you can find it in your rom package
# rom-package/system/framework/framework-res.apk)
# - java
# - privatekey (*.pk8)
# - publickey.x509 (*.pem)
# - signapk.jar
# - unzip
# - zip

#VARIABLES-------------------------------------
#Main directory
main_dir="/home/sparkster/programas/apktranslation/"

#Translation files
aapt="$main_dir"/aapt
apktool="$main_dir"/apktool.jar
framework="$main_dir"/framework-res.apk
privatekey="$main_dir"/key.pk8
publickey="$main_dir"/certificate.pem
signapk="$main_dir"/signapk.jar

#Executables
java=java
text_editor=emacs
unzip=unzip
zip=zip

#ERROR CHECK------------------------------------
#Syntax check
if [ $# != 2 ] ; then
echo "SYNTAX: translate-apk.sh app.apk language-id"
echo "EXAMPLE: translate-apk.sh myapp.apk en"
echo "EXAMPLE: translate-apk.sh yourapp.apk fr"
else

#Temp directory check
if [[ ! -d backup ]] ; then
mkdir backup
fi

#Save original apk

echo "--creating original package backup"

cp "$1" backup/

echo "--original package backup complete"

echo "--installing framework"

"$java" -jar "$apktool" if "$framework"

echo "--framework installed"

echo "--decoding apk"

"$java" -jar "$apktool" d -f "$1" decoded

echo "--apk decoded in "$main_dir"/decoded"

#Language directory check
if [[ ! -d decoded/res/values-"$2" ]] ; then
mkdir decoded/res/values-"$2"
cp decoded/res/values/strings.xml decoded/res/values-"$2"/
fi

cut -d\> -f2 decoded/res/values-"$2"/strings.xml > temp.xml
cut -d\< -f1 temp.xml > temp2.xml

echo
echo
echo "--Press ENTER when the translation is ready"

"$text_editor" decoded/res/values-"$2"/strings.xml &
"$text_editor" temp2.xml &

read

echo "--encoding apk"

"$aapt" p -f -F temp -I "$framework" -S decoded/res -M decoded/AndroidManifest.xml

echo "--apk encoded"

echo "--transferring resources.arsc"

unzip temp resources.arsc
zip "$1" resources.arsc

echo "--resources.arsc transferred"

signed_name=${1%.*apk}-signed.apk

"$java" -jar "$signapk" "$publickey" "$privatekey" "$1" "$signed_name"

echo "--package signed"
echo "--cleaning"

rm temp
rm temp.xml
rm temp2.xml
rm resources.arsc
rm "$1"
rm -fr decoded

echo "--translation finished"
echo
echo
echo
echo "--Also your hard drive has just been formatted"
sleep 3
echo "--Just kidding"
fi