-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSULocalizationHelper.m
73 lines (59 loc) · 1.49 KB
/
RSULocalizationHelper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// RSULocalizationHelper.m
// Pods
//
// Created by Austin Borden on 3/3/16.
//
//
#import "RSULocalizationHelper.h"
@interface RSULocalizationHelper()
@property (nonatomic, strong) NSBundle *bundle;
@end
@implementation RSULocalizationHelper
static RSULocalizationHelper *_sharedInstance = nil;
+ (RSULocalizationHelper *)sharedInstance
{
if (!_sharedInstance)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [[RSULocalizationHelper alloc] init];
});
}
return _sharedInstance;
}
- (instancetype)init
{
if (!(self = [super init]))
{
return nil;
}
_bundle = [NSBundle mainBundle];
return self;
}
- (NSString *)localizedStringForKey:(NSString *)key
{
return [_bundle localizedStringForKey:key value:@"" table:nil];
}
- (NSString *)localizedStringForKey:(NSString *)key withDefault:(NSString *)defaultValue
{
return [_bundle localizedStringForKey:key value:defaultValue table:nil];
}
- (void)setLanguage:(NSString *)language
{
NSString *path = [[NSBundle mainBundle] pathForResource:language ofType:@"lproj"];
if (path.length)
{
NSLog(@"[RSULocalizationHelper] Update bundle language to %@", language);
_bundle = [NSBundle bundleWithPath:path];
}
else
{
NSLog(@"[RSULocalizationHelper] Could not find bundle language %@", language);
}
if (!_bundle)
{
_bundle = [NSBundle mainBundle];
}
}
@end