From: Jay Freeman (saurik) Date: Mon, 15 Sep 2008 07:29:11 +0000 (+0000) Subject: Added .strings support. X-Git-Tag: v0.9.3900~70 X-Git-Url: https://git.saurik.com/winterboard.git/commitdiff_plain/4fa950dfa07f3feed25005f095044b72c9bbb3c7 Added .strings support. --- diff --git a/Library.mm b/Library.mm index e971c6c..e8c4e7d 100644 --- a/Library.mm +++ b/Library.mm @@ -129,6 +129,7 @@ void WBInject(const char *classname, const char *oldname, IMP newimp, const char /* }}} */ @protocol WinterBoard +- (NSString *) wb_localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table; - (id) wb_initWithBadge:(id)badge; - (void) wb_cacheImageForIcon:(SBIcon *)icon; - (UIImage *) wb_getCachedImagedForIcon:(SBIcon *)icon; @@ -851,6 +852,33 @@ static void SBIconLabel$setInDock$(SBIconLabel *self, SEL sel, BOOL return [self wb_setInDock:docked]; } +static NSMutableDictionary *Strings_; + +static NSString *NSBundle$localizedStringForKey$value$table$(NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) { + NSString *identifier = [self bundleIdentifier]; + NSLocale *locale = [NSLocale currentLocale]; + NSString *language = [locale objectForKey:NSLocaleLanguageCode]; + //if (Debug_) + NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language); + NSString *file = table == nil ? @"Localizable" : table; + NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file]; + NSDictionary *strings; + if ((strings = [Strings_ objectForKey:name]) != nil) { + if (static_cast(strings) != [NSNull null]) strings: + if (NSString *value = [strings objectForKey:key]) + return value; + } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings", + language, file + ], self, false)) { + if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) { + [Strings_ setObject:[strings autorelease] forKey:name]; + goto strings; + } else goto null; + } else null: + [Strings_ setObject:[NSNull null] forKey:name]; + return [self wb_localizedStringForKey:key value:value table:table]; +} + @class WebCoreFrameBridge; static CGSize WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(WebCoreFrameBridge *self, SEL sel, id node, float width) { if (node == nil) @@ -1089,6 +1117,7 @@ extern "C" void WBInitialize() { //WBRename(true, "UIWebDocumentView", @selector(setViewportSize:forDocumentTypes:", (IMP) &UIWebDocumentView$setViewportSize$forDocumentTypes$); WBRename(true, "NSBundle", @selector(bundlePath), (IMP) &NSBundle$bundlePath$); + WBRename(true, "NSBundle", @selector(localizedStringForKey:value:table:), (IMP) &NSBundle$localizedStringForKey$value$table$); WBRename(true, "NSBundle", @selector(pathForResource:ofType:), (IMP) &NSBundle$pathForResource$ofType$); WBRename(true, "UIImage", @selector(initWithContentsOfFile:), (IMP) &$initWithContentsOfFile$); @@ -1129,6 +1158,7 @@ extern "C" void WBInitialize() { PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16]; Files_ = [[NSMutableDictionary alloc] initWithCapacity:16]; Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64]; + Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0]; themes_ = [[NSMutableArray alloc] initWithCapacity:8];