aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMLocalizedString.h
blob: c49b8a9da7ae88e06ac3ddcc59ae476cda1b4b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
//  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 NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedString(
    NSString *key,  NSString *comment) {
  return GTMLocalizedStringWithDefaultValueInternal(key,
                                                    nil,
                                                    [NSBundle mainBundle],
                                                    @"",
                                                    comment);
}

GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringFromTable(
    NSString *key, NSString *tableName, NSString *comment) {
  return GTMLocalizedStringWithDefaultValueInternal(key,
                                                    tableName,
                                                    [NSBundle mainBundle],
                                                    @"",
                                                    comment);
}

GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringFromTableInBundle(
    NSString *key,  NSString *tableName, NSBundle *bundle, NSString *comment) {
  return GTMLocalizedStringWithDefaultValueInternal(key,
                                                    tableName,
                                                    bundle,
                                                    @"",
                                                    comment);
}

GTM_INLINE NS_FORMAT_ARGUMENT(1) NSString *GTMLocalizedStringWithDefaultValue(
    NSString *key, NSString *tableName, NSBundle *bundle, NSString *value,
    NSString *comment) {
  return GTMLocalizedStringWithDefaultValueInternal(key,
                                                    tableName,
                                                    bundle,
                                                    value,
                                                    comment);
}