mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-19 21:53:19 +00:00
Monotone-Parent: f4861ebaae0a55ed464809d54f5ecd4f0bef9913
Monotone-Revision: d23a6bb43fc70fa7f45420eb293780b9dcfbd02c Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-04-09T18:45:14 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -21,8 +21,16 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#import <NGObjWeb/WOContext+SoObjects.h>
|
||||
#import <NGObjWeb/WORequest.h>
|
||||
|
||||
#import "NSDictionary+Utilities.h"
|
||||
#import "SOGoUser.h"
|
||||
#import "SOGoUserDefaults.h"
|
||||
|
||||
#import "NSObject+Utilities.h"
|
||||
|
||||
@implementation NSObject (SOGoObjectUtilities)
|
||||
@@ -53,4 +61,64 @@
|
||||
return nodes;
|
||||
}
|
||||
|
||||
- (NSArray *) _languagesForLabelsInContext: (WOContext *) context
|
||||
{
|
||||
NSMutableArray *languages;
|
||||
NSArray *browserLanguages;
|
||||
NSString *language;
|
||||
SOGoUser *user;
|
||||
|
||||
#warning the purpose of this method needs to be reviewed
|
||||
languages = [NSMutableArray array];
|
||||
|
||||
user = [context activeUser];
|
||||
if ([user isKindOfClass: [SOGoUser class]])
|
||||
{
|
||||
language = [[user userDefaults] language];
|
||||
[languages addObject: language];
|
||||
}
|
||||
else
|
||||
{
|
||||
browserLanguages = [[context request] browserLanguages];
|
||||
[languages addObjectsFromArray: browserLanguages];
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
- (NSString *) labelForKey: (NSString *) key
|
||||
inContext: (WOContext *) context
|
||||
{
|
||||
NSString *language, *label;
|
||||
NSArray *paths;
|
||||
NSEnumerator *languages;
|
||||
NSBundle *bundle;
|
||||
NSDictionary *strings;
|
||||
|
||||
label = nil;
|
||||
|
||||
bundle = [NSBundle bundleForClass: [self class]];
|
||||
if (!bundle)
|
||||
bundle = [NSBundle mainBundle];
|
||||
languages = [[self _languagesForLabelsInContext: context] objectEnumerator];
|
||||
|
||||
while (!label && (language = [languages nextObject]))
|
||||
{
|
||||
paths = [bundle pathsForResourcesOfType: @"strings"
|
||||
inDirectory: [NSString stringWithFormat: @"%@.lproj",
|
||||
language]
|
||||
forLocalization: language];
|
||||
if ([paths count] > 0)
|
||||
{
|
||||
strings = [NSDictionary
|
||||
dictionaryFromStringsFile: [paths objectAtIndex: 0]];
|
||||
label = [strings objectForKey: key];
|
||||
}
|
||||
}
|
||||
if (!label)
|
||||
label = key;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user