From e3e9148be1bb79de58068556c0e79346f738c026 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 22 Apr 1999 21:26:10 +0000 Subject: [PATCH] Improvements for localisation git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4116 72102866-910b-0410-8b05-ffd578937521 --- Headers/gnustep/base/NSBundle.h | 24 +++++++++++------ Source/NSBundle.m | 46 +++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Headers/gnustep/base/NSBundle.h b/Headers/gnustep/base/NSBundle.h index cfc22fbde..a70d19ba8 100644 --- a/Headers/gnustep/base/NSBundle.h +++ b/Headers/gnustep/base/NSBundle.h @@ -1,5 +1,5 @@ /* 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 Date: 1995 @@ -29,6 +29,7 @@ @class NSString; @class NSArray; @class NSDictionary; +@class NSMutableDictionary; extern NSString* NSBundleDidLoadNotification; extern NSString* NSShowNonLocalizedStrings; @@ -36,13 +37,14 @@ extern NSString* NSLoadedClasses; @interface NSBundle : NSObject { - NSString *_path; - NSArray* _bundleClasses; - Class _principalClass; - id _infoDict; - unsigned int _bundleType; - BOOL _codeLoaded; - unsigned int _version; + NSString *_path; + NSArray *_bundleClasses; + Class _principalClass; + NSDictionary *_infoDict; + NSMutableDictionary *_localizations; + unsigned _bundleType; + BOOL _codeLoaded; + unsigned _version; } + (NSArray *) allBundles; @@ -91,11 +93,17 @@ extern NSString* NSLoadedClasses; + (NSString*) _gnustep_target_dir; + (NSString*) _gnustep_target_os; + (NSString*) _library_combo; ++ (NSBundle*) gnustepBundle; + (NSString *) pathForGNUstepResource: (NSString *)name ofType: (NSString *)ext inDirectory: (NSString *)bundlePath; @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 #define NSLocalizedString(key, comment) \ diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 9229cd110..a56ab594a 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -83,6 +83,7 @@ static NSMapTable* _releasedBundles = NULL; where to store the class names. */ static NSBundle* _loadingBundle = nil; +static NSBundle* _gnustep_bundle = nil; static NSRecursiveLock* load_lock = nil; static BOOL _strip_after_loading = NO; @@ -242,7 +243,8 @@ _bundle_load_callback(Class theClass, Category *theCategory) env = [[NSProcessInfo processInfo] environment]; if (env) { - NSString *str; + NSMutableString *system; + NSString *str; if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil) gnustep_target_dir = [str retain]; @@ -261,6 +263,12 @@ _bundle_load_callback(Class theClass, Category *theCategory) if ((str = [env objectForKey: @"LIBRARY_COMBO"]) != nil) 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) -/* 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 variables. */ ++ (NSBundle *) gnustepBundle +{ + return _gnustep_bundle; +} + + (NSString *) pathForGNUstepResource: (NSString *)name ofType: (NSString *)ext inDirectory: (NSString *)bundlePath; { - NSString *user_path, *local_path, *system_path; - NSBundle *user_bundle = nil, *local_bundle = nil, *system_bundle = nil; + NSString *path; + NSBundle *user_bundle = nil, *local_bundle = nil; NSProcessInfo *pInfo; NSDictionary *env; - NSMutableString *user, *local, *system; + NSMutableString *user, *local; /* 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"] mutableCopy] autorelease]; [local appendString: @"/Libraries"]; - system = [[[env objectForKey: @"GNUSTEP_SYSTEM_ROOT"] - mutableCopy] autorelease]; - [system appendString: @"/Libraries"]; if (user) user_bundle = [NSBundle bundleWithPath: user]; if (local) local_bundle = [NSBundle bundleWithPath: local]; - if (system) - system_bundle = [NSBundle bundleWithPath: system]; /* Gather up the paths */ /* Search user first */ - user_path = [user_bundle pathForResource: name + path = [user_bundle pathForResource: name ofType: ext inDirectory: bundlePath]; - if (user_path) - return user_path; + if (path) + return path; /* Search local second */ - local_path = [local_bundle pathForResource: name + path = [local_bundle pathForResource: name ofType: ext inDirectory: bundlePath]; - if (local_path) - return local_path; + if (path) + return path; /* Search system last */ - system_path = [system_bundle pathForResource: name + path = [_gnustep_bundle pathForResource: name ofType: ext inDirectory: bundlePath]; - if (system_path) - return system_path; + if (path) + return path; /* Didn't find it */ return nil;