1
- #import " MNSMiniStrings .h"
1
+ #import " SSTSmallStrings .h"
2
2
#import < compression.h>
3
3
4
- @implementation MNSMiniStrings
5
-
6
4
static NSDictionary <NSString *, NSString *> *sKeyToString = nil ;
7
5
8
- + ( NSData *) _decompressedDataForFile : (NSURL *) file
6
+ NSData * SSTDecompressedDataForFile (NSURL *file)
9
7
{
10
8
// The file format is: |-- 8 bytes for length of uncompressed data --|-- compressed LZFSE data --|
11
9
NS_VALID_UNTIL_END_OF_SCOPE NSData *compressedData = [NSData dataWithContentsOfURL: file options: NSDataReadingMappedIfSafe error: nil ];
@@ -19,14 +17,14 @@ + (NSData *)_decompressedDataForFile:(NSURL *)file
19
17
return [NSData dataWithBytesNoCopy: outBuffer length: actualSize freeWhenDone: YES ];
20
18
}
21
19
22
- + ( id ) _jsonForName : ( NSString *) name
20
+ id SSTJsonForName ( NSString *name)
23
21
{
24
22
NSURL *compressedFile = [[NSBundle mainBundle ] URLForResource: name withExtension: nil subdirectory: @" localization" ];
25
- NSData *data = [ self _decompressedDataForFile: compressedFile] ;
23
+ NSData *data = SSTDecompressedDataForFile ( compressedFile) ;
26
24
return [NSJSONSerialization JSONObjectWithData: data options: 0 error: nil ];
27
25
}
28
26
29
- + ( NSDictionary <NSString *, NSString *> *) _createKeyToString
27
+ NSDictionary <NSString *, NSString *> *SSTCreateKeyToString ()
30
28
{
31
29
// Note that the preferred list does seem to at least include the development region as a fallback if there aren't
32
30
// any other languages
@@ -35,9 +33,9 @@ + (id)_jsonForName:(NSString *)name
35
33
return @{};
36
34
}
37
35
NSString *valuesPath = [NSString stringWithFormat: @" %@ .values.json.lzfse" , bestLocalization];
38
- NSArray <id > *values = [ self _jsonForName: valuesPath] ;
36
+ NSArray <id > *values = SSTJsonForName ( valuesPath) ;
39
37
40
- NSArray <NSString *> *keys = [ self _jsonForName: @" keys.json.lzfse" ] ;
38
+ NSArray <NSString *> *keys = SSTJsonForName ( @" keys.json.lzfse" ) ;
41
39
42
40
NSMutableDictionary <NSString *, NSString *> *keyToString = [NSMutableDictionary dictionaryWithCapacity: keys.count];
43
41
NSInteger count = keys.count ;
@@ -52,15 +50,13 @@ + (id)_jsonForName:(NSString *)name
52
50
return keyToString; // Avoid -copy to be a bit faster
53
51
}
54
52
55
- + ( NSString *) stringForKey : (NSString *) key
53
+ NSString *SSTStringForKey (NSString *key)
56
54
{
57
55
static dispatch_once_t onceToken;
58
56
dispatch_once (&onceToken, ^{
59
- sKeyToString = [ self _createKeyToString ] ;
57
+ sKeyToString = SSTCreateKeyToString () ;
60
58
});
61
59
// Haven't tested with CFBundleAllowMixedLocalizations set to YES, although it seems like that'd be handled by the
62
60
// NSLocalizedString fallback
63
61
return sKeyToString [key] ?: NSLocalizedString(key, @" " );
64
62
}
65
-
66
- @end
0 commit comments