2002-10-31 00:02:10 +00:00
|
|
|
/** Interface for NSBundle for GNUStep -*-objc-*-
|
|
|
|
Copyright (C) 1995, 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
|
1995-07-01 19:01:11 +00:00
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: 1995
|
2002-10-31 00:02:10 +00:00
|
|
|
|
|
|
|
Updates by various authors.
|
|
|
|
Documentation by Nicola Pero <n.pero@mi.flashnet.it>
|
2002-08-20 10:22:05 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-23 03:47:56 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1995-03-23 03:47:56 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2002-08-20 10:22:05 +00:00
|
|
|
|
1995-03-23 03:47:56 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
2002-08-20 10:22:05 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1995-03-23 03:47:56 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2006-09-13 10:20:49 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
2002-08-20 10:22:05 +00:00
|
|
|
*/
|
1995-03-23 03:47:56 +00:00
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
#ifndef __NSBundle_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSBundle_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
1995-03-18 17:15:15 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
#import <Foundation/NSString.h>
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
|
|
@class NSString;
|
|
|
|
@class NSArray;
|
1997-01-06 22:30:33 +00:00
|
|
|
@class NSDictionary;
|
2006-05-05 11:06:57 +00:00
|
|
|
@class NSMutableArray;
|
1999-04-22 21:26:10 +00:00
|
|
|
@class NSMutableDictionary;
|
1997-01-06 22:30:33 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
|
2008-06-06 13:57:06 +00:00
|
|
|
enum {
|
|
|
|
NSBundleExecutableArchitectureI386 = 0x00000007,
|
|
|
|
NSBundleExecutableArchitecturePPC = 0x00000012,
|
|
|
|
NSBundleExecutableArchitecturePPC64 = 0x01000012,
|
2012-07-20 12:39:35 +00:00
|
|
|
NSBundleExecutableArchitectureX86_64 = 0x01000007
|
2008-06-06 13:57:06 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Notification posted when a bundle is loaded. The notification object is
|
|
|
|
* the [NSBundle] itself. The notification also contains a <em>userInfo</em>
|
|
|
|
* dictionary, containing the single key '<code>NSLoadedClasses</code>',
|
|
|
|
* mapped to an [NSArray] containing the names of each class and category
|
|
|
|
* loaded (as strings).
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
GS_EXPORT NSString* const NSBundleDidLoadNotification;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A user default affecting the behavior of
|
|
|
|
* [NSBundle-localizedStringForKey:value:table:]. If set, the value of the
|
|
|
|
* key will be returned as an uppercase string rather than any localized
|
|
|
|
* equivalent found. This can be useful during development to check where
|
|
|
|
* a given string in the UI is "coming from".
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
GS_EXPORT NSString* const NSShowNonLocalizedStrings;
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When an [NSBundle] loads classes and posts a
|
|
|
|
* <code>NSBundleDidLoadNotification</code>, its <em>userInfo</em> dictionary
|
|
|
|
* contains this key, mapped to an [NSArray] containing the names of each
|
|
|
|
* class and category loaded (as strings).
|
|
|
|
*/
|
2004-09-19 23:19:53 +00:00
|
|
|
GS_EXPORT NSString* const NSLoadedClasses;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/**
|
|
|
|
<p>
|
|
|
|
NSBundle provides methods for locating and handling application (and tool)
|
|
|
|
resources at runtime. Resources includes any time of file that the
|
2002-11-20 04:48:35 +00:00
|
|
|
application might need, such as images, nib (gorm or gmodel) files,
|
2002-11-19 20:39:29 +00:00
|
|
|
localization files, and any other type of file that an application
|
|
|
|
might need to use to function. Resources also include executable
|
|
|
|
code, which can be dynamically linked into the application at
|
|
|
|
runtime. These files and executable code are commonly put together
|
|
|
|
into a directory called a bundle.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
NSBundle knows how these bundles are organized and can search for
|
|
|
|
files inside a bundle. NSBundle also handles locating the
|
|
|
|
executable code, linking this in and initializing any classes that
|
|
|
|
are located in the code. NSBundle also handles Frameworks, which are
|
|
|
|
basically a bundle that contains a library archive. The
|
|
|
|
organization of a framework is a little difference, but in most
|
|
|
|
respects there is no difference between a bundle and a framework.
|
2002-11-20 04:48:35 +00:00
|
|
|
</p>
|
2002-11-19 20:39:29 +00:00
|
|
|
<p>
|
2002-11-20 04:48:35 +00:00
|
|
|
There is one special bundle, called the mainBundle, which is
|
2002-11-19 20:39:29 +00:00
|
|
|
basically the application itself. The mainBundle is always loaded
|
|
|
|
(of course), but you can still perform other operations on the
|
|
|
|
mainBundle, such as searching for files, just as with any other
|
|
|
|
bundle.
|
|
|
|
</p>
|
|
|
|
*/
|
1995-03-18 17:15:15 +00:00
|
|
|
@interface NSBundle : NSObject
|
|
|
|
{
|
2010-02-14 10:48:10 +00:00
|
|
|
#if GS_EXPOSE(NSBundle)
|
|
|
|
@public
|
2006-05-05 11:06:57 +00:00
|
|
|
NSString *_path;
|
|
|
|
NSMutableArray *_bundleClasses;
|
|
|
|
Class _principalClass;
|
|
|
|
NSDictionary *_infoDict;
|
1999-04-22 21:26:10 +00:00
|
|
|
NSMutableDictionary *_localizations;
|
2006-05-05 11:06:57 +00:00
|
|
|
unsigned _bundleType;
|
|
|
|
BOOL _codeLoaded;
|
|
|
|
unsigned _version;
|
|
|
|
NSString *_frameworkVersion;
|
2010-03-02 09:51:12 +00:00
|
|
|
#endif
|
2011-02-16 05:49:45 +00:00
|
|
|
#if GS_NONFRAGILE
|
|
|
|
#else
|
2011-02-14 06:37:45 +00:00
|
|
|
/* Pointer to private additional data used to avoid breaking ABI
|
|
|
|
* when we don't have the non-fragile ABI available.
|
2011-02-16 05:49:45 +00:00
|
|
|
* Use this mechanism rather than changing the instance variable
|
|
|
|
* layout (see Source/GSInternal.h for details).
|
2011-02-14 06:37:45 +00:00
|
|
|
*/
|
2011-03-05 18:12:55 +00:00
|
|
|
@private id _internal GS_UNUSED_IVAR;
|
2011-02-14 06:37:45 +00:00
|
|
|
#endif
|
1995-03-18 17:15:15 +00:00
|
|
|
}
|
|
|
|
|
2002-10-31 00:02:10 +00:00
|
|
|
/** Return an array enumerating all the bundles in the application. This
|
|
|
|
* does not include frameworks. */
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSArray*) allBundles;
|
2002-10-31 00:02:10 +00:00
|
|
|
|
|
|
|
/** Return an array enumerating all the frameworks in the application. This
|
|
|
|
* does not include normal bundles. */
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSArray*) allFrameworks;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/**
|
|
|
|
* <p>Return the bundle containing the resources for the executable. If
|
2002-10-31 00:02:10 +00:00
|
|
|
* the executable is an application, this is the main application
|
|
|
|
* bundle (the xxx.app directory); if the executable is a tool, this
|
|
|
|
* is a bundle 'naturally' associated with the tool: if the tool
|
|
|
|
* executable is xxx/Tools/ix86/linux-gnu/gnu-gnu-gnu/Control then the
|
|
|
|
* tool's main bundle directory is xxx/Tools/Resources/Control.
|
2002-11-01 08:20:02 +00:00
|
|
|
* </p>
|
|
|
|
* <p>NB: traditionally tools didn't have a main bundle -- this is a recent
|
2002-10-31 00:02:10 +00:00
|
|
|
* GNUstep extension, but it's quite nice and it's here to stay.
|
2002-11-01 08:20:02 +00:00
|
|
|
* </p>
|
|
|
|
* <p>The main bundle is where the application should put all of its
|
2002-10-31 00:02:10 +00:00
|
|
|
* resources, such as support files (images, html, rtf, txt, ...),
|
|
|
|
* localization tables, .gorm (.nib) files, etc. gnustep-make
|
|
|
|
* (/ProjectCenter) allows you to easily specify the resource files to
|
|
|
|
* put in the main bundle when you create an application or a tool.
|
2002-11-01 08:20:02 +00:00
|
|
|
* </p>
|
2002-10-31 00:02:10 +00:00
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSBundle*) mainBundle;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/**
|
|
|
|
* <p>Return the bundle to which aClass belongs. If aClass was loaded
|
2002-10-31 00:02:10 +00:00
|
|
|
* from a bundle, return the bundle; if it belongs to a framework
|
|
|
|
* (either a framework linked into the application, or loaded
|
2006-05-11 10:16:55 +00:00
|
|
|
* dynamically), return the framework; if it belongs to a library,
|
|
|
|
* return the bundle for that library; in all other cases, return the
|
2002-10-31 00:02:10 +00:00
|
|
|
* main bundle.
|
2002-11-01 08:20:02 +00:00
|
|
|
* </p>
|
|
|
|
* <p>Please note that GNUstep supports plain shared libraries, while the
|
2002-10-31 00:02:10 +00:00
|
|
|
* openstep standard, and other openstep-like systems, do not; the
|
2006-05-11 10:16:55 +00:00
|
|
|
* behaviour when aClass belongs to a plain shared library is to return
|
|
|
|
* a bundle for that library, but might be changed. :-)
|
2002-11-01 08:20:02 +00:00
|
|
|
* </p>
|
2002-10-31 00:02:10 +00:00
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSBundle*) bundleForClass: (Class)aClass;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2006-05-11 10:16:55 +00:00
|
|
|
/** Returns the bundle for the specified identifier (see -bundleIdentifier)
|
|
|
|
* as long as the bundle has already been loaded. This never causes a
|
|
|
|
* bundle to be loaded.
|
|
|
|
*/
|
|
|
|
+ (NSBundle*) bundleWithIdentifier: (NSString*)identifier;
|
|
|
|
|
2002-10-31 00:02:10 +00:00
|
|
|
/** Return a bundle for the path at path. If path doesn't exist or is
|
2002-02-25 15:29:53 +00:00
|
|
|
* not readable, return nil. If you want the main bundle of an
|
|
|
|
* application or a tool, it's better if you use +mainBundle. */
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSBundle*) bundleWithPath: (NSString*)path;
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
2011-06-22 23:01:01 +00:00
|
|
|
+ (NSBundle*) bundleWithURL: (NSURL*)url;
|
|
|
|
#endif
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/**
|
|
|
|
Returns an absolute path for a resource name with the extension
|
2011-10-17 10:59:02 +00:00
|
|
|
in the specified bundlePath. See also
|
2002-11-19 20:39:29 +00:00
|
|
|
-pathForResource:ofType:inDirectory: for more information on
|
|
|
|
searching a bundle.
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSString*) pathForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension
|
1999-09-16 07:21:34 +00:00
|
|
|
inDirectory: (NSString*)bundlePath;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/**
|
2004-06-22 22:27:39 +00:00
|
|
|
This method has been deprecated. Version numbers were never implemented
|
2002-11-19 20:39:29 +00:00
|
|
|
so this method behaves exactly like +pathForResource:ofType:inDirectory:.
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (NSString*) pathForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension
|
1999-09-16 07:21:34 +00:00
|
|
|
inDirectory: (NSString*)bundlePath
|
|
|
|
withVersion: (int)version;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
2011-06-22 23:01:01 +00:00
|
|
|
+ (NSURL*) URLForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
withExtension: (NSString*)extension
|
2011-06-22 23:01:01 +00:00
|
|
|
subdirectory: (NSString*)subpath
|
|
|
|
inBundleWithURL: (NSURL*)bundleURL;
|
|
|
|
#endif
|
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/** <init />
|
2005-04-01 10:57:35 +00:00
|
|
|
* Init the bundle for reading resources from path.<br />
|
|
|
|
* The MacOS-X documentation says that the path must be a full path to
|
|
|
|
* a directory on disk. However, it (in MacOS-X) version 10.3 at least)
|
|
|
|
* actually accepts relative paths too.<br />
|
|
|
|
* The GNUstep behavior is similar in that it accepts a relative path,
|
|
|
|
* but GNUstep converts it to an absolute path by referring to the
|
|
|
|
* current working directory when the is initialised, so an absolute
|
|
|
|
* path is then used and a warning message is printed.<br />
|
|
|
|
* On MacOS-X using a bundle initialised with a relative path will cause
|
|
|
|
* a crash if the current working directory is changed between the point
|
|
|
|
* at which the bundle was initialised and that at which it is used.<br />
|
2006-05-11 10:16:55 +00:00
|
|
|
* If path is nil or can't be accessed, initWithPath: deallocates the
|
2005-04-01 10:57:35 +00:00
|
|
|
* receiver and returns nil.<br />
|
|
|
|
* If a bundle for that path already existed, it is returned in place
|
2006-05-11 10:16:55 +00:00
|
|
|
* of the receiver (and the receiver is deallocated).<br />
|
|
|
|
* If the -bundleIdentifier is not nil, and a bundle with the same
|
|
|
|
* identifier already exists, the existing bundle is returned in place
|
2005-04-01 10:57:35 +00:00
|
|
|
* of the receiver (and the receiver is deallocated).
|
2002-10-31 00:02:10 +00:00
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithPath: (NSString*)path;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
2011-06-22 23:01:01 +00:00
|
|
|
- (id) initWithURL: (NSURL*)url;
|
|
|
|
#endif
|
|
|
|
|
2002-10-31 00:02:10 +00:00
|
|
|
/** Return the path to the bundle - an absolute path. */
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSString*) bundlePath;
|
2002-02-25 15:29:53 +00:00
|
|
|
|
2013-08-10 13:15:29 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
- (NSURL*) bundleURL;
|
|
|
|
#endif
|
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/** Returns the class in the bundle with the given name. If no class
|
|
|
|
of this name exists in the bundle, then Nil is returned.
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (Class) classNamed: (NSString*)className;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/** Returns the principal class of the bundle. This is the class
|
|
|
|
specified by the NSPrincipalClass key in the Info-gnustep property
|
2004-11-30 22:16:32 +00:00
|
|
|
list contained in the bundle. If this key or the specified class
|
|
|
|
is not found, the class returned is arbitrary, although it is
|
|
|
|
typically the first class compiled into the archive.
|
2002-11-19 20:39:29 +00:00
|
|
|
*/
|
1997-01-06 22:30:33 +00:00
|
|
|
- (Class) principalClass;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
2005-10-21 02:20:41 +00:00
|
|
|
<p> Returns an array of paths for all resources with the specified
|
|
|
|
extension and residing in the bundlePath directory. bundlePath can
|
|
|
|
be any type of directory structure, but typically it is used to
|
|
|
|
search for resources in a application or framework. For example,
|
|
|
|
one could search for tiff files in the MyApp.app application using [NSBundle
|
|
|
|
pathsForResourcesOfType: @"tiff" inDirectory: @"MyApp.app"]. It
|
|
|
|
will search in any Resources subdirectory inside bundlePath as well
|
|
|
|
as the main directory for resource files. If extension is nil or
|
|
|
|
empty, all resources are returned. </p>
|
2004-06-22 22:27:39 +00:00
|
|
|
*/
|
2002-11-19 20:39:29 +00:00
|
|
|
+ (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
|
|
|
inDirectory: (NSString*)bundlePath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
<p>
|
|
|
|
Returns an array of paths for all resources with the specified
|
|
|
|
extension and residing in the bundlePath directory. If extension is
|
|
|
|
nil or empty, all bundle resources are returned.
|
|
|
|
</p>
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
2005-10-21 02:20:41 +00:00
|
|
|
inDirectory: (NSString*)subPath;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
<p>
|
2011-10-17 10:59:02 +00:00
|
|
|
Returns an absolute path for a resource name with the extension
|
2002-11-19 20:39:29 +00:00
|
|
|
in the specified bundlePath. Directories in the bundle are searched
|
|
|
|
in the following order:
|
|
|
|
</p>
|
|
|
|
<example>
|
2005-10-21 02:20:41 +00:00
|
|
|
root path/Resources/subPath
|
|
|
|
root path/Resources/subPath/"language.lproj"
|
|
|
|
root path/subPath
|
|
|
|
root path/subPath/"language.lproj"
|
2002-11-19 20:39:29 +00:00
|
|
|
</example>
|
|
|
|
<p>
|
2004-07-29 15:30:47 +00:00
|
|
|
where language.lproj can be any localized language directory inside
|
2002-11-19 20:39:29 +00:00
|
|
|
the bundle.
|
|
|
|
</p>
|
|
|
|
<p>
|
2011-10-17 10:59:02 +00:00
|
|
|
If extension is nil or empty, then the first file exactly matching name
|
2009-01-08 10:40:13 +00:00
|
|
|
(ie with no extension) is returned.
|
2002-11-19 20:39:29 +00:00
|
|
|
</p>
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSString*) pathForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension
|
2005-10-21 02:20:41 +00:00
|
|
|
inDirectory: (NSString*)subPath;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-17 10:59:02 +00:00
|
|
|
Returns an absolute path for a resource name with the extension
|
2002-11-19 20:39:29 +00:00
|
|
|
in the receivers bundle path.
|
|
|
|
See -pathForResource:ofType:inDirectory:.
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSString*) pathForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
2011-06-22 23:01:01 +00:00
|
|
|
- (NSURL*) URLForResource: (NSString*)name
|
|
|
|
withExtension: (NSString*)extension;
|
|
|
|
- (NSURL*) URLForResource: (NSString*)name
|
|
|
|
withExtension: (NSString*)extension
|
|
|
|
subdirectory: (NSString*)subpath;
|
|
|
|
- (NSURL*) URLForResource: (NSString*)name
|
|
|
|
withExtension: (NSString*)extension
|
|
|
|
subdirectory: (NSString*)subpath
|
|
|
|
localization: (NSString*)localizationName;
|
|
|
|
#endif
|
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/**
|
2013-02-28 16:50:37 +00:00
|
|
|
* <p>Returns the value for the key found in the strings file tableName, or
|
|
|
|
* Localizable.strings if tableName is nil.
|
|
|
|
* </p>
|
|
|
|
* <p>If the user default <code>NSShowNonLocalizedStrings</code> is set, the
|
|
|
|
* value of the key will be returned as an uppercase string rather than any
|
|
|
|
* localized equivalent found. This can be useful during development to check
|
|
|
|
* where a given string in the UI is "coming from".</p>
|
2002-11-19 20:39:29 +00:00
|
|
|
*/
|
2011-02-14 10:57:57 +00:00
|
|
|
- (NSString*) localizedStringForKey: (NSString*)key
|
|
|
|
value: (NSString*)value
|
|
|
|
table: (NSString*)tableName;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/** Returns the absolute path to the resources directory of the bundle. */
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSString*) resourcePath;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
2014-01-14 14:13:31 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
/** Returns the absolute path to the resources directory of the bundle. */
|
|
|
|
- (NSURL *) resourceURL;
|
|
|
|
#endif
|
|
|
|
|
2004-11-11 18:51:37 +00:00
|
|
|
/** Returns the full path to the plug-in subdirectory of the bundle. */
|
2006-05-11 10:16:55 +00:00
|
|
|
- (NSString *) builtInPlugInsPath;
|
2004-11-11 18:51:37 +00:00
|
|
|
|
2013-08-14 21:10:35 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
2013-08-10 13:31:46 +00:00
|
|
|
/** Returns the full path to the plug-in subdirectory of the bundle. */
|
|
|
|
- (NSURL *) builtInPlugInsURL;
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 21:10:35 +00:00
|
|
|
/** Returns the full path to the private frameworks subdirectory of the bundle. */
|
|
|
|
- (NSString *) privateFrameworksPath;
|
|
|
|
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
/** Returns the full path to the private frameworks subdirectory of the bundle. */
|
|
|
|
- (NSURL *) privateFrameworksURL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-28 03:46:31 +00:00
|
|
|
/** Returns the bundle identifier, as defined by the CFBundleIdentifier
|
|
|
|
key in the infoDictionary */
|
2006-05-11 10:16:55 +00:00
|
|
|
- (NSString *) bundleIdentifier;
|
2003-03-28 03:46:31 +00:00
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/** Returns the bundle version. */
|
1997-09-01 21:59:51 +00:00
|
|
|
- (unsigned) bundleVersion;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/** Set the bundle version */
|
1997-09-01 21:59:51 +00:00
|
|
|
- (void) setBundleVersion: (unsigned)version;
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
|
|
|
* Returns subarray of given array containing those localizations that are
|
|
|
|
* used to locate resources given environment and user preferences.
|
|
|
|
*/
|
2002-11-19 20:39:29 +00:00
|
|
|
+ (NSArray *) preferredLocalizationsFromArray: (NSArray *)localizationsArray;
|
2006-05-11 10:16:55 +00:00
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
|
|
|
* Returns subarray of given array containing those localizations that are
|
|
|
|
* used to locate resources given environment given user preferences (which
|
|
|
|
* are used instead of looking up the preferences of the current user).
|
|
|
|
*/
|
2002-11-19 20:39:29 +00:00
|
|
|
+ (NSArray *) preferredLocalizationsFromArray: (NSArray *)localizationsArray
|
|
|
|
forPreferences: (NSArray *)preferencesArray;
|
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2,GS_API_LATEST)
|
2006-05-11 10:16:55 +00:00
|
|
|
/**
|
|
|
|
* Returns a boolean indicating whether code for the bundle has been loaded.
|
|
|
|
*/
|
2003-02-04 21:49:35 +00:00
|
|
|
- (BOOL) isLoaded;
|
2008-06-06 13:57:06 +00:00
|
|
|
#endif
|
2005-10-21 02:20:41 +00:00
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
2006-09-13 07:31:38 +00:00
|
|
|
* This method returns the same information as
|
|
|
|
* -pathsForResourcesOfType:inDirectory: except that only non-localized
|
|
|
|
* resources and resources that match the localization localizationName
|
|
|
|
* are returned.<br />
|
|
|
|
* The GNUstep implementation places localised resources in the array
|
|
|
|
* before any non-localised resources.
|
2004-06-22 22:27:39 +00:00
|
|
|
*/
|
2002-11-19 20:39:29 +00:00
|
|
|
- (NSArray*) pathsForResourcesOfType: (NSString*)extension
|
2005-10-21 02:20:41 +00:00
|
|
|
inDirectory: (NSString*)subPath
|
2002-11-19 20:39:29 +00:00
|
|
|
forLocalization: (NSString*)localizationName;
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
2006-09-13 07:31:38 +00:00
|
|
|
* This is like -pathForResource:ofType:inDirectory: but returns only
|
|
|
|
* resources matching localizationName (preferentially), or non-localized
|
|
|
|
* resources.
|
2004-06-22 22:27:39 +00:00
|
|
|
*/
|
2002-11-19 20:39:29 +00:00
|
|
|
- (NSString*) pathForResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension
|
2005-10-21 02:20:41 +00:00
|
|
|
inDirectory: (NSString*)subPath
|
2002-11-19 20:39:29 +00:00
|
|
|
forLocalization: (NSString*)localizationName;
|
|
|
|
|
|
|
|
/** Returns the info property list associated with the bundle. */
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSDictionary*) infoDictionary;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2,GS_API_LATEST)
|
2002-11-19 20:39:29 +00:00
|
|
|
/** Returns a localized info property list based on the preferred
|
2006-09-13 07:31:38 +00:00
|
|
|
* localization or the most appropriate localization if the preferred
|
|
|
|
* one cannot be found.
|
|
|
|
*/
|
|
|
|
- (NSDictionary*) localizedInfoDictionary;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
2008-06-06 13:57:06 +00:00
|
|
|
/** Not implemented
|
|
|
|
*/
|
|
|
|
- (NSString*) developmentLocalization;
|
|
|
|
|
|
|
|
/** Not implemented
|
|
|
|
*/
|
|
|
|
- (id) objectForInfoDictionaryKey: (NSString *)key;
|
|
|
|
#endif
|
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/** Returns all the localizations in the bundle. */
|
2006-09-13 07:31:38 +00:00
|
|
|
- (NSArray*) localizations;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
2006-09-13 07:31:38 +00:00
|
|
|
/**
|
|
|
|
* Returns the list of localizations that the bundle uses to search
|
|
|
|
* for information. This is based on the user's preferences.
|
|
|
|
*/
|
|
|
|
- (NSArray*) preferredLocalizations;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
|
|
|
/** Loads any executable code contained in the bundle into the
|
|
|
|
application. Load will be called implicitly if any information
|
|
|
|
about the bundle classes is requested, such as -principalClass or
|
|
|
|
-classNamed:.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) load;
|
2002-11-19 20:39:29 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2,GS_API_LATEST)
|
2008-06-06 13:57:06 +00:00
|
|
|
/** * Not implemented
|
|
|
|
*/
|
|
|
|
- (BOOL) unload;
|
|
|
|
#endif
|
|
|
|
|
2002-11-19 20:39:29 +00:00
|
|
|
/** Returns the path to the executable code in the bundle */
|
2006-10-28 07:18:36 +00:00
|
|
|
- (NSString *) executablePath;
|
2013-08-10 13:31:46 +00:00
|
|
|
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
- (NSURL *) executableURL;
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 21:10:35 +00:00
|
|
|
- (NSString *) pathForAuxiliaryExecutable: (NSString *) executableName;
|
|
|
|
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
- (NSURL *)URLForAuxiliaryExecutable: (NSString *) executableName;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1997-01-06 22:30:33 +00:00
|
|
|
#endif
|
1995-03-18 17:15:15 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
|
2008-06-06 13:57:06 +00:00
|
|
|
/** Not implemented */
|
|
|
|
- (NSArray *) executableArchitectures;
|
|
|
|
/** Not implemented */
|
|
|
|
- (BOOL) preflightAndReturnError: (NSError **)error;
|
|
|
|
/** Not implemented */
|
|
|
|
- (BOOL) loadAndReturnError: (NSError **)error;
|
|
|
|
#endif
|
1995-03-18 17:15:15 +00:00
|
|
|
@end
|
|
|
|
|
2008-06-10 18:20:23 +00:00
|
|
|
#if GS_API_VERSION(GS_API_NONE, 011700)
|
2004-06-22 22:27:39 +00:00
|
|
|
/**
|
|
|
|
* Augments [NSBundle], including methods for handling libraries in the GNUstep
|
|
|
|
* fashion, for rapid localization, and other purposes.
|
|
|
|
*/
|
1997-10-18 19:49:50 +00:00
|
|
|
@interface NSBundle (GNUstep)
|
|
|
|
|
2007-03-01 13:43:23 +00:00
|
|
|
/** This method is an experimental GNUstep extension, and might change.
|
2007-03-09 19:09:08 +00:00
|
|
|
* <p>Return a bundle to access the resources for the (static or shared) library
|
|
|
|
* libraryName, with interface version interfaceVersion.
|
|
|
|
* </p>
|
|
|
|
* <p>Resources for shared libraries are stored into
|
|
|
|
* GNUSTEP_LIBRARY/Libraries/libraryName/Versions/interfaceVersion/Resources/;
|
|
|
|
* this method will search for the first such existing directory and return it.
|
|
|
|
*</p>
|
|
|
|
* <p>libraryName should be the name of a library without the
|
|
|
|
* <em>lib</em> prefix or any extensions; interfaceVersion is the
|
|
|
|
* interface version of the library (eg, it's 1.13 in libgnustep-base.so.1.13;
|
|
|
|
* see library.make on how to control it).
|
2007-03-01 13:43:23 +00:00
|
|
|
* </p>
|
|
|
|
* <p>This method exists to provide resource bundles for libraries and has no
|
|
|
|
* particular relationship to the library code itsself. The named library
|
|
|
|
* could be a dynamic library linked in to the running program, a static
|
|
|
|
* library (whose code may not even exist on the host machine except where
|
|
|
|
* it is linked in to the program), or even a library which is not linked
|
|
|
|
* into the program at all (eg. where you want to share resources provided
|
|
|
|
* for a library you do not actually use).
|
|
|
|
* </p>
|
|
|
|
* <p>The bundle for the library <em>gnustep-base</em> is a special case ...
|
|
|
|
* for this bundle the -principalClass method returns [NSObject] and the
|
|
|
|
* -executablePath method returns the path to the gnustep-base dynamic
|
|
|
|
* library (if it can be found). As a general rule, library bundles are
|
|
|
|
* not guaranteed to return values for these methods as the library may
|
|
|
|
* not exist on disk.
|
|
|
|
* </p>
|
2002-10-31 00:02:10 +00:00
|
|
|
*/
|
2007-03-09 19:09:08 +00:00
|
|
|
+ (NSBundle *) bundleForLibrary: (NSString *)libraryName
|
|
|
|
version: (NSString *)interfaceVersion;
|
|
|
|
|
|
|
|
/** This method is a equivalent to bundleForLibrary:version: with a nil
|
|
|
|
* version.
|
|
|
|
*/
|
2001-12-21 18:30:09 +00:00
|
|
|
+ (NSBundle *) bundleForLibrary: (NSString *)libraryName;
|
|
|
|
|
2007-03-09 19:09:08 +00:00
|
|
|
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
/** Find a resource in the "Library" directory. */
|
2003-04-28 02:29:49 +00:00
|
|
|
+ (NSString*) pathForLibraryResource: (NSString*)name
|
2011-10-17 10:59:02 +00:00
|
|
|
ofType: (NSString*)extension
|
2003-04-28 02:29:49 +00:00
|
|
|
inDirectory: (NSString*)bundlePath;
|
|
|
|
|
1997-10-18 19:49:50 +00:00
|
|
|
@end
|
2001-12-21 18:30:09 +00:00
|
|
|
|
2001-02-23 00:50:10 +00:00
|
|
|
#endif /* GNUSTEP */
|
1997-10-18 19:49:50 +00:00
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/**
|
2002-08-20 10:22:05 +00:00
|
|
|
* <p>
|
|
|
|
* This function (macro) is used to get the localized
|
|
|
|
* translation of the string <code>key</code>.
|
|
|
|
* <code>key</code> is looked up in the
|
|
|
|
* <code>Localizable.strings</code> file for the current
|
|
|
|
* language. The current language is determined by the
|
|
|
|
* available languages in which the application is
|
|
|
|
* translated, and by using the <code>NSLanguages</code> user
|
|
|
|
* defaults (which should contain an array of the languages
|
|
|
|
* preferred by the user, in order of preference).
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* Technically, the function works by calling
|
|
|
|
* <code>localizedStringForKey:value:table:</code> on the
|
|
|
|
* main bundle, using <code>@""</code> as value, and
|
|
|
|
* <code>nil</code> as the table. The <code>comment</code>
|
|
|
|
* is ignored when the macro is expanded; but when we have
|
|
|
|
* tools which can generate the
|
|
|
|
* <code>Localizable.strings</code> files automatically from
|
|
|
|
* source code, the <code>comment</code> will be used by the
|
|
|
|
* tools and added as a comment before the string to
|
|
|
|
* translate. Upon finding something like
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* <code>
|
|
|
|
* NSLocalizedString (@"My useful string",
|
|
|
|
* @"My useful comment about the string");
|
|
|
|
* </code>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* in the source code, the tools will generate a comment and the line
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* <code>
|
|
|
|
* " My useful string" = "My useful string";
|
|
|
|
* </code>
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* in the <code>Localizable.strings</code> file (the
|
|
|
|
* translator then can use this as a skeleton for the
|
|
|
|
* <code>Localizable.strings</code> for his/her own language,
|
|
|
|
* where she/he can replace the right hand side with the
|
|
|
|
* translation in her/his own language). The comment can
|
|
|
|
* help the translator to decide how to translate when it is
|
|
|
|
* not clear how to translate (because the original string is
|
|
|
|
* now out of context, and out of context might not be so
|
|
|
|
* clear what the string means). The comment is totally
|
|
|
|
* ignored by the library code.
|
|
|
|
* </p>
|
|
|
|
* <p>
|
|
|
|
* If you don't have a comment (because the string is so
|
|
|
|
* self-explanatory that it doesn't need it), you can leave
|
|
|
|
* it blank, by using <code>@""</code> as a comment. If the
|
|
|
|
* string might be unclear out of context, it is recommended
|
|
|
|
* that you add a comment (even if it is unused for now).
|
|
|
|
* </p>
|
|
|
|
*/
|
1997-01-06 22:30:33 +00:00
|
|
|
#define NSLocalizedString(key, comment) \
|
|
|
|
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
|
2002-08-20 10:22:05 +00:00
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/**
|
2002-08-20 10:22:05 +00:00
|
|
|
* This function (macro) does the same as
|
|
|
|
* <code>NSLocalizedString</code>, but uses the table
|
|
|
|
* <code>table</code> rather than the default table. This
|
|
|
|
* means that the string to translate will be looked up in a
|
|
|
|
* different file than <code>Localizable.strings</code>. For
|
|
|
|
* example, if you pass <code>DatabaseErrors</code> as the
|
|
|
|
* <code>table</code>, the string will be looked up for
|
|
|
|
* translation in the file
|
|
|
|
* <code>DatabaseErrors.strings</code>. This allows you to
|
|
|
|
* have the same string translated in different ways, by
|
|
|
|
* having a different translation in different tables, and
|
|
|
|
* choosing between the different translation by choosing a
|
|
|
|
* different table.
|
|
|
|
*/
|
1997-01-06 22:30:33 +00:00
|
|
|
#define NSLocalizedStringFromTable(key, tbl, comment) \
|
|
|
|
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
|
2002-08-20 10:22:05 +00:00
|
|
|
|
2002-11-01 08:20:02 +00:00
|
|
|
/**
|
2002-08-20 10:22:05 +00:00
|
|
|
* This function is the full-blown localization function (it
|
|
|
|
* is actually a macro). It looks up the string
|
|
|
|
* <code>key</code> for translation in the table
|
|
|
|
* <code>table</code> of the bundle <code>bundle</code>
|
|
|
|
* (please refer to the NSBundle documentation for more
|
|
|
|
* information on how this lookup is done).
|
|
|
|
* <code>comment</code> is a comment, which is ignored by the
|
|
|
|
* library (it is discarded when the macro is expanded) but which
|
|
|
|
* can be used by tools which parse the source code and generate
|
|
|
|
* strings table to provide a comment which the translator can
|
|
|
|
* use when translating the string.
|
|
|
|
*/
|
1997-01-06 22:30:33 +00:00
|
|
|
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
|
|
|
|
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
|
|
|
|
|
1999-04-23 02:54:45 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-20 17:16:23 +00:00
|
|
|
#if !NO_GNUSTEP && !defined(GNUSTEP_BASE_INTERNAL)
|
2010-02-18 11:40:58 +00:00
|
|
|
#import <GNUstepBase/NSBundle+GNUstepBase.h>
|
|
|
|
#endif
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
#endif /* __NSBundle_h_GNUSTEP_BASE_INCLUDE */
|