From: helge Date: Tue, 19 Jul 2005 11:15:43 +0000 (+0000) Subject: reworked string table system X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=306e99da15ee553b2f8948f4348e98df064e72ed;p=sope reworked string table system git-svn-id: http://svn.opengroupware.org/SOPE/trunk@916 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/WEExtensions/ChangeLog b/sope-appserver/WEExtensions/ChangeLog index 75adca3c..db16c355 100644 --- a/sope-appserver/WEExtensions/ChangeLog +++ b/sope-appserver/WEExtensions/ChangeLog @@ -1,3 +1,13 @@ +2005-07-19 Helge Hess + + * v4.5.75 + + * WEStringTableManager.m: reworked table manager + + * WEStringTable.m: added methods for NSDictionary compatibility + + * WEResourceManager.m: updated API to match NGObjWeb + 2005-07-11 Marcus Mueller * WEExtensions-Info.plist: fixed bundle identifier diff --git a/sope-appserver/WEExtensions/Version b/sope-appserver/WEExtensions/Version index 6df08dfe..43acebab 100644 --- a/sope-appserver/WEExtensions/Version +++ b/sope-appserver/WEExtensions/Version @@ -1,5 +1,6 @@ # version file -SUBMINOR_VERSION:=74 +SUBMINOR_VERSION:=75 +# v4.5.75 requires libNGObjWeb v4.5.174 # v4.5.65 requires libNGObjWeb v4.5.106 diff --git a/sope-appserver/WEExtensions/WEResourceManager.m b/sope-appserver/WEExtensions/WEResourceManager.m index 5cdf74ab..d5f7ea3e 100644 --- a/sope-appserver/WEExtensions/WEResourceManager.m +++ b/sope-appserver/WEExtensions/WEResourceManager.m @@ -894,24 +894,41 @@ checkCache(NSDictionary *_cache, WEResourceKey *_key, return [self->labelManager labelForKey:_key component:_component]; } +- (id)stringTableWithName:(NSString *)_tableName + inFramework:(NSString *)_framework + languages:(NSArray *)_languages +{ + id table; + + table = [self->labelManager + stringTableWithName:_tableName inFramework:_framework + languages:_languages]; + if (table != nil) return table; + + return [super stringTableWithName:_tableName inFramework:_framework + languages:_languages]; +} + - (NSString *)stringForKey:(NSString *)_key inTableNamed:(NSString *)_tableName - withDefaultValue:(NSString *)_default - languages:(NSArray *)_langs + withDefaultValue:(NSString *)_defaultValue + inFramework:(NSString *)_framework + languages:(NSArray *)_languages { NSString *s; s = [self->labelManager stringForKey:_key inTableNamed:_tableName - withDefaultValue:_default languages:_langs]; + withDefaultValue:_defaultValue languages:_languages]; if (s != nil) return s; s = [super stringForKey:_key inTableNamed:_tableName - withDefaultValue:_default - languages:_langs]; + withDefaultValue:_defaultValue + inFramework:_framework + languages:_languages]; if (s != nil) return s; - return s != nil ? s : _default; + return s != nil ? s : _defaultValue; } /* debugging */ diff --git a/sope-appserver/WEExtensions/WEStringTable.h b/sope-appserver/WEExtensions/WEStringTable.h index bf7b2337..1562443b 100644 --- a/sope-appserver/WEExtensions/WEStringTable.h +++ b/sope-appserver/WEExtensions/WEStringTable.h @@ -32,7 +32,7 @@ TODO: support standard translation formats. */ -@class NSString, NSDictionary, NSDate; +@class NSString, NSDictionary, NSDate, NSArray, NSEnumerator; @interface WEStringTable : NSObject { @@ -47,6 +47,15 @@ - (NSString *)stringForKey:(NSString *)_key withDefaultValue:(NSString *)_def; +/* fake being a dictionary */ + +- (NSEnumerator *)keyEnumerator; +- (NSEnumerator *)objectEnumerator; +- (id)objectForKey:(id)_key; +- (unsigned int)count; +- (NSArray *)allKeys; +- (NSArray *)allValues; + @end #endif /* __OGoFoundation_WEStringTable_H__ */ diff --git a/sope-appserver/WEExtensions/WEStringTable.m b/sope-appserver/WEExtensions/WEStringTable.m index 3886b7ac..667a693b 100644 --- a/sope-appserver/WEExtensions/WEStringTable.m +++ b/sope-appserver/WEExtensions/WEStringTable.m @@ -124,6 +124,39 @@ static BOOL useLatin1Strings = NO; return value ? value : _def; } +/* fake being a dictionary */ + +- (NSEnumerator *)keyEnumerator { + [self checkState]; + return [self->data keyEnumerator]; +} +- (NSEnumerator *)objectEnumerator { + [self checkState]; + return [self->data objectEnumerator]; +} +- (id)objectForKey:(id)_key { + [self checkState]; + return [self->data objectForKey:_key]; +} +- (unsigned int)count { + [self checkState]; + return [self->data count]; +} +- (NSArray *)allKeys { + [self checkState]; + return [self->data allKeys]; +} +- (NSArray *)allValues { + [self checkState]; + return [self->data allValues]; +} + +/* KVC */ + +- (id)valueForKey:(NSString *)_key { + return [self objectForKey:_key]; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/sope-appserver/WEExtensions/WEStringTableManager.h b/sope-appserver/WEExtensions/WEStringTableManager.h index ebb212a8..b763dd0a 100644 --- a/sope-appserver/WEExtensions/WEStringTableManager.h +++ b/sope-appserver/WEExtensions/WEStringTableManager.h @@ -53,6 +53,10 @@ withDefaultValue:(NSString *)_default languages:(NSArray *)_languages; +- (id)stringTableWithName:(NSString *)_tableName + inFramework:(NSString *)_framework + languages:(NSArray *)_languages; + @end diff --git a/sope-appserver/WEExtensions/WEStringTableManager.m b/sope-appserver/WEExtensions/WEStringTableManager.m index 83eb2ff1..c47abb49 100644 --- a/sope-appserver/WEExtensions/WEStringTableManager.m +++ b/sope-appserver/WEExtensions/WEStringTableManager.m @@ -223,9 +223,7 @@ static BOOL debugOn = NO; return nil; } -- (NSString *)_bundleStringForKey:(NSString *)_key - inTableNamed:(NSString *)_tableName - withDefaultValue:(NSString *)_default +- (WEStringTable *)bundleTableWithName:(NSString *)_tableName languages:(NSArray *)_languages { NSBundle *bundle; @@ -255,7 +253,7 @@ static BOOL debugOn = NO; path = [bundle pathForResource:_tableName ofType:@"strings" languages:ls]; - if (path) { + if (path != nil) { NSString *tname; id table; @@ -264,8 +262,7 @@ static BOOL debugOn = NO; table = [WEStringTable stringTableWithPath:path]; [self->nameToTable setObject:table forKey:tname]; - - return [table stringForKey:_key withDefaultValue:_default]; + return table; } } @@ -273,20 +270,21 @@ static BOOL debugOn = NO; ofType:@"strings" languages:nil]; - if (path) { + if (path != nil) { WEStringTable *table; table = [WEStringTable stringTableWithPath:path]; [self->nameToTable setObject:table forKey:_tableName]; - - return [table stringForKey:_key withDefaultValue:_default]; + return table; } - else if (debugOn) { + + if (debugOn) { + // TODO: use logging NSLog(@"WARNING: missing string table %@ in bundle %@", _tableName, [bundle bundlePath]); } - return _default; + return nil; } + (NSString *)gsTranslationsSubpath { @@ -358,16 +356,14 @@ static BOOL debugOn = NO; return ltranslations; } -- (NSString *)_resourceStringForKey:(NSString *)_key - inTableNamed:(NSString *)_tableName - withDefaultValue:(NSString *)_default +- (WEStringTable *)resourceTableWithName:(NSString *)_tableName languages:(NSArray *)_languages { NSString *rpath, *path; NSEnumerator *e; NSString *language; NSFileManager *fm; - + if (_tableName == nil) _tableName = @"default"; fm = [NSFileManager defaultManager]; @@ -396,6 +392,7 @@ static BOOL debugOn = NO; ls = [NSArray arrayWithObject:language]; + // TODO: add support for .po path = [_tableName stringByAppendingPathExtension:@"strings"]; path = [[language stringByAppendingPathExtension:@"lproj"] stringByAppendingPathComponent:path]; @@ -410,11 +407,12 @@ static BOOL debugOn = NO; table = [WEStringTable stringTableWithPath:path]; [self->nameToTable setObject:table forKey:tname]; - return [table stringForKey:_key withDefaultValue:_default]; + return table; } /* look into resource dir */ + // TODO: add support for .po path = [_tableName stringByAppendingPathExtension:@"strings"]; path = [rpath stringByAppendingPathComponent:path]; @@ -426,14 +424,13 @@ static BOOL debugOn = NO; self->nameToTable = [[NSMutableDictionary alloc] initWithCapacity:16]; [self->nameToTable setObject:table forKey:_tableName]; - - return [table stringForKey:_key withDefaultValue:_default]; + return table; } + // TODO: use SOPE 4.5 logging framework if (debugOn) NSLog(@"WARNING: missing string table %@ in %@", _tableName, path); - - return _default; + return nil; } - (NSString *)stringForKey:(NSString *)_key @@ -441,12 +438,14 @@ static BOOL debugOn = NO; withDefaultValue:(NSString *)_default languages:(NSArray *)_languages { + WEStringTable *table; NSString *s; - if (_tableName == nil) _tableName = @"default"; + if (_tableName == nil) // TODO: Localizable in NGObjWeb + _tableName = @"default"; /* look into string cache */ - + s = [self _cachedStringForKey:_key inTableNamed:_tableName withDefaultValue:_default @@ -458,17 +457,30 @@ static BOOL debugOn = NO; /* search for string */ - s = [self _resourceStringForKey:_key - inTableNamed:_tableName - withDefaultValue:nil - languages:_languages]; - if (s != nil) return s; + if ((table = [self resourceTableWithName:_tableName languages:_languages])){ + if ((s = [table stringForKey:_key withDefaultValue:nil]) != nil) + return s; + } + + if ((table = [self bundleTableWithName:_tableName languages:_languages])){ + if ((s = [table stringForKey:_key withDefaultValue:nil]) != nil) + return s; + } - s = [self _bundleStringForKey:_key - inTableNamed:_tableName - withDefaultValue:nil - languages:_languages]; - if (s != nil) return s; + // TODO: shouldn't we return the default value? + return nil; +} + +- (id)stringTableWithName:(NSString *)_tableName + inFramework:(NSString *)_framework + languages:(NSArray *)_languages +{ + WEStringTable *table; + + if ((table = [self resourceTableWithName:_tableName languages:_languages])) + return table; + if ((table = [self bundleTableWithName:_tableName languages:_languages])) + return table; return nil; }