Posts / December 8, 2012

Redefining NSLocalizedString for iOS Framework Bundles

In the upcoming version of the Ushahidi iOS SDK, I ran into a snag getting translations to work inside my custom iOS framework.

The trick is to ensure that you include the Localizable.strings in the Copy Files section in the Build Phases of your framework bundle.

You can double check whether your Localizable.strings were included correctly by expanding the bundle in the project using the framework.

The problem however is that the NSLocalizedString macro is defined to use [NSBundle mainBundle], which means it won’t find your Localizable.strings since they live inside your separate framework bundle.

#define NSLocalizedString(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

The solution is to instead use NSLocalizedStringFromTableInBundle, which allows you to provide your own NSBundle for the string lookup.

#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]

However I didn’t what to replace all my existing NSLocalizedString statements with NSLocalizedStringFromTableInBundle, so instead I re-defined the macro in my SDK-Prefix.pch:

#undef NSLocalizedString
#define NSLocalizedString(key, comment) \
[[NSBundle bundleWithName:@"Ushahidi.bundle"] localizedStringForKey:(key) value:@"" table:nil]

To help with the bundle lookup, I added NSBundle+USH.h category to provide an easy way to obtain a bundle by name.

+ (NSBundle*) bundleWithName:(NSString*)name {
  NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
  NSString *frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:name];
  if ([[NSFileManager defaultManager] fileExistsAtPath:frameworkBundlePath]){
    return [NSBundle bundleWithPath:frameworkBundlePath];
  }
  return nil;
}

Voila! All my existing NSLocalizedString statements now return the correct translated phrases from the framework bundle, without any additional changes in the framework code.

Comments
Can Amoxicillin Be Taken Before Bed [url=http://apcialisle.com/#]cialis[/url] Foro Priligy 30 Mg Buy Cialis Whats Does Keflex Do
Achat De Viagra En Ligne [url=https://apcialisle.com/#]cialis vs viagra[/url] Weight Loss Orlistat Medical Fl Cialis Viagra Generico Pagamento Postepay
[url=http://vsdoxycyclinev.com/]buy doxycycline medication online[/url]
ivermectin purchase - ivermectin side effects stromectol ebay
tadalafil canada online - site cialis generic online pharmacy
tadalafil online https://tadalafilgenc.com/ tadalafil generic tadalafil tablets
tadalafil https://tadalafilgenc.com/ buy tadalafil us generic tadalafil 40 mg
tadalafil generic https://superactivetadalafil.com/ tadalafil pills buy tadalafil
buy tadalafil https://tadalafilgenc.com/ buy tadalafil buy tadalafil us
priligy 60 mg - cialis 20 mg price usa where can you buy tadalafil
low cost ed pills - pills for ed herbal ed treatment
prednisone 5 mg buy online - prednisone pharmacy prices prednisone 16 mg
provigil dosage - gnprovigl.com modafinil addiction
amoxicillin for sale uk - gnamoxicill.com buy amoxicillina 500 mg online
cialis online 5mg - buy cialis online visa best prices for cialis
ivermectin oral - buy liquid ivermectin
best tadalafil generic - where can i get cialis pills cialis daily cost canada
stromectol uk - stromectol online pharmacy ivermectin 9mg
prednisone ordering online - prednisone prices 20 mg of prednisone
modafinil 200 mg - order modafinil online modafinil reviews
zpac - generic zithromax 250mg buy generic zithromax 500mg
buy furosemide 20 mg - order lasix online no prescription can you buy furosemide over the counter tablets
clomiphene tablets - clomiphene generic clomid without prescription
how to get viagra prescription in australia - how to buy sildenafil without a prescription discount viagra sale
cialis south africa - Cialis prescription cialis generic australia
doxycycline 400 mg - doxycycline 50 doxycycline 40 mg capsule
ivermectin australia - where can i buy oral ivermectin
amoxicillin brand over the counter - gnamoxil amoxicillin rash
medrol medication generic - lyrica 25mg capsules lyrica 75 mg cost
viagra price in india - Generic viagra canadian buy cheap viagra generic online
cialis for sale canadian pharmacy - Buy cialis low price buy cialis online usa
oral ivermectin cost - purchase stromectol stromectol 3 mg tablet
furosemide lasix - clomid tablets price of lasix 80 mg
cheap albuterol - ventolin pills buy ventolin
buy doxycycline 100mg uk - doxycycline hyclate 100mg prednisolone 10 mg buy online
stromectol us - stromectol ivermectin purchase stromectol
accutane price nz - 20 mg accutane daily accutane cream online
academic writing support - research paper editing writing dissertation service
xenical 42 - xenical 84 alli vs xenical
cialis discount pharmacy - cialis from canada legal online pharmacy
ivermectin 1 cream - stromectol uk coronavirus ivermectin pills canada
buy cheap viagra online uk - pharmacy viagra viagra pills for sale nz
viagra us - sildenafil cost viagra 120mg otc
generic tadalafil from canada - cialis cost cialis buy online australia
canadian pharmacy 1 internet online drugstore - Pharmacy cialis cialis 30
ivermectin generic cream - stromectol otc ivermectin for humans for sale
write papers online - help writing papers for college help with assignments uk
best viagra pills over the counter - Buy viagra online cheap buy sildenafil without a prescription