Improvements for localisation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4116 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-04-22 21:26:10 +00:00
parent e846ffba24
commit e3e9148be1
2 changed files with 43 additions and 27 deletions

View file

@ -1,5 +1,5 @@
/* Interface for NSBundle for GNUStep /* Interface for NSBundle for GNUStep
Copyright (C) 1995, 1997 Free Software Foundation, Inc. Copyright (C) 1995, 1997, 1999 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu> Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: 1995 Date: 1995
@ -29,6 +29,7 @@
@class NSString; @class NSString;
@class NSArray; @class NSArray;
@class NSDictionary; @class NSDictionary;
@class NSMutableDictionary;
extern NSString* NSBundleDidLoadNotification; extern NSString* NSBundleDidLoadNotification;
extern NSString* NSShowNonLocalizedStrings; extern NSString* NSShowNonLocalizedStrings;
@ -36,13 +37,14 @@ extern NSString* NSLoadedClasses;
@interface NSBundle : NSObject @interface NSBundle : NSObject
{ {
NSString *_path; NSString *_path;
NSArray* _bundleClasses; NSArray *_bundleClasses;
Class _principalClass; Class _principalClass;
id _infoDict; NSDictionary *_infoDict;
unsigned int _bundleType; NSMutableDictionary *_localizations;
BOOL _codeLoaded; unsigned _bundleType;
unsigned int _version; BOOL _codeLoaded;
unsigned _version;
} }
+ (NSArray *) allBundles; + (NSArray *) allBundles;
@ -91,11 +93,17 @@ extern NSString* NSLoadedClasses;
+ (NSString*) _gnustep_target_dir; + (NSString*) _gnustep_target_dir;
+ (NSString*) _gnustep_target_os; + (NSString*) _gnustep_target_os;
+ (NSString*) _library_combo; + (NSString*) _library_combo;
+ (NSBundle*) gnustepBundle;
+ (NSString *) pathForGNUstepResource: (NSString *)name + (NSString *) pathForGNUstepResource: (NSString *)name
ofType: (NSString *)ext ofType: (NSString *)ext
inDirectory: (NSString *)bundlePath; inDirectory: (NSString *)bundlePath;
@end @end
#define GSLocalizedString(key, comment) \
[[NSBundle gnustepBundle] localizedStringForKey:(key) value:@"" table:nil]
#define GSLocalizedStringFromTable(key, tbl, comment) \
[[NSBundle gnustepBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
#endif #endif
#define NSLocalizedString(key, comment) \ #define NSLocalizedString(key, comment) \

View file

@ -83,6 +83,7 @@ static NSMapTable* _releasedBundles = NULL;
where to store the class names. where to store the class names.
*/ */
static NSBundle* _loadingBundle = nil; static NSBundle* _loadingBundle = nil;
static NSBundle* _gnustep_bundle = nil;
static NSRecursiveLock* load_lock = nil; static NSRecursiveLock* load_lock = nil;
static BOOL _strip_after_loading = NO; static BOOL _strip_after_loading = NO;
@ -242,7 +243,8 @@ _bundle_load_callback(Class theClass, Category *theCategory)
env = [[NSProcessInfo processInfo] environment]; env = [[NSProcessInfo processInfo] environment];
if (env) if (env)
{ {
NSString *str; NSMutableString *system;
NSString *str;
if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil) if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil)
gnustep_target_dir = [str retain]; gnustep_target_dir = [str retain];
@ -261,6 +263,12 @@ _bundle_load_callback(Class theClass, Category *theCategory)
if ((str = [env objectForKey: @"LIBRARY_COMBO"]) != nil) if ((str = [env objectForKey: @"LIBRARY_COMBO"]) != nil)
library_combo = [str retain]; library_combo = [str retain];
system = [[[env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]
mutableCopy] autorelease];
[system appendString: @"/Libraries"];
_gnustep_bundle = [NSBundle bundleWithPath: system];
} }
} }
} }
@ -887,19 +895,24 @@ _bundle_load_callback(Class theClass, Category *theCategory)
@implementation NSBundle (GNUstep) @implementation NSBundle (GNUstep)
/* This is a convenience method for searching for resource files /* These are convenience methods for searching for resource files
within the GNUstep directory structure specified by the environment within the GNUstep directory structure specified by the environment
variables. */ variables. */
+ (NSBundle *) gnustepBundle
{
return _gnustep_bundle;
}
+ (NSString *) pathForGNUstepResource: (NSString *)name + (NSString *) pathForGNUstepResource: (NSString *)name
ofType: (NSString *)ext ofType: (NSString *)ext
inDirectory: (NSString *)bundlePath; inDirectory: (NSString *)bundlePath;
{ {
NSString *user_path, *local_path, *system_path; NSString *path;
NSBundle *user_bundle = nil, *local_bundle = nil, *system_bundle = nil; NSBundle *user_bundle = nil, *local_bundle = nil;
NSProcessInfo *pInfo; NSProcessInfo *pInfo;
NSDictionary *env; NSDictionary *env;
NSMutableString *user, *local, *system; NSMutableString *user, *local;
/* /*
The path of where to search for the resource files The path of where to search for the resource files
@ -916,39 +929,34 @@ _bundle_load_callback(Class theClass, Category *theCategory)
local = [[[env objectForKey: @"GNUSTEP_LOCAL_ROOT"] local = [[[env objectForKey: @"GNUSTEP_LOCAL_ROOT"]
mutableCopy] autorelease]; mutableCopy] autorelease];
[local appendString: @"/Libraries"]; [local appendString: @"/Libraries"];
system = [[[env objectForKey: @"GNUSTEP_SYSTEM_ROOT"]
mutableCopy] autorelease];
[system appendString: @"/Libraries"];
if (user) if (user)
user_bundle = [NSBundle bundleWithPath: user]; user_bundle = [NSBundle bundleWithPath: user];
if (local) if (local)
local_bundle = [NSBundle bundleWithPath: local]; local_bundle = [NSBundle bundleWithPath: local];
if (system)
system_bundle = [NSBundle bundleWithPath: system];
/* Gather up the paths */ /* Gather up the paths */
/* Search user first */ /* Search user first */
user_path = [user_bundle pathForResource: name path = [user_bundle pathForResource: name
ofType: ext ofType: ext
inDirectory: bundlePath]; inDirectory: bundlePath];
if (user_path) if (path)
return user_path; return path;
/* Search local second */ /* Search local second */
local_path = [local_bundle pathForResource: name path = [local_bundle pathForResource: name
ofType: ext ofType: ext
inDirectory: bundlePath]; inDirectory: bundlePath];
if (local_path) if (path)
return local_path; return path;
/* Search system last */ /* Search system last */
system_path = [system_bundle pathForResource: name path = [_gnustep_bundle pathForResource: name
ofType: ext ofType: ext
inDirectory: bundlePath]; inDirectory: bundlePath];
if (system_path) if (path)
return system_path; return path;
/* Didn't find it */ /* Didn't find it */
return nil; return nil;