GTMLocalizedString.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // GTMLocalizedString.h
  3. //
  4. // Copyright (c) 2010 Google Inc. All rights reserved.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. #import "GTMDefines.h"
  20. // The NSLocalizedString macros do not have NS_FORMAT_ARGUMENT modifiers put
  21. // on them which means you get warnings on Snow Leopard with when
  22. // GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES and you do things like:
  23. // NSString *foo
  24. // = [NSString stringWithFormat:NSLocalizedString(@"blah %@", nil), @"bar"];
  25. // The GTMLocalizedString functions fix that for you so you can do:
  26. // NSString *foo
  27. // = [NSString stringWithFormat:GTMLocalizedString(@"blah %@", nil), @"bar"];
  28. // and you will compile cleanly.
  29. // If you use genstrings you can call it with
  30. // genstrings -s GTMLocalizedString ...
  31. // and it should work as expected.
  32. // You can override how GTM gets its localized strings (if you are using
  33. // something other than NSLocalizedString) by redefining
  34. // GTMLocalizedStringWithDefaultValueInternal.
  35. #ifndef GTMLocalizedStringWithDefaultValueInternal
  36. #define GTMLocalizedStringWithDefaultValueInternal \
  37. NSLocalizedStringWithDefaultValue
  38. #endif
  39. GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedString(
  40. NSString *key, NSString *comment) {
  41. return GTMLocalizedStringWithDefaultValueInternal(key,
  42. nil,
  43. [NSBundle mainBundle],
  44. @"",
  45. comment);
  46. }
  47. GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringFromTable(
  48. NSString *key, NSString *tableName, NSString *comment) {
  49. return GTMLocalizedStringWithDefaultValueInternal(key,
  50. tableName,
  51. [NSBundle mainBundle],
  52. @"",
  53. comment);
  54. }
  55. GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringFromTableInBundle(
  56. NSString *key, NSString *tableName, NSBundle *bundle, NSString *comment) {
  57. return GTMLocalizedStringWithDefaultValueInternal(key,
  58. tableName,
  59. bundle,
  60. @"",
  61. comment);
  62. }
  63. GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringWithDefaultValue(
  64. NSString *key, NSString *tableName, NSBundle *bundle, NSString *value,
  65. NSString *comment) {
  66. return GTMLocalizedStringWithDefaultValueInternal(key,
  67. tableName,
  68. bundle,
  69. value,
  70. comment);
  71. }