Home > Localization > Extracting localization strings from Settings.bundle plists

Extracting localization strings from Settings.bundle plists

If you are building child panes in your Settings.bundle, you’ll end up with several .plist files. When it comes time to localize your project, you find the creation of the corresponding .strings file a bit tedious (I know I do).

Here’s a handy list bash script which will (i) find tags, (ii) extract the contents of the following tag, and then (iii) output that value to a text file in the “string” = “string” format needed for ibtool.

You pass the input and output file names as parameters.

echo "//Manual edits will be overwritten the next time this script runs.// Generated by plist2strings.\n/* A single strings file, whose title is specified in your preferences schema. The strings files provide the localized content to display to the user for each of your preferences. */\n" > plist2stringstmp
sed -n '
# look for a "#" at the end of the line
/<key>Title<\/key>$/ {
# Found one - now read in the next line
# delete the "#" and the new line character,
	s/.*<\(string\)>\(.*\)<\/\1>/"\2" = "\2"/gp
}' $1 > plist2stringstmp2
cat plist2stringstmp plist2stringstmp2 > $2
rm plist2stringstmp plist2stringstmp2

Copy-N-Paste into a text file. I saved mine as plist2strings. Be sure to give it execute permissions. For example, in Terminal execute:

 macbook:~ foo$ chmod 755 plist2strings

To execute the script (if saved to your user folder) from root of your Settings.bundle directory, just use the syntax:

 macbook:~ foo$ ~/plist2strings mysettings.plist en.lprog/mysettings.strings

If mysettings.strings is not already present in that folder, it will create it. If it is already there, it will automatically overwrite it without warning.

Hope someone finds this useful. And feel free to use (and abuse) as you see fit (caveat emptor ;-)). If you make any useful changes, consider posting them back up here for others to enjoy too.

Happy Localizing!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: