diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index ad19fa26bc..7e52d8b821 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -78,6 +78,32 @@ - (NSDictionary *) _localizedCategoryLabels return labelsDictionary; } +- (NSDictionary *) _localizedContactsLabels +{ + NSArray *categoryLabels, *localizedCategoryLabels; + NSDictionary *labelsDictionary; + + labelsDictionary = nil; + localizedCategoryLabels = [[self labelForKey: @"contacts_category_labels" + withResourceManager: [preferencesProduct resourceManager]] + componentsSeparatedByString: @","]; + categoryLabels = [[[preferencesProduct resourceManager] + stringForKey: @"contacts_category_labels" + inTableNamed: nil + withDefaultValue: @"" + languages: [NSArray arrayWithObject: @"English"]] + componentsSeparatedByString: @","]; + + if ([localizedCategoryLabels count] == [categoryLabels count]) + labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels + forKeys: categoryLabels]; + else + [self logWithFormat: @"ERROR: localizable strings contacts_category_labels is incorrect for language %@", + [[[context activeUser] userDefaults] language]]; + + return labelsDictionary; +} + - (WOResponse *) activeExternalSieveScriptsAction { NGSieveClient *client; @@ -121,7 +147,7 @@ - (NSString *) jsonDefaults SOGoUserDefaults *defaults; SOGoDomainDefaults *domainDefaults; NSMutableArray *accounts; - NSDictionary *categoryLabels, *vacationOptions; + NSDictionary *calendarCategoryLabels, *contactsCategoriesLabels, *vacationOptions; if (!preferencesProduct) { @@ -131,7 +157,8 @@ - (NSString *) jsonDefaults defaults = [[context activeUser] userDefaults]; domainDefaults = [[context activeUser] domainDefaults]; - categoryLabels = nil; + calendarCategoryLabels = nil; + contactsCategoriesLabels = nil; // // Default General preferences @@ -223,7 +250,7 @@ - (NSString *) jsonDefaults { NSArray *defaultCalendarCategories; - categoryLabels = [self _localizedCategoryLabels]; + calendarCategoryLabels = [self _localizedCategoryLabels]; if ((defaultCalendarCategories = [defaults calendarCategories])) { @@ -239,7 +266,7 @@ - (NSString *) jsonDefaults for (count = 0; count < max; count++) { label = [defaultCalendarCategories objectAtIndex: count]; - if (!(localizedLabel = [categoryLabels objectForKey: label])) + if (!(localizedLabel = [calendarCategoryLabels objectForKey: label])) { localizedLabel = label; } @@ -252,15 +279,15 @@ - (NSString *) jsonDefaults { // Calendar categories are taken from localizable strings - [defaults setCalendarCategories: [categoryLabels allValues]]; + [defaults setCalendarCategories: [calendarCategoryLabels allValues]]; } } if (![[defaults source] objectForKey: @"SOGoCalendarCategoriesColors"]) { NSDictionary *defaultCalendarCategoriesColors; - if (!categoryLabels) - categoryLabels = [self _localizedCategoryLabels]; + if (!calendarCategoryLabels) + calendarCategoryLabels = [self _localizedCategoryLabels]; if ((defaultCalendarCategoriesColors = [defaults calendarCategoriesColors])) { @@ -278,7 +305,7 @@ - (NSString *) jsonDefaults for (count = 0; count < max; count++) { label = [defaultCalendarCategories objectAtIndex: count]; - if (!(localizedLabel = [categoryLabels objectForKey: label])) + if (!(localizedLabel = [calendarCategoryLabels objectForKey: label])) { localizedLabel = label; } @@ -296,7 +323,7 @@ - (NSString *) jsonDefaults NSMutableDictionary *colors; int i; - calendarCategories = [categoryLabels allValues]; + calendarCategories = [calendarCategoryLabels allValues]; colors = [NSMutableDictionary dictionaryWithCapacity: [calendarCategories count]]; for (i = 0; i < [calendarCategories count]; i++) @@ -311,18 +338,41 @@ - (NSString *) jsonDefaults // // Populate default contact categories, based on the user's preferred language // - if (![defaults contactsCategories]) + if (![[defaults source] objectForKey: @"SOGoContactsCategories"]) { NSArray *contactsCategories; - contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]] - componentsSeparatedByString: @","] trimmedComponents] - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + contactsCategoriesLabels = [self _localizedContactsLabels]; + + if((contactsCategories = [defaults contactsCategories])) + { + // Contact categories are taken from SOGo's configuration or SOGoDefaults.plist + + NSMutableArray *filteredContactsCategories; + NSString *label, *localizedLabel; + int count, max; - if (!contactsCategories) - contactsCategories = [NSArray array]; + max = [contactsCategories count]; + filteredContactsCategories = [NSMutableArray arrayWithCapacity: max]; + + for (count = 0; count < max; count++) + { + label = [contactsCategories objectAtIndex: count]; + if (!(localizedLabel = [contactsCategoriesLabels objectForKey: label])) + { + localizedLabel = label; + } + [filteredContactsCategories addObject: localizedLabel]; + } + + [defaults setContactsCategories: filteredContactsCategories]; + } + else + { + // Contact categories are taken from localizable strings - [defaults setContactsCategories: contactsCategories]; + [defaults setContactsCategories: [contactsCategoriesLabels allValues]]; + } } if (![[defaults source] objectForKey: @"SOGoMailAddOutgoingAddresses"]) diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index fcc85137a1..43bbc7fb2a 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -909,18 +909,63 @@ - (NSString *) defaultCalendarCategoriesColors // // Used by templates // +- (NSDictionary *) _localizedContactsLabels +{ + NSArray *categoryLabels, *localizedCategoryLabels; + NSDictionary *labelsDictionary; + + labelsDictionary = nil; + localizedCategoryLabels = [[self labelForKey: @"contacts_category_labels" + withResourceManager: [self resourceManager]] + componentsSeparatedByString: @","]; + categoryLabels = [[[self resourceManager] + stringForKey: @"contacts_category_labels" + inTableNamed: nil + withDefaultValue: @"" + languages: [NSArray arrayWithObject: @"English"]] + componentsSeparatedByString: @","]; + + if ([localizedCategoryLabels count] == [categoryLabels count]) + labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels + forKeys: categoryLabels]; + else + [self logWithFormat: @"ERROR: localizable strings contacts_category_labels is incorrect for language %@", + [[[context activeUser] userDefaults] language]]; + + return labelsDictionary; +} + - (NSString *) defaultContactsCategories { - NSArray *contactsCategories; + NSArray *labels; + NSDictionary *localizedLabels; + NSMutableArray *defaultCategoriesLabels; + NSString *label, *localizedLabel; + unsigned int i; + + localizedLabels = [self _localizedContactsLabels]; + labels = [[SOGoSystemDefaults sharedSystemDefaults] contactsCategories]; + defaultCategoriesLabels = [NSMutableArray array]; - contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [self resourceManager]] - componentsSeparatedByString: @","] trimmedComponents] - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + if(labels) + { + for (i = 0; i < [labels count]; i++) + { + label = [labels objectAtIndex: i]; + if (!(localizedLabel = [localizedLabels objectForKey: label])) + { + localizedLabel = label; + } + [defaultCategoriesLabels addObject: localizedLabel]; + } + } + else + { + defaultCategoriesLabels = [localizedLabels allValues]; + } - if (!contactsCategories) - contactsCategories = [NSArray array]; - return [contactsCategories jsonRepresentation]; + return [defaultCategoriesLabels jsonRepresentation]; } //