Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Classes/BundleLocalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import <Foundation/Foundation.h>
#import "NSBundle+Localization.h"

extern NSString *const kBundleLocalizationChangedNotification;

@interface BundleLocalization : NSObject

+ (BundleLocalization*) sharedInstance;
Expand Down
9 changes: 9 additions & 0 deletions Classes/BundleLocalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import "BundleLocalization.h"
#import "NSBundle+Localization.h"

NSString *const kBundleLocalizationChangedNotification = @"kBundleLocalizationChangedNotification";


@implementation BundleLocalization
{
Expand Down Expand Up @@ -64,6 +66,13 @@ - (void) setLanguage:(NSString*) lang {
}
selectedLanguage = lang;
}

// Set the language so system frameworks will be localized also.
// This requires an app restart to take effect.
[[NSUserDefaults standardUserDefaults] setObject:@[lang] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

[[NSNotificationCenter defaultCenter] postNotificationName:kBundleLocalizationChangedNotification object:nil];
}

- (NSString*) language{
Expand Down
12 changes: 10 additions & 2 deletions Classes/NSBundle+Localization.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ + (void)load {

#pragma mark - Method Swizzling

-(NSString*) customLocaLizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
- (NSString *) customLocaLizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
{
NSBundle* bundle = [BundleLocalization sharedInstance].localizationBundle;
NSBundle *bundle = [BundleLocalization sharedInstance].localizationBundle;
NSString *bundleString = [self.bundleURL.path stringByReplacingOccurrencesOfString:@"/private" withString:@""];

// This is not the app bundle (i.e. a system framework such as UIKit, or MediaPlayer)
if ([bundle.bundleURL.path rangeOfString:bundleString].location == NSNotFound)
{
return [self customLocaLizedStringForKey:key value:value table:tableName];
}

return [bundle customLocaLizedStringForKey:key value:value table:tableName];
}

Expand Down