mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-04-25 00:11:46 +00:00
* GSWeb/GSWResourceManager.m
reformat statics, add TheStringsTableLock add _cachedStringsTable() add _cachedStringForKey() rewrote -stringForKey:inTableNamed:withDefaultValue:inFramework:languages: use NONESTR, not @"NONE" * Testing/DynamicElements/ImagePage.h * Testing/DynamicElements/Resources/Chinese.lproj/Localizable.strings * Testing/DynamicElements/Resources/Russian.lproj/Localizable.strings * Testing/DynamicElements/Resources/French.lproj/Localizable.strings * Testing/DynamicElements/Resources/English.lproj/Localizable.strings * Testing/DynamicElements/Resources/German.lproj/Localizable.strings * Testing/DynamicElements/ImagePage.m * Testing/DynamicElements/ImagePage.wo add test for GSWResourceManager's -stringForKey:inTableNamed:withDefaultValue:inFramework:languages: * Testing/DynamicElements/DynamicElements.m set UTF8 encoding * Testing/DynamicElements/GNUmakefile add new files git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30841 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3fb75c4004
commit
029c4d499e
13 changed files with 199 additions and 29 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2010-06-23 David Wetzel <dave@turbocat.de>
|
||||
* GSWeb/GSWResourceManager.m
|
||||
reformat statics, add TheStringsTableLock
|
||||
add _cachedStringsTable()
|
||||
add _cachedStringForKey()
|
||||
rewrote -stringForKey:inTableNamed:withDefaultValue:inFramework:languages:
|
||||
use NONESTR, not @"NONE"
|
||||
* Testing/DynamicElements/ImagePage.h
|
||||
* Testing/DynamicElements/Resources/Chinese.lproj/Localizable.strings
|
||||
* Testing/DynamicElements/Resources/Russian.lproj/Localizable.strings
|
||||
* Testing/DynamicElements/Resources/French.lproj/Localizable.strings
|
||||
* Testing/DynamicElements/Resources/English.lproj/Localizable.strings
|
||||
* Testing/DynamicElements/Resources/German.lproj/Localizable.strings
|
||||
* Testing/DynamicElements/ImagePage.m
|
||||
* Testing/DynamicElements/ImagePage.wo
|
||||
add test for GSWResourceManager's -stringForKey:inTableNamed:withDefaultValue:inFramework:languages:
|
||||
* Testing/DynamicElements/DynamicElements.m
|
||||
set UTF8 encoding
|
||||
* Testing/DynamicElements/GNUmakefile
|
||||
add new files
|
||||
|
||||
2010-06-22 David Wetzel <dave@turbocat.de>
|
||||
* GSWeb/GSWResponse.m
|
||||
* GSWeb/GSWHTTPIO.m
|
||||
|
|
|
@ -37,8 +37,10 @@ RCS_ID("$Id$")
|
|||
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
||||
#include <GNUstepBase/NSString+GNUstepBase.h>
|
||||
|
||||
static NSString * emptyStr=@"";
|
||||
|
||||
static NSString * NONESTR = @"NONE";
|
||||
static NSString * localNotFoundMarker=@"NOTFOUND";
|
||||
static NSMutableDictionary * TheStringsTableDictionary = nil;
|
||||
static NSLock * TheStringsTableLock = nil;
|
||||
//====================================================================
|
||||
@implementation GSWResourceManager
|
||||
|
||||
|
@ -48,7 +50,6 @@ NSString* globalMimePListPathName=nil;
|
|||
NSDictionary* localGS2ISOLanguages=nil;
|
||||
NSDictionary* localISO2GSLanguages=nil;
|
||||
NSString* globalLanguagesPListPathName=nil;
|
||||
NSString* localNotFoundMarker=@"NOTFOUND";
|
||||
NSMutableDictionary *globalPathCache = nil;
|
||||
//--------------------------------------------------------------------
|
||||
+(void)initialize
|
||||
|
@ -158,6 +159,10 @@ NSMutableDictionary *globalPathCache = nil;
|
|||
if (!globalPathCache) {
|
||||
globalPathCache = [NSMutableDictionary new];
|
||||
}
|
||||
if (!TheStringsTableDictionary) {
|
||||
TheStringsTableDictionary = [NSMutableDictionary new];
|
||||
TheStringsTableLock = [NSLock new];
|
||||
}
|
||||
//TODO NSBundle* mainBundle=[NSBundle mainBundle];
|
||||
NSArray* allFrameworks=[NSBundle allFrameworks];
|
||||
int i=0;
|
||||
|
@ -365,40 +370,121 @@ NSMutableDictionary *globalPathCache = nil;
|
|||
return url;
|
||||
}
|
||||
|
||||
|
||||
static NSDictionary * _cachedStringsTable(GSWResourceManager * resmanager, NSString * tableName, NSString * framework, NSString * lang)
|
||||
{
|
||||
NSDictionary * stringTableDict = nil;
|
||||
|
||||
if (tableName)
|
||||
{
|
||||
NSString * languageKey = (!lang) ? NONESTR : lang;
|
||||
NSString * frameworkNameKey = (!framework) ? NONESTR : framework;
|
||||
NSString * tableKey = [NSString stringWithFormat:@"%@_%@_%@", tableName, frameworkNameKey, languageKey];
|
||||
|
||||
SYNCHRONIZED(TheStringsTableLock) {
|
||||
stringTableDict = [TheStringsTableDictionary objectForKey:tableKey];
|
||||
} END_SYNCHRONIZED;
|
||||
|
||||
if (!stringTableDict)
|
||||
{
|
||||
// load from file
|
||||
if (tableName)
|
||||
{
|
||||
NSString * path;
|
||||
|
||||
path = [resmanager pathForResourceNamed:[tableName stringByAppendingString:@".strings"]
|
||||
inFramework:framework
|
||||
language:lang];
|
||||
|
||||
if (path) {
|
||||
NSString * fileString = nil;
|
||||
NSStringEncoding encoding = 0;
|
||||
NSError * error = nil;
|
||||
|
||||
fileString = [NSString stringWithContentsOfFile:path
|
||||
usedEncoding:&encoding
|
||||
error:&error];
|
||||
|
||||
if (error) {
|
||||
NSLog(@"%s: %@", __PRETTY_FUNCTION__, error);
|
||||
} else {
|
||||
stringTableDict = [fileString propertyListFromStringsFileFormat];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stringTableDict)
|
||||
{
|
||||
stringTableDict = (NSDictionary*) [NSNull null];
|
||||
}
|
||||
SYNCHRONIZED(TheStringsTableLock) {
|
||||
[TheStringsTableDictionary setObject:stringTableDict
|
||||
forKey:tableKey];
|
||||
} END_SYNCHRONIZED;
|
||||
}
|
||||
// we are using a static object so the == is ok here.
|
||||
if ((stringTableDict == (NSDictionary*) [NSNull null]))
|
||||
{
|
||||
stringTableDict = nil;
|
||||
}
|
||||
}
|
||||
return stringTableDict;
|
||||
}
|
||||
|
||||
|
||||
static NSString * _cachedStringForKey(GSWResourceManager * resmanager, NSString * key, NSString * tableName, NSString * framework, NSString * lang)
|
||||
{
|
||||
NSDictionary * stringTableDict = _cachedStringsTable(resmanager, tableName, framework, lang);
|
||||
NSString * string = nil;
|
||||
|
||||
if ((stringTableDict) && (key))
|
||||
{
|
||||
string = [stringTableDict objectForKey:key];
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return value: string from tableName using key to look it up.
|
||||
* first searches the tableName.strings file in the locale
|
||||
* subdirectories. languages specifies the search order.
|
||||
*/
|
||||
-(NSString*)stringForKey:(NSString*)key
|
||||
inTableNamed:(NSString*)tableName
|
||||
inTableNamed:(NSString*)aTableName
|
||||
withDefaultValue:(NSString*)defaultValue
|
||||
inFramework:(NSString*)framework
|
||||
languages:(NSArray*)languages
|
||||
{
|
||||
NSLog(@"I am working on this -- dw");
|
||||
// NSString* string=nil;
|
||||
// [self lock];
|
||||
// NS_DURING
|
||||
// {
|
||||
// string=[self lockedStringForKey:key
|
||||
// inTableNamed:tableName
|
||||
// inFramework:framework
|
||||
// languages:languages];
|
||||
// }
|
||||
// NS_HANDLER
|
||||
// {
|
||||
// //TODO
|
||||
// [self unlock];
|
||||
// [localException raise];
|
||||
// }
|
||||
// NS_ENDHANDLER;
|
||||
// [self unlock];
|
||||
// if (!string)
|
||||
// string=defaultValue;
|
||||
// return string;
|
||||
return nil;
|
||||
};
|
||||
NSString * string=nil;
|
||||
NSString * tableName;
|
||||
|
||||
if (!aTableName) {
|
||||
tableName = @"Localizable";
|
||||
} else {
|
||||
tableName = aTableName;
|
||||
}
|
||||
|
||||
if (languages)
|
||||
{
|
||||
NSUInteger count = [languages count];
|
||||
NSUInteger idx;
|
||||
|
||||
for(idx = 0; idx < count; idx++)
|
||||
{
|
||||
NSString * lang = [languages objectAtIndex:idx];
|
||||
string = _cachedStringForKey(self, key, tableName, framework, lang);
|
||||
if (string)
|
||||
{
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
string = _cachedStringForKey(self, key, tableName, framework, nil);
|
||||
|
||||
if (!string)
|
||||
string=defaultValue;
|
||||
return string;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
-(void)unlock
|
||||
|
@ -490,7 +576,7 @@ NSMutableDictionary *globalPathCache = nil;
|
|||
NSString * key = [NSString stringWithFormat:@"%@:%@:%@",
|
||||
resourceName,
|
||||
(frameworkName) ? frameworkName : @"APP",
|
||||
(language) ? language : @"NONE"];
|
||||
(language) ? language : NONESTR];
|
||||
|
||||
cachedPath = [globalPathCache objectForKey:key];
|
||||
|
||||
|
@ -509,7 +595,7 @@ NSMutableDictionary *globalPathCache = nil;
|
|||
NSString * key = [NSString stringWithFormat:@"%@:%@:%@",
|
||||
resourceName,
|
||||
(frameworkName) ? frameworkName : @"APP",
|
||||
(language) ? language : @"NONE"];
|
||||
(language) ? language : NONESTR];
|
||||
|
||||
if (!path) {
|
||||
path = localNotFoundMarker;
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
*/
|
||||
|
||||
@implementation DynamicElements
|
||||
- (id) init
|
||||
{
|
||||
if ([super init]) {
|
||||
[WOMessage setDefaultEncoding: NSUTF8StringEncoding];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface Session: WOSession
|
||||
|
|
|
@ -33,6 +33,11 @@ DynamicElements_GSWAPP_INFO_PLIST=Resources/Info-DynamicElements.plist
|
|||
# The bundle resource files and directories
|
||||
DynamicElements_RESOURCE_FILES = \
|
||||
Resources/Info-DynamicElements.plist \
|
||||
Resources/Chinese.lproj \
|
||||
Resources/English.lproj \
|
||||
Resources/French.lproj \
|
||||
Resources/German.lproj \
|
||||
Resources/Russian.lproj \
|
||||
|
||||
DynamicElements_WEBSERVER_RESOURCE_FILES = testpic.jpg
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
@interface ImagePage: BasePage
|
||||
{
|
||||
}
|
||||
- (NSString*) helloMessage;
|
||||
|
||||
@end
|
||||
|
||||
#endif //_ImagePage_h__
|
||||
|
|
|
@ -34,5 +34,18 @@
|
|||
|
||||
@implementation ImagePage
|
||||
|
||||
- (NSString*) helloMessage
|
||||
{
|
||||
NSString * helloStr;
|
||||
|
||||
helloStr = [[WOApp resourceManager] stringForKey:@"hello"
|
||||
inTableNamed:nil
|
||||
withDefaultValue:@"string not found"
|
||||
inFramework:nil
|
||||
languages:[self languages]];
|
||||
|
||||
return helloStr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<h2>GSWImage Test 1 (Web server resources)</h2>
|
||||
<br/><webobject name="HelloString"></webobject>
|
||||
<br/>
|
||||
<webobject name="TestImage"></webobject>
|
||||
<hr/>
|
||||
|
|
|
@ -9,3 +9,7 @@ TestImage: WOImage
|
|||
filename = "testpic.jpg";
|
||||
alt = "test";
|
||||
}
|
||||
HelloString: WOString
|
||||
{
|
||||
value = helloMessage;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
Localizable.strings
|
||||
Created by dave on 23.06.10.
|
||||
*/
|
||||
|
||||
"hello" = "你好";
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
Localizable.strings
|
||||
Created by dave on 23.06.10.
|
||||
*/
|
||||
|
||||
"hello" = "Hello";
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
Localizable.strings
|
||||
Created by dave on 23.06.10.
|
||||
*/
|
||||
|
||||
"hello" = "Bonjour";
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
Localizable.strings
|
||||
Created by dave on 23.06.10.
|
||||
*/
|
||||
|
||||
"hello" = "Hallo";
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
Localizable.strings
|
||||
Created by dave on 23.06.10.
|
||||
*/
|
||||
|
||||
"hello" = "Привет";
|
Loading…
Reference in a new issue