iPhone and Linux

Monday, November 23, 2009

Deleting iPhone language packs

Every iPhone application has the option of including language packs. There come in the form of a seperate directory for every language the app supports. Inside those directories are files with various strings in that language that the app may use. Some apps may not support any additional languages and some may support 20.

They say (and I don't know who *they* are) that removing them can increase the phone's performance. I don't know how accurate that is, but it obviously does increase free space on the phone.

So here is one way to remove them from MobileTerminal, or any other command line program that can run commands on the phone.

First, log in as root by whatever means you wish. Either su in MobileTerminal, ssh root@IP, or whatever.

Run this command to update the locate database: updatedb

Now, we want to build a list of directories to delete by using the locate command to find all the language packs. Luckily, they are all found in *.lproj directories, so we start with locate lproj.

The output will include all the files in an .lproj directory, so let's use a grep regular expression to get only the directories. locate lproj | grep -E lproj$ will output only files that end with lproj, so it will output English.lproj, but not English.lproj/somefile.txt

Now we want to filter out the directories we want to keep. In my case, all I want to keep is English. On the iPhone, English can be either en.lproj or English.lproj so I piped the output to grep -v to filter out both: grep -E -v -i '(en.l|English)'

It may be simpler to grep the one at a time with -v and -i. "-v" is like a 'reverse grep' which displays everything except the string you specify and "-i" makes it case insensitive.

The official iPhone apps usually use long names like "English" and "Italian" while other apps will often use "en" and "it", so be sure to look for long and short names.

So, if you wanted to keep German, you could run this to save it to a text file:
locate lproj | grep -E proj$ | grep -v -i "XXXXXX.lproj" > langpacks.txt
Just add | grep -v -i "XXXXXX.lproj" for any languages you don't want deleted, and remember to add a grep for both long and short names.

Once you're sure everything looks safe to delete, then run this command:
while read file; do rm -rf "$file"; done < langpacks.txt
To recap: if you're certain you only want English languages on your phone, run this:
updatedb 
locate lproj | grep -E proj$ | grep -E -v -i '(en.l|English)' > langpacks.txt
while read file; do rm -rf "$file"; done < langpacks.txt
I deleted over 3000 language pack directories with this, and I only have less than 2 pages of apps installed.

Blog Archive