mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Add David's generalisation of _()
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32184 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d07f49a9b6
commit
b96b154e5e
3 changed files with 58 additions and 33 deletions
|
@ -1,3 +1,11 @@
|
|||
2011-02-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/common.h:
|
||||
* Headers/Additions/GNUstepBase/GNUstep.h:
|
||||
Implement David's idea of allowing some generalisation of the _()
|
||||
macro by using a preprocessor define to set the bundle to be used
|
||||
to lookup localisation information.
|
||||
|
||||
2011-02-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSInternal.h:
|
||||
|
|
|
@ -190,28 +190,44 @@ id __object = (object); (__object != nil) ? [__object autorelease] : nil; })
|
|||
* <code>_(@"My string to translate")</code>
|
||||
* </p>
|
||||
* <p>
|
||||
* is exactly the same as
|
||||
* is basically equivalent to
|
||||
* </p>
|
||||
* <p>
|
||||
* <code>NSLocalizedString (@"My string to translate", @"")</code>
|
||||
* <code>NSLocalizedString(@"My string to translate", @"")</code>
|
||||
* </p>
|
||||
* <p>
|
||||
* It is useful when you need to translate an application
|
||||
* very quickly, as you just need to enclose all strings
|
||||
* inside <code>_()</code>. But please note that when you
|
||||
* use this macro, you are not taking advantage of comments
|
||||
* for the translator, so consider using
|
||||
* <code>NSLocalizedString</code> instead when you need a
|
||||
* comment.
|
||||
* It is useful when you need to translate an application
|
||||
* very quickly, as you just need to enclose all strings
|
||||
* inside <code>_()</code>. But please note that when you
|
||||
* use this macro, you are not taking advantage of comments
|
||||
* for the translator, so consider using
|
||||
* <code>NSLocalizedString</code> instead when you need a
|
||||
* comment.
|
||||
* </p>
|
||||
* <p>You may define GS_LOCALISATION_BUNDLE_ID to the bundle identifier
|
||||
* of the bundle which is to provide the localisation information.<br />
|
||||
* This can be used when compiling a single file by specifying something like
|
||||
* '-D GS_LOCALISATION_BUNDLE_ID=$(FRAMEWORK_NAME)' in your make file.<br />
|
||||
* If this is not defined, the localisation is provided by your application's
|
||||
* main bundle exactly like the NSLocalizedString function.
|
||||
* </p>
|
||||
* <p>Alternatively you may define GS_LOCALISATION_BUNDLE to be the bundle
|
||||
* to be used to prvide the localisation information.
|
||||
* </p>
|
||||
*/
|
||||
#define _(X) NSLocalizedString (X, @"")
|
||||
|
||||
/* The quickest possible way to localize a static string:
|
||||
|
||||
static NSString *string = __(@"New Game");
|
||||
|
||||
NSLog (_(string)); */
|
||||
# define _(X) \
|
||||
[GS_LOCALISATION_BUNDLE localizedStringForKey: (X) value: @"" table: nil]
|
||||
|
||||
#if !defined(GS_LOCALISATION_BUNDLE)
|
||||
# if defined(GS_LOCALISATION_BUNDLE_ID)
|
||||
# define GS_LOCALISATION_BUNDLE [NSBundle bundleWithIdentifier: \
|
||||
GS_LOCALISATION_BUNDLE_ID]
|
||||
# else
|
||||
# define GS_LOCALISATION_BUNDLE [NSBundle mainBundle]
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -224,7 +240,7 @@ id __object = (object); (__object != nil) ? [__object autorelease] : nil; })
|
|||
* is exactly the same as
|
||||
* </p>
|
||||
* <p>
|
||||
* <code>GSLocalizedStaticString (@"My string to translate", @"")</code>
|
||||
* <code>GSLocalizedStaticString(@"My string to translate", @"")</code>
|
||||
* </p>
|
||||
* <p>
|
||||
* It is useful when you need to translate an application very
|
||||
|
@ -246,16 +262,16 @@ id __object = (object); (__object != nil) ? [__object autorelease] : nil; })
|
|||
*/
|
||||
#define __(X) X
|
||||
|
||||
/* The better way for a static string, with a comment - use as follows -
|
||||
|
||||
static NSString *string = GSLocalizedStaticString (@"New Game",
|
||||
@"Menu Option");
|
||||
|
||||
NSLog (_(string));
|
||||
|
||||
If you need anything more complicated than this, please initialize
|
||||
the static strings manually.
|
||||
*/
|
||||
/* The better way for a static string, with a comment - use as follows -
|
||||
*
|
||||
* static NSString *string = GSLocalizedStaticString (@"New Game",
|
||||
* @"Menu Option");
|
||||
*
|
||||
* NSLog (_(string));
|
||||
*
|
||||
* If you need anything more complicated than this, please initialize
|
||||
* the static strings manually.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
#import "GNUstepBase/preface.h"
|
||||
#import "GNUstepBase/GSConfig.h"
|
||||
|
||||
/* Set localisation macro for use within the base library itsself.
|
||||
*/
|
||||
#define GS_LOCALISATION_BUNDLE \
|
||||
[NSBundle bundleForLibrary: @"gnustep-base" version: \
|
||||
OBJC_STRINGIFY(GNUSTEP_BASE_MAJOR_VERSION.GNUSTEP_BASE_MINOR_VERSION)]
|
||||
|
||||
#import "GNUstepBase/GNUstep.h"
|
||||
|
||||
/* Foundation/NSObject.h imports <Foundation/NSZone.h> and
|
||||
|
@ -37,15 +43,10 @@
|
|||
*/
|
||||
#import "Foundation/NSString.h"
|
||||
#import "Foundation/NSDebug.h"
|
||||
|
||||
#import "Foundation/NSBundle.h"
|
||||
#import "GNUstepBase/NSBundle+GNUstepBase.h"
|
||||
|
||||
/* Change localisation macro for use within the base library itsself.
|
||||
*/
|
||||
#undef _
|
||||
#define _(X) [[NSBundle bundleForLibrary: @"gnustep-base" version: \
|
||||
OBJC_STRINGIFY(GNUSTEP_BASE_MAJOR_VERSION.GNUSTEP_BASE_MINOR_VERSION)] \
|
||||
localizedStringForKey:(X) value: @"" table: nil]
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
|
Loading…
Reference in a new issue