@@ -25,18 +25,22 @@ id SSTJsonForName(NSString *name, NSBundle *bundle, NSString *subdirectory)
2525 return [NSJSONSerialization JSONObjectWithData: data options: 0 error: nil ];
2626}
2727
28- NSDictionary <NSString *, NSString *> *SSTCreateKeyToString (NSBundle *bundle, NSString *subdirectory)
28+ NSDictionary <NSString *, NSString *> *SSTCreateKeyToString (NSBundle *bundle, NSString *subdirectory, NSString *targetName )
2929{
3030 // Note that the preferred list does seem to at least include the development region as a fallback if there aren't
3131 // any other languages
3232 NSString *bestLocalization = [[bundle preferredLocalizations ] firstObject ] ?: [bundle developmentLocalization ];
3333 if (!bestLocalization) {
3434 return @{};
3535 }
36- NSString *valuesPath = [NSString stringWithFormat: @" %@ .values.json.lzfse" , bestLocalization];
36+ NSString *targetNamePrefix = @" " ;
37+ if (targetName) {
38+ targetNamePrefix = [NSString stringWithFormat: @" %@ ." , targetName];
39+ }
40+ NSString *valuesPath = [NSString stringWithFormat: @" %@%@ .values.json.lzfse" , targetNamePrefix, bestLocalization];
3741 NSArray <id > *values = SSTJsonForName (valuesPath, bundle, subdirectory);
3842
39- NSArray <NSString *> *keys = SSTJsonForName (@" keys.json.lzfse" , bundle, subdirectory);
43+ NSArray <NSString *> *keys = SSTJsonForName ([ NSString stringWithFormat: @" %@ keys.json.lzfse" , targetNamePrefix] , bundle, subdirectory);
4044
4145 NSMutableDictionary <NSString *, NSString *> *keyToString = [NSMutableDictionary dictionaryWithCapacity: keys.count];
4246 NSInteger count = keys.count ;
@@ -51,19 +55,24 @@ id SSTJsonForName(NSString *name, NSBundle *bundle, NSString *subdirectory)
5155 return keyToString; // Avoid -copy to be a bit faster
5256}
5357
54- NSString *SSTStringForKeyWithBundleAndSubdirectory (NSString *key, NSBundle *bundle, NSString *subdirectory) {
58+ NSString *SSTStringForKeyWithBundleAndSubdirectoryAndTargetName (NSString *key, NSBundle *bundle, NSString *subdirectory, NSString *targetName ) {
5559 static dispatch_once_t onceToken;
5660 dispatch_once (&onceToken, ^{
57- sKeyToString = SSTCreateKeyToString (bundle, subdirectory);
61+ sKeyToString = SSTCreateKeyToString (bundle, subdirectory, targetName );
5862 });
5963 // Haven't tested with CFBundleAllowMixedLocalizations set to YES, although it seems like that'd be handled by the
6064 // NSLocalizedString fallback
6165 return sKeyToString [key] ?: NSLocalizedString(key, @" " );
6266}
6367
68+ NSString *SSTStringForKeyWithBundleAndSubdirectory (NSString *key, NSBundle *bundle, NSString *subdirectory)
69+ {
70+ return SSTStringForKeyWithBundleAndSubdirectoryAndTargetName (key, bundle, subdirectory, nil );
71+ }
72+
6473NSString *SSTStringForKeyWithBundle (NSString *key, NSBundle *bundle)
6574{
66- return SSTStringForKeyWithBundleAndSubdirectory (key, bundle, @" localization" );
75+ return SSTStringForKeyWithBundleAndSubdirectoryAndTargetName (key, bundle, @" localization" , nil );
6776}
6877
6978NSString *SSTStringForKey (NSString *key)
0 commit comments