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 */
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 {
return nil;
}
-- (NSString *)_bundleStringForKey:(NSString *)_key
- inTableNamed:(NSString *)_tableName
- withDefaultValue:(NSString *)_default
+- (WEStringTable *)bundleTableWithName:(NSString *)_tableName
languages:(NSArray *)_languages
{
NSBundle *bundle;
path = [bundle pathForResource:_tableName
ofType:@"strings"
languages:ls];
- if (path) {
+ if (path != nil) {
NSString *tname;
id table;
table = [WEStringTable stringTableWithPath:path];
[self->nameToTable setObject:table forKey:tname];
-
- return [table stringForKey:_key withDefaultValue:_default];
+ return table;
}
}
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 {
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];
ls = [NSArray arrayWithObject:language];
+ // TODO: add support for .po
path = [_tableName stringByAppendingPathExtension:@"strings"];
path = [[language stringByAppendingPathExtension:@"lproj"]
stringByAppendingPathComponent:path];
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];
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
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
/* 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;
}