Can I load a localizable.strings file into an iOS app over-the-air

Lets say my app only runs in English. But I do not want to release a new version for every time I add a new language. My proposal is to load this localizable.strings file remotely into my app.

My app has facility to load files from ftp sites.

Do you guys think is possible to load languages this way? Or does the App has to compile the language file at compile time?



All localized string resources (plus many other kind of resources) are extracted from the bundle. Usually an app uses the "main bundle" which is the one that is created by XCode together with your app. But you can create separately any other bundle, provided you make it with the correct structure, then you can download it in your app and finally extract a localized string using the NSLocalizedStringFromTableInBundle() function.

So let's say you extract for a key "KEY" the language translation, then the normal syntax would be:

NSString *translated = NSLocalizedStringFromTable(@"key",nil,nil);

but there is a variant of this option that allows you to specify the bundle:

NSString *translated = NSLocalizedStringFromTableInBundle(@"key",nil,myBundle,nil);

In the standard case you replace myBundle with [NSBundle mainBundle] but if you want to use another bundle you can specify it in this way:

NSString *myBundlePath = "the path to the downloaded bundle";
NSBundle *myBundle = [NSBundle bundleWithPath:myBundlePath];
NSString *translated = NSLocalizedStringFromTableInBundle(@"key",nil,myBundle,nil);

The full structure of a bundle can be seen in the "Bundle Programming Guide" in the Apple docs, but in your case you can simply create in this way:

  • in your Mac create a directory, and call it "MyBundle"
  • inside this directory move your localized string(s) (if you have multiple languages in the bundle then the localizable.strings file will be inside the lproj directories: en.lproj, it.lproj, fr.lproj, ...)
  • then rename the directory to "MyBundle.bundle"

You will notice with the last operation that now this object is seen as a standalone object but in fact it is a directory.

Now you can decide to have a multiple-bundle approach or follow a single-bundle technique: in the latter case you can package all the languages and then use the unique updated bundle for language translation by using the automatic system localization rules; in the other case you can make a bundle for each language and then - based on the currently selected language - load the appropriate bundle and choose it for your translations.

Need Your Help

writing a http sniffer

http url network-programming packet-capture packet-sniffers

I would like to write a program to extract the URLs of websites visited by a system (an IP address) through packet capture.. I think this URL will come in the data section ( ie not in any of the he...

Bash Script to backup my “home” folder

linux bash shell sh

How can I skip backing up my "Downloads" folder?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.