From 2ebeaf6626b9543e569f1e29fb6c6149c904502e Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Thu, 6 May 2010 22:35:09 +0000 Subject: [Author: dmaclach] So I can get around warnings on CoverStory on SnowLeopard. Hopefully Apple will fix this on their end and we can drop back to NSLocalizedString in future SDKs. R=thomasvl --- Foundation/GTMLocalizedString.h | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Foundation/GTMLocalizedString.h (limited to 'Foundation/GTMLocalizedString.h') diff --git a/Foundation/GTMLocalizedString.h b/Foundation/GTMLocalizedString.h new file mode 100644 index 0000000..c5fcde6 --- /dev/null +++ b/Foundation/GTMLocalizedString.h @@ -0,0 +1,84 @@ +// +// GTMLocalizedString.h +// +// Copyright (c) 2010 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import +#import "GTMDefines.h" + +// The NSLocalizedString macros do not have NS_FORMAT_ARGUMENT modifiers put +// on them which means you get warnings on Snow Leopard with when +// GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES and you do things like: +// NSString *foo +// = [NSString stringWithFormat:NSLocalizedString(@"blah %@", nil), @"bar"]; +// The GTMLocalizedString functions fix that for you so you can do: +// NSString *foo +// = [NSString stringWithFormat:GTMLocalizedString(@"blah %@", nil), @"bar"]; +// and you will compile cleanly. +// If you use genstrings you can call it with +// genstrings -s GTMLocalizedString ... +// and it should work as expected. +// You can override how GTM gets its localized strings (if you are using +// something other than NSLocalizedString) by redefining +// GTMLocalizedStringWithDefaultValueInternal. + +#ifndef GTMLocalizedStringWithDefaultValueInternal + #define GTMLocalizedStringWithDefaultValueInternal \ + NSLocalizedStringWithDefaultValue +#endif + +GTM_INLINE NSString *GTMLocalizedString(NSString *key, + NSString *comment) NS_FORMAT_ARGUMENT(1) { + return GTMLocalizedStringWithDefaultValueInternal(key, + nil, + [NSBundle mainBundle], + @"", + comment); +} + +GTM_INLINE NSString *GTMLocalizedStringFromTable(NSString *key, + NSString *tableName, + NSString *comment) NS_FORMAT_ARGUMENT(1) { + return GTMLocalizedStringWithDefaultValueInternal(key, + tableName, + [NSBundle mainBundle], + @"", + comment); +} + +GTM_INLINE NSString *GTMLocalizedStringFromTableInBundle(NSString *key, + NSString *tableName, + NSBundle *bundle, + NSString *comment) NS_FORMAT_ARGUMENT(1) { + return GTMLocalizedStringWithDefaultValueInternal(key, + tableName, + bundle, + @"", + comment); +} + +GTM_INLINE NSString *GTMLocalizedStringWithDefaultValue(NSString *key, + NSString *tableName, + NSBundle *bundle, + NSString *value, + NSString *comment) NS_FORMAT_ARGUMENT(1) { + return GTMLocalizedStringWithDefaultValueInternal(key, + tableName, + bundle, + value, + comment); +} + -- cgit v1.2.3