diff --git a/SoObjects/Mailer/SOGoMailLabel.h b/SoObjects/Mailer/SOGoMailLabel.h index dec1d6839..28a3e5577 100644 --- a/SoObjects/Mailer/SOGoMailLabel.h +++ b/SoObjects/Mailer/SOGoMailLabel.h @@ -43,7 +43,7 @@ - (NSString *) color; + (NSArray *) labelsFromDefaults: (NSDictionary *) theDefaults - component: (UIxComponent *) theComponent; + component: (id) theComponent; @end diff --git a/SoObjects/Mailer/SOGoMailLabel.m b/SoObjects/Mailer/SOGoMailLabel.m index bdbce74b8..1c66786f6 100644 --- a/SoObjects/Mailer/SOGoMailLabel.m +++ b/SoObjects/Mailer/SOGoMailLabel.m @@ -65,7 +65,7 @@ + (NSArray *) labelsFromDefaults: (NSDictionary *) theDefaults - component: (UIxComponent *) theComponent + component: (id) theComponent { NSMutableArray *allLabels, *allKeys; NSString *key, *name; @@ -81,7 +81,6 @@ key = [allKeys objectAtIndex: i]; values = [theDefaults objectForKey: key]; name = [theComponent commonLabelForKey: [values objectAtIndex: 0]]; - label = [[self alloc] initWithName: key label: name color: [values objectAtIndex: 1]]; diff --git a/UI/Common/WODirectAction+SOGo.h b/UI/Common/WODirectAction+SOGo.h index a2e90cb32..e08de93c7 100644 --- a/UI/Common/WODirectAction+SOGo.h +++ b/UI/Common/WODirectAction+SOGo.h @@ -38,6 +38,7 @@ - (WOResponse *) responseWith204; - (WOResponse *) redirectToLocation: (NSString *) newLocation; +- (NSString *) commonLabelForKey: (NSString *) _str; - (NSString *) labelForKey: (NSString *) _str; - (WOResourceManager *) pageResourceManager; diff --git a/UI/Common/WODirectAction+SOGo.m b/UI/Common/WODirectAction+SOGo.m index 805acbe8c..bd8ae3461 100644 --- a/UI/Common/WODirectAction+SOGo.m +++ b/UI/Common/WODirectAction+SOGo.m @@ -35,8 +35,20 @@ #import "WODirectAction+SOGo.h" +static SoProduct *commonProduct = nil; + @implementation WODirectAction (SOGoExtension) ++ (void) initialize +{ + if (commonProduct == nil) + { + // @see commonLabelForKey: + commonProduct = [[SoProduct alloc] initWithBundle: + [NSBundle bundleForClass: NSClassFromString(@"CommonUIProduct")]]; + } +} + - (WOResponse *) responseWithStatus: (unsigned int) status { WOResponse *response; @@ -91,55 +103,60 @@ return response; } -- (NSString *) labelForKey: (NSString *) key +- (NSString *) labelForKey: (NSString *) _str + withResourceManager: (WOResourceManager *) rm { - NSString *bundleId, *userLanguage, *label; - NSArray *paths; - NSBundle *bundle; - NSDictionary *strings; - SOGoUserDefaults *ud; - static NSMutableDictionary *bundlesCache = nil; - NSMutableDictionary *languagesCache; + NSString *lKey, *lTable, *lVal; + NSRange r; - if (!bundlesCache) - bundlesCache = [NSMutableDictionary new]; + if ([_str length] == 0) + return nil; - bundle = [NSBundle bundleForClass: [self class]]; - if (!bundle) - bundle = [NSBundle mainBundle]; + if (rm == nil) + [self warnWithFormat:@"missing resource manager!"]; - bundleId = [bundle executablePath]; - languagesCache = [bundlesCache objectForKey: bundleId]; - if (!languagesCache) - { - languagesCache = [NSMutableDictionary new]; - [bundlesCache setObject: languagesCache forKey: bundleId]; - [languagesCache release]; - } + /* get parameters */ + r = [_str rangeOfString:@"/"]; + if (r.length > 0) { + lTable = [_str substringToIndex:r.location]; + lKey = [_str substringFromIndex:(r.location + r.length)]; + } + else { + lTable = nil; + lKey = _str; + } + lVal = lKey; - ud = [[context activeUser] userDefaults]; - userLanguage = [ud language]; - strings = [languagesCache objectForKey: userLanguage]; - if (!strings) - { - paths = [bundle pathsForResourcesOfType: @"strings" - inDirectory: [NSString stringWithFormat: @"%@.lproj", - userLanguage] - forLocalization: userLanguage]; - if ([paths count] > 0) - { - strings = [NSDictionary - dictionaryFromStringsFile: [paths objectAtIndex: 0]]; - if (strings) - [languagesCache setObject: strings forKey: userLanguage]; - } - } - - label = [strings objectForKey: key]; - if (!label) - label = key; + if ([lKey hasPrefix:@"$"]) + lKey = [self valueForKeyPath:[lKey substringFromIndex:1]]; + + if ([lTable hasPrefix:@"$"]) + lTable = [self valueForKeyPath:[lTable substringFromIndex:1]]; - return label; + /* lookup string */ + return [rm stringForKey: lKey + inTableNamed: lTable + withDefaultValue: lVal + languages: [context resourceLookupLanguages]]; +} + +- (NSString *) commonLabelForKey: (NSString *) _str +{ + WOResourceManager *rm; + + rm = [commonProduct resourceManager]; + + return [self labelForKey: _str withResourceManager: rm]; +} + +- (NSString *) labelForKey: (NSString *) _str +{ + WOResourceManager *rm; + /* find resource manager */ + + rm = [self pageResourceManager]; + + return [self labelForKey: _str withResourceManager: rm]; } - (WOResourceManager *) pageResourceManager diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index 75f69414d..525954124 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -18,6 +18,8 @@ * Boston, MA 02111-1307, USA. */ +#import + #import #import #import @@ -30,6 +32,7 @@ #import #import +#import #import "UIxJSONPreferences.h" @@ -75,27 +78,38 @@ if (![defaults contactsCategories]) { categoryLabels = [[[self labelForKey: @"contacts_category_labels"] - componentsSeparatedByString: @","] + componentsSeparatedByString: @","] sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; if (!categoryLabels) categoryLabels = [NSArray array]; - + [defaults setContactsCategories: categoryLabels]; dirty = YES; } - + // Populate default mail lablels, based on the user's preferred language if (![[defaults source] objectForKey: @"SOGoMailLabelsColors"]) { - NSDictionary *v; + SOGoMailLabel *label; + NSArray *labels; + id v; - v = [defaults mailLabelsColors]; - - // TODO - translate + refactor to not pass self since it's not a component - //[defaults setMailLabelsColors: [SOGoMailLabel labelsFromDefaults: v component: self]]; - [defaults setMailLabelsColors: v]; - dirty = YES; + int i; + + v = [defaults mailLabelsColors]; + + labels = [SOGoMailLabel labelsFromDefaults: v component: self]; + v = [NSMutableDictionary dictionary]; + for (i = 0; i < [labels count]; i++) + { + label = [labels objectAtIndex: i]; + [v setObject: [NSArray arrayWithObjects: [label label], [label color], nil] + forKey: [label name]]; + } + + [defaults setMailLabelsColors: v]; + dirty = YES; } if (dirty)