aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Foundation/GTMLocalizedString.h84
-rw-r--r--GTM.xcodeproj/project.pbxproj4
-rw-r--r--GTMDefines.h5
3 files changed, 93 insertions, 0 deletions
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 <Foundation/Foundation.h>
+#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);
+}
+
diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj
index e241a21..abae17e 100644
--- a/GTM.xcodeproj/project.pbxproj
+++ b/GTM.xcodeproj/project.pbxproj
@@ -102,6 +102,7 @@
8B1B49190E5F8E2100A08972 /* GTMExceptionalInlines.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B49170E5F8E2100A08972 /* GTMExceptionalInlines.m */; };
8B1B49260E5F97C800A08972 /* GTMExceptionalInlinesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B491B0E5F904C00A08972 /* GTMExceptionalInlinesTest.m */; };
8B21BE9211532CDC00DD2686 /* GTMNSAnimatablePropertyContainerTest.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8B21BE9111532CDC00DD2686 /* GTMNSAnimatablePropertyContainerTest.xib */; };
+ 8B21DE56117E5CB7000E004F /* GTMLocalizedString.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B21DE54117E5CB7000E004F /* GTMLocalizedString.h */; };
8B2789960EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 8B2789950EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff */; };
8B307FF81056B773006C4C7A /* GTMNSNumber+64Bit.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B307FF61056B773006C4C7A /* GTMNSNumber+64Bit.m */; };
8B307FF91056B773006C4C7A /* GTMNSNumber+64Bit.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B307FF71056B773006C4C7A /* GTMNSNumber+64Bit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -560,6 +561,7 @@
8B1B491B0E5F904C00A08972 /* GTMExceptionalInlinesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMExceptionalInlinesTest.m; sourceTree = "<group>"; };
8B21BE8F11532C7700DD2686 /* GTMNSAnimatablePropertyContainerTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMNSAnimatablePropertyContainerTest.h; sourceTree = "<group>"; };
8B21BE9111532CDC00DD2686 /* GTMNSAnimatablePropertyContainerTest.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GTMNSAnimatablePropertyContainerTest.xib; sourceTree = "<group>"; };
+ 8B21DE54117E5CB7000E004F /* GTMLocalizedString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMLocalizedString.h; sourceTree = "<group>"; };
8B2789950EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = GTMUnitTestingWindow.10.5.6.tiff; sourceTree = "<group>"; };
8B307FF61056B773006C4C7A /* GTMNSNumber+64Bit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSNumber+64Bit.m"; sourceTree = "<group>"; };
8B307FF71056B773006C4C7A /* GTMNSNumber+64Bit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSNumber+64Bit.h"; sourceTree = "<group>"; };
@@ -1277,6 +1279,7 @@
F41711320ECDFBD500B9B276 /* GTMLightweightProxy.h */,
F41711330ECDFBD500B9B276 /* GTMLightweightProxy.m */,
F41711340ECDFBD500B9B276 /* GTMLightweightProxyTest.m */,
+ 8B21DE54117E5CB7000E004F /* GTMLocalizedString.h */,
F98680AF0E2C15C300CEE8BF /* GTMLogger.h */,
F98680B00E2C15C300CEE8BF /* GTMLogger.m */,
F98680B10E2C15C300CEE8BF /* GTMLoggerTest.m */,
@@ -1521,6 +1524,7 @@
8B158ADE10A8C42000C93125 /* GTMNSAnimation+Duration.h in Headers */,
8BF2555310F65B56000490C8 /* GTMTypeCasting.h in Headers */,
8BDB8A991152E1B200C411B1 /* GTMNSAnimatablePropertyContainer.h in Headers */,
+ 8B21DE56117E5CB7000E004F /* GTMLocalizedString.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/GTMDefines.h b/GTMDefines.h
index 4090aa3..dc058cf 100644
--- a/GTMDefines.h
+++ b/GTMDefines.h
@@ -282,6 +282,11 @@ GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...);
#endif
#endif
+// Defined on 10.6 and above.
+#ifndef NS_FORMAT_ARGUMENT
+ #define NS_FORMAT_ARGUMENT(A)
+#endif
+
#ifndef GTM_NONNULL
#define GTM_NONNULL(x) __attribute__((nonnull(x)))
#endif