@@ -18,7 +18,10 @@ @implementation LocalizationSystem
1818
1919+(LocalizationSystem *)sharedLocalSystem {
2020 static dispatch_once_t once;
21- dispatch_once (&once, ^ { _sharedLocalSystem = [[super allocWithZone: nil ] init ]; });
21+ dispatch_once (&once, ^ {
22+ _sharedLocalSystem = [[super allocWithZone: nil ] init ];
23+ [_sharedLocalSystem setLanguage: [_sharedLocalSystem getLanguage ]];
24+ });
2225 return _sharedLocalSystem;
2326}
2427
@@ -59,6 +62,9 @@ +(id)alloc
5962// AMLocalizedString(@"Text to localize",@"Alternative text, in case hte other is not find");
6063- (NSString *)localizedStringForKey : (NSString *)key value : (NSString *)comment
6164{
65+ if (!bundle) {
66+ bundle = nil ;
67+ }
6268 return [bundle localizedStringForKey: key value: comment table: nil ];
6369}
6470
@@ -78,12 +84,20 @@ - (void) setLanguage:(NSString*) l{
7884
7985 NSString *path = [[ NSBundle mainBundle ] pathForResource: l ofType: @" lproj" ];
8086
81-
82- if (path == nil )
87+ if ([l isEqualToString: @" en" ]) {
88+ path = [[ NSBundle mainBundle ] pathForResource: @" Base" ofType: @" lproj" ];
89+ }
90+ if (path == nil ) {
8391 // in case the language does not exists
8492 [self resetLocalization ];
85- else
93+ }
94+ else {
8695 bundle = [NSBundle bundleWithPath: path];
96+ //
97+ [[NSUserDefaults standardUserDefaults ] setObject: @[l] forKey: @" AppleLanguages" ];
98+ //
99+ [[NSUserDefaults standardUserDefaults ] synchronize ];
100+ }
87101}
88102
89103// Just gets the current setted up language.
@@ -106,7 +120,12 @@ - (NSString*) getLanguage{
106120// LocalizationReset;
107121- (void ) resetLocalization
108122{
109- bundle = [NSBundle mainBundle ];
123+ [[NSUserDefaults standardUserDefaults ] removeObjectForKey: @" AppleLanguages" ];
124+ //
125+ [[NSUserDefaults standardUserDefaults ] synchronize ];
126+ //
127+ NSString *path = [[NSBundle mainBundle ] pathForResource: @" Base" ofType: @" lproj" ];
128+ bundle = [NSBundle bundleWithPath: path];
110129}
111130
112131
0 commit comments