From 187f1889273846be7698d098923566f0473c831a Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 25 Sep 2015 09:54:20 -0500 Subject: [PATCH] Framework localization fix Previously QBValidator was using `NSLocalizedStringFromTable` to do localizations. Which works in the case that you're not using QBValidator as a .framework. The solution is to first try to `NSLocalizedStringFromTableInBundle` using `[NSBundle bundleForClass:[self class]]`. This will get the key from the .framework bundle if available. If not, then go to the main bundle --- QBValidator/QBValidator.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/QBValidator/QBValidator.m b/QBValidator/QBValidator.m index d7ec11c..bf0e119 100644 --- a/QBValidator/QBValidator.m +++ b/QBValidator/QBValidator.m @@ -186,7 +186,13 @@ - (NSString *)errorMessageForRule:(QBValidationRule *)rule name:(NSString *)name } key = [key stringByAppendingString:@"Satisfied"]; - NSString *errorMessage = NSLocalizedStringFromTable(key, [rule localizationTableName], nil); + // First check bundleForClass: + // This will ensure that we work if packaged in a framework + NSString *errorMessage = NSLocalizedStringFromTableInBundle(key, [rule localizationTableName], [NSBundle bundleForClass:[self class]], nil); + if ([errorMessage isEqualToString:key]) { + // Fall back to main bundle + errorMessage = NSLocalizedStringFromTableInBundle(key, [rule localizationTableName], [NSBundle mainBundle], nil); + } // Replace patterns errorMessage = [errorMessage stringByReplacingOccurrencesOfString:@"{name}"