(fix) correctly localize mail labels from common bundle
parent
4252b66b6e
commit
772a682655
|
@ -43,7 +43,7 @@
|
|||
- (NSString *) color;
|
||||
|
||||
+ (NSArray *) labelsFromDefaults: (NSDictionary *) theDefaults
|
||||
component: (UIxComponent *) theComponent;
|
||||
component: (id) theComponent;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -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]];
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
- (WOResponse *) responseWith204;
|
||||
- (WOResponse *) redirectToLocation: (NSString *) newLocation;
|
||||
|
||||
- (NSString *) commonLabelForKey: (NSString *) _str;
|
||||
- (NSString *) labelForKey: (NSString *) _str;
|
||||
|
||||
- (WOResourceManager *) pageResourceManager;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSDictionary.h>
|
||||
|
||||
#import <NGObjWeb/WOContext+SoObjects.h>
|
||||
#import <NGObjWeb/WODirectAction.h>
|
||||
#import <NGObjWeb/WOResponse.h>
|
||||
|
@ -30,6 +32,7 @@
|
|||
#import <Mailer/SOGoMailLabel.h>
|
||||
|
||||
#import <SOGoUI/UIxComponent.h>
|
||||
#import <UI/Common/WODirectAction+SOGo.h>
|
||||
|
||||
#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)
|
||||
|
|
Loading…
Reference in New Issue