Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Obsolete number formatting and localization sample code

  • Loading branch information...
commit bd53b5fd930399c69cc11231de369ef008142525 1 parent 422c55a
Gwendal Roué authored February 13, 2013

Showing 26 changed files with 22 additions and 6,525 deletions. Show diff stats Hide diff stats

  1. 4  Guides/compatibility.md
  2. 71  Guides/delegate.md
  3. 2  Guides/filters.md
  4. 4  Guides/rendering_objects.md
  5. 3  Guides/runtime.md
  6. 16  Guides/sample_code/README.md
  7. 4  Guides/sample_code/indexes.md
  8. 373  Guides/sample_code/localization.md
  9. 319  Guides/sample_code/localization/GRMustacheLocalization.xcodeproj/project.pbxproj
  10. 29  Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.h
  11. 173  Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.m
  12. 34  Guides/sample_code/localization/GRMustacheLocalization/GRMustacheLocalization-Info.plist
  13. 7  Guides/sample_code/localization/GRMustacheLocalization/GRMustacheLocalization-Prefix.pch
  14. 57  Guides/sample_code/localization/GRMustacheLocalization/LocalizingHelper.h
  15. 152  Guides/sample_code/localization/GRMustacheLocalization/LocalizingHelper.m
  16. 5  Guides/sample_code/localization/GRMustacheLocalization/en.lproj/Localizable.strings
  17. 4,666  Guides/sample_code/localization/GRMustacheLocalization/en.lproj/MainMenu.xib
  18. 14  Guides/sample_code/localization/GRMustacheLocalization/main.m
  19. 184  Guides/sample_code/number_formatting.md
  20. 269  Guides/sample_code/number_formatting/GRMustacheNumberFormatting.xcodeproj/project.pbxproj
  21. 27  Guides/sample_code/number_formatting/GRMustacheNumberFormatting/Document.h
  22. 85  Guides/sample_code/number_formatting/GRMustacheNumberFormatting/Document.m
  23. 7  Guides/sample_code/number_formatting/GRMustacheNumberFormatting/GRMustacheNumberFormatting-Prefix.pch
  24. 35  Guides/sample_code/number_formatting/GRMustacheNumberFormatting/main.m
  25. 6  README.md
  26. 1  TODO.txt
4  Guides/compatibility.md
Source Rendered
@@ -144,9 +144,9 @@ Tag delegates
144 144
 
145 145
 GRMustache's [tag delegates](delegate.md), unknown to the Mustache specification, let you observe, and possibly alter the rendering of the Mustache tags.
146 146
 
147  
-Tag delegates may be used for formatting values in a spec-compliant way (see sample code in [Tag Delegates Guide](delegate.md)). They may also be used for putting Mustache on steroids, as in the [Localization Sample Code](sample_code/localization.md).
  147
+Tag delegates may be used for formatting values in a spec-compliant way (see sample code in [Tag Delegates Guide](delegate.md)). They may also at the core of many items of the [standard library](standard_library.md).
148 148
 
149  
-As such, they are an ambiguous tool. You will have to know when you cross the line.
  149
+They are an ambiguous tool. You will have to know when you cross the line.
150 150
 
151 151
 
152 152
 [up](../../../../GRMustache#documentation), [next](configuration.md)
71  Guides/delegate.md
Source Rendered
@@ -150,67 +150,17 @@ You can, for instance, provide default rendering for missing values:
150 150
 [[Document new] render];
151 151
 ```
152 152
 
153  
-### Altering the rendering of tags in a section
154  
-
155  
-As stated above, when a section renders an object that conforms to the `GRMustacheTagDelegate` protocol, this object observes the rendering of all tags inside the section.
156  
-
157  
-The [Localization Sample Code](sample_code/localization.md) will give us an example, but let's have fun with numbers, and have Mustache format all numbers in a section attached to a `NSNumberFormatter` instance:
158  
-
159  
-```objc
160  
-// Have NSNumberFormatter conform to the GRMustacheTagDelegate protocol,
161  
-// so that a formatter can format all numbers in a section:
162  
-@interface NSNumberFormatter(Document)<GRMustacheTagDelegate>
163  
-@end
164  
-
165  
-@implementation NSNumberFormatter(Document)
166  
-
167  
-- (id)mustacheTag:(GRMustacheTag *)tag willRenderObject:(id)object
168  
-{
169  
-    // Format all numbers that happen to be rendered by variable tags such as
170  
-    // `{{ count }}`.
171  
-    //
172  
-    // We avoid messing with sections, since they rely on boolean values of
173  
-    // numbers.
174  
-    
175  
-    if (tag.type == GRMustacheTagTypeVariable && [object isKindOfClass:[NSNumber class]]) {
176  
-        return [self stringFromNumber:object];
177  
-    }
178  
-    return object;
179  
-}
180  
-
181  
-@end
182  
-
183  
-NSString *templateString = @"x = {{x}}\n"
184  
-                           @"{{#percent}}x = {{x}}{{/percent}}\n"
185  
-                           @"{{#decimal}}x = {{x}}{{/decimal}}";
186  
-GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL];
187  
-
188  
-NSNumberFormatter *percentFormatter = [NSNumberFormatter new];
189  
-percentFormatter.numberStyle = NSNumberFormatterPercentStyle;
190  
-
191  
-NSNumberFormatter *decimalFormatter = [NSNumberFormatter new];
192  
-decimalFormatter.numberStyle = NSNumberFormatterDecimalStyle;
193  
-
194  
-id data = @{
195  
-    @"x": @(0.5),
196  
-    @"percent": percentFormatter,
197  
-    @"decimal": decimalFormatter
198  
-};
199  
-
200  
-// On a French system:
201  
-// x = 0.5
202  
-// x = 50 %
203  
-// x = 0,5
204  
-NSString *rendering = [template renderObject:data error:NULL];
205  
-```
206  
-
207 153
 
208 154
 Tag Delegates as Cross-Platform Filters
209 155
 ---------------------------------------
210 156
 
211  
-Let's consider again the number formatting example above. We were able to render `{{#percent}}x = {{x}}{{/percent}}` as `x = 50 %`: The tag delegate attached to the `percent` has formatted the number `x` as a percentage.
  157
+Tag delegates can observe, but also *alter* the rendering of all tags inside a section or the full template.
  158
+
  159
+Let's consider the behavior of NSFormatter in GRMustache. They are able to format all variable tags inside a section (check the [NSFormatter Guide](NSFormatter.md)).
212 160
 
213  
-You could also use [filters](filters.md) in order to format numbers: `x = {{ percent(x) }}` would render just as well.
  161
+For example, `{{#percent}}x = {{x}}{{/percent}}` renders as `x = 50 %` when `percent` is attached to an NSNumberFormatter. That is because formatters are *tag delegates*.
  162
+
  163
+We could also use [filters](filters.md) in order to format numbers: `x = {{ percent(x) }}` would render just as well.
214 164
 
215 165
 However, `{{#percent}}x = {{x}}{{/percent}}` has one advantage over `x = {{ percent(x) }}`: it uses plain Mustache syntax, and is compatible with [other Mustache implementations](https://github.com/defunkt/mustache/wiki/Other-Mustache-implementations).
216 166
 
@@ -222,7 +172,7 @@ With such a common template, it's now a matter of providing different data, depe
222 172
     // data for GRMustache
223 173
     {
224 174
       "x": 0.5,
225  
-      "percent": the_formating_tag_delegate
  175
+      "percent": (some well-configured NSNumberFormatter)
226 176
     }
227 177
 
228 178
     // data for other Mustache implementations
@@ -276,6 +226,7 @@ NSString *rendering = [GRMustacheTemplate renderObject:data
276 226
 
277 227
 The final rendering is "JOHANNES KEPLER".
278 228
 
  229
+
279 230
 Compatibility with other Mustache implementations
280 231
 -------------------------------------------------
281 232
 
@@ -284,10 +235,4 @@ The [Mustache specification](https://github.com/mustache/spec) does not have the
284 235
 **As a consequence, if your goal is to design templates that remain compatible with [other Mustache implementations](https://github.com/defunkt/mustache/wiki/Other-Mustache-implementations), use `GRMustacheTagDelegate` with great care.**
285 236
 
286 237
 
287  
-Sample code
288  
------------
289  
-
290  
-The [Localization Sample Code](sample_code/localization.md) uses tag delegates for localizing portions of a template.
291  
-
292  
-
293 238
 [up](../../../../GRMustache#documentation), [next](rendering_objects.md)
2  Guides/filters.md
Source Rendered
@@ -179,7 +179,7 @@ Instead, have a look at tag delegates, especially the [Tag Delegates as Cross-Pl
179 179
 Sample code
180 180
 -----------
181 181
 
182  
-Custom filters are used by the [Formatted Numbers](sample_code/number_formatting.md) and [Collection Indexes](sample_code/indexes.md) sample codes. Go check inspiration there.
  182
+Custom filters are used in the [Collection Indexes](sample_code/indexes.md) sample code. Go check inspiration there.
183 183
 
184 184
 
185 185
 [up](../../../../GRMustache#documentation), [next](delegate.md)
4  Guides/rendering_objects.md
Source Rendered
@@ -419,7 +419,7 @@ Many useful things.
419 419
     
420 420
     When GRMustache renders `{{ name }}`, it looks for the `name` key in the [context stack](runtime.md): for the title and names of our movies and people to render, movies and people must enter the context stack. This is the reason for the derivation of new contexts, using the `contextByAddingObject:` method, before partials are rendered.
421 421
     
422  
-    There is also a `contextByAddingTagDelegate:` method, that is documented in the [Delegates Guide](delegate.md). An interesting usage of this method is demonstrated in the [Localization Sample Code](sample_code/localization.md).
  422
+    There is also a `contextByAddingTagDelegate:` method, that is illustrated in the [Delegates Guide](delegate.md).
423 423
 
424 424
 
425 425
 Example: Render collections of objects
@@ -483,8 +483,6 @@ You *can* write specification-compliant "Mustache lambdas" with rendering object
483 483
 Sample code
484 484
 -----------
485 485
 
486  
-The [Localization Sample Code](sample_code/localization.md) uses the `GRMustacheRendering` protocol for localizing portions of template.
487  
-
488 486
 The [Collection Indexes Sample Code](sample_code/indexes.md) uses the `GRMustacheRendering` protocol for rendering indexes of an array items.
489 487
 
490 488
 [up](../../../../GRMustache#documentation), [next](protected_contexts.md)
3  Guides/runtime.md
Source Rendered
@@ -239,7 +239,6 @@ Such sections are fully documented in the [Rendering Objects Guide](rendering_ob
239 239
 
240 240
 ```objc
241 241
 id data = @{
242  
-    @"localize": [LocalizingHelper new],
243 242
     @"name1": @"Gustave",
244 243
     @"name2": @"Henriett" };
245 244
 
@@ -252,7 +251,7 @@ NSString *rendering = [GRMustacheTemplate renderObject:data
252 251
                                                  error:NULL];
253 252
 ```
254 253
 
255  
-This fancy `LocalizingHelper` class is described in the [Localization Sample Code](sample_code/localization.md).
  254
+The `localize` key is attached to a rendering object that is built in the [standard library](standard_library.md) shipped with GRMustache.
256 255
 
257 256
 
258 257
 ### Other sections
16  Guides/sample_code/README.md
Source Rendered
... ...
@@ -1,18 +1,8 @@
1  
-[up](../../../../../GRMustache#documentation), [next](number_formatting.md)
  1
+[up](../../../../../GRMustache#documentation), [next](indexes.md)
2 2
 
3 3
 Sample code
4 4
 ===========
5 5
 
6  
-- [Number Formatting](number_formatting.md)
  6
+**[Collection Indexes](indexes.md)**: How to have GRMustache render array indexes, render sections for the first or the last element, for odd or even elements, etc.: *discussion, downloadable Xcode project*.
7 7
 
8  
-    How to format numbers: *discussion, downloadable Xcode project*.
9  
-
10  
-- [Collection Indexes](indexes.md)
11  
-    
12  
-    How to have GRMustache render array indexes, render sections for the first or the last element, for odd or even elements, etc.: *discussion, downloadable Xcode project*.
13  
-
14  
-- [Localization](localization.md)
15  
-    
16  
-    How to have GRMustache localize portions of your templates: *discussion, downloadable Xcode project*.
17  
-
18  
-[up](../../../../../GRMustache#documentation), [next](number_formatting.md)
  8
+[up](../../../../../GRMustache#documentation), [next](indexes.md)
4  Guides/sample_code/indexes.md
Source Rendered
... ...
@@ -1,4 +1,4 @@
1  
-[up](../../../../tree/master/Guides/sample_code), [next](localization.md)
  1
+[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
2 2
 
3 3
 Collection Indexes
4 4
 ==================
@@ -153,4 +153,4 @@ Writing [filters](../filters.md) that return [rendering objects](../rendering_ob
153 153
 
154 154
 **[Download the code](../../../../tree/master/Guides/sample_code/indexes)**
155 155
 
156  
-[up](../../../../tree/master/Guides/sample_code), [next](localization.md)
  156
+[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
373  Guides/sample_code/localization.md
Source Rendered
... ...
@@ -1,372 +1 @@
1  
-[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
2  
-
3  
-Localization
4  
-============
5  
-
6  
-Overview
7  
---------
8  
-
9  
-Mustache and GRMustache have no built-in localization feature. It is thus a matter of injecting our own application code into the template rendering, some code that localizes its input.
10  
-
11  
-We'll see below how to localize:
12  
-
13  
-1. a section of a template
14  
-    
15  
-        {{#localize}}Hello{{/localize}}
16  
-    
17  
-    into:
18  
-    
19  
-        Hello
20  
-        Bonjour
21  
-        Hola
22  
-        
23  
-2. a value
24  
-    
25  
-        {{ localize(greeting) }}
26  
-    
27  
-    into:
28  
-    
29  
-        Hello
30  
-        Bonjour
31  
-        Hola
32  
-        
33  
-3. a portion of a template *with arguments*:
34  
-    
35  
-        {{#localize}}Hello {{name1}}, do you know {{name2}}?{{/localize}}
36  
-    
37  
-    into:
38  
-    
39  
-        Hello Arthur, do you know Barbara?
40  
-        Bonjour Arthur, est-ce que tu connais Barbara ?
41  
-        Hola Arthur, sabes Barbara?
42  
-
43  
-4. a portion of a template with arguments and *conditions*:
44  
-    
45  
-        {{#localize}}{{name1}} and {{name2}} {{#count}}have {{#isPlural(count)}}{{count}} mutual friends{{/}}{{^isPlural(count)}}one mutual friend{{/}}{{/count}}{{^count}}have no mutual friend{{/count}}.{{/localize}}
46  
-    
47  
-    into:
48  
-    
49  
-        Arthur and Barbara have no mutual friend.
50  
-        Craig et Dennis ont un ami commun.
51  
-        Eugene y Fiona tiene 5 amigos en común.
52  
-
53  
-Of course, we'll always eventually use the standard `NSLocalizedString` function.
54  
-
55  
-Localizing a template section
56  
------------------------------
57  
-
58  
-**[Download the code](../../../../tree/master/Guides/sample_code/localization)**
59  
-
60  
-`Document.mustache`:
61  
-
62  
-    {{#localize}}Hello{{/localize}}
63  
-
64  
-`Render.m`:
65  
-
66  
-```objc
67  
-id data = @{
68  
-    @"localize": [GRMustache renderingObjectWithBlock:^NSString *(GRMustacheTag *tag, GRMustacheContext *context, BOOL *HTMLSafe, NSError **error) {
69  
-        return NSLocalizedString(tag.innerTemplateString, nil);
70  
-    }]
71  
-};
72  
-
73  
-NSString *rendering = [GRMustacheTemplate renderObject:data
74  
-                                          fromResource:@"Document"
75  
-                                                bundle:nil
76  
-                                                 error:NULL];
77  
-```
78  
-
79  
-Final rendering depends on the current locale:
80  
-
81  
-    Hello
82  
-    Bonjour
83  
-    Hola
84  
-
85  
-`+[GRMustache renderingObjectWithBlock:]` and `-[GRMustacheTag innerTemplateString]` are documented in the [Rendering Objects Guide](../rendering_objects.md).
86  
-
87  
-
88  
-Localizing a value
89  
-------------------
90  
-
91  
-**[Download the code](../../../../tree/master/Guides/sample_code/localization)**
92  
-
93  
-`Document.mustache`:
94  
-
95  
-    {{ localize(greeting) }}
96  
-
97  
-`Render.m`:
98  
-
99  
-```objc
100  
-id data = @{
101  
-    @"greeting": @"Hello",
102  
-    @"localize": [GRMustacheFilter filterWithBlock:^id(id value) {
103  
-        return NSLocalizedString([value description], nil);
104  
-    }]
105  
-};
106  
-
107  
-NSString *rendering = [GRMustacheTemplate renderObject:data
108  
-                                          fromResource:@"Document"
109  
-                                                bundle:nil
110  
-                                                 error:NULL];
111  
-```
112  
-
113  
-Final rendering depends on the current locale:
114  
-
115  
-    Hello
116  
-    Bonjour
117  
-    Hola
118  
-
119  
-`+[GRMustache renderingObjectWithBlock:]` and `-[GRMustacheTag renderContentWithContext:HTMLSafe:error:]` are documented in the [Rendering Objects Guide](../rendering_objects.md).
120  
-
121  
-`+[GRMustacheFilter filterWithBlock:]` is documented in the [Filters Guide](../filters.md).
122  
-
123  
-
124  
-Localizing a template section with arguments
125  
---------------------------------------------
126  
-
127  
-**[Download the code](../../../../tree/master/Guides/sample_code/localization)**
128  
-
129  
-`Document.mustache`:
130  
-
131  
-    {{#localize}}
132  
-        Hello {{name1}}, do you know {{name2}}?
133  
-    {{/localize}}
134  
-
135  
-`Rendering.m`:
136  
-
137  
-```objc
138  
-id data = @{
139  
-    @"name1": @"Arthur",
140  
-    @"name2": @"Barbara",
141  
-    @"localize": [LocalizingHelper new],
142  
-};
143  
-
144  
-NSString *rendering = [GRMustacheTemplate renderObject:data
145  
-                                          fromResource:@"Document"
146  
-                                                bundle:nil
147  
-                                                 error:NULL];
148  
-```
149  
-
150  
-Final rendering depends on the current locale:
151  
-
152  
-    Hello Arthur, do you know Barbara?
153  
-    Bonjour Arthur, est-ce que tu connais Barbara ?
154  
-    Hola Arthur, sabes Barbara?
155  
-
156  
-Before diving in the sample code, let's first describe out strategy:
157  
-
158  
-1. When rendering the section, we'll build the *localizable format*:
159  
-
160  
-    `Hello %@, do you know %@?`
161  
-
162  
-2. We'll also gather the *format arguments*:
163  
-    - `Arthur`
164  
-    - `Barbara`
165  
-    
166  
-3. We'll localize the localizable format with `NSLocalizedString`, that will give us the *localized format*:
167  
-    - `Hello %@, do you know %@?`
168  
-    - `Bonjour %@, est-ce que tu connais %@ ?`
169  
-    - `Hola %@, sabes %@?`
170  
-
171  
-4. We'll finally use `[NSString stringWithFormat:]`, with the localized format, and format arguments:
172  
-    - `Hello Arthur, do you know Barbara?`
173  
-    - `Bonjour Arthur, est-ce que tu connais Barbara ?`
174  
-    - `Hola Arthur, sabes Barbara?`
175  
-
176  
-The tricky part is building the *localizable format* and extracting the *format arguments*. We could most certainly "manually" parse the inner template string of the section, `Hello {{name1}}, do you know {{name2}}?`. However, we'll take a more robust and reusable path.
177  
-
178  
-The [GRMustacheTagDelegate](../delegate.md) protocol is a nifty tool: not only does it tell you know what value GRMustache is about to render, but you can also decide what value should eventually be rendered.
179  
-
180  
-This looks like a nice way to build our format arguments and the localizable format in a single strike: instead of letting `Arthur` and `Barbara` render, we'll instead put those values away, and tell the library to render `%@`.
181  
-
182  
-Our `LocalizingHelper` class will thus conform to *both* the `GRMustacheRendering` and `GRMustacheTemplateDelegate` protocols. Now the convenient `[GRMustache renderingObjectWithBlock:]` method is not enough. Let's go for a full class:
183  
-
184  
-```objc
185  
-@interface LocalizingHelper: NSObject<GRMustacheRendering, GRMustacheTagDelegate>
186  
-@property (nonatomic) NSMutableArray *formatArguments;
187  
-@end
188  
-
189  
-@implementation LocalizingHelper
190  
-
191  
-- (NSString *)renderForMustacheTag:(GRMustacheTag *)tag context:(GRMustacheContext *)context HTMLSafe:(BOOL *)HTMLSafe error:(NSError *__autoreleasing *)error
192  
-{
193  
-    /**
194  
-     * Add self as a tag delegate, so that we know when tag will and did render.
195  
-     */
196  
-    context = [context contextByAddingTagDelegate:self];
197  
-    
198  
-    
199  
-    /**
200  
-     * Perform a first rendering of the section tag, that will set
201  
-     * localizableFormat to "Hello %@! Do you know %@?".
202  
-     *
203  
-     * Our mustacheTag:willRenderObject: implementation will tell the tags to
204  
-     * render "%@" instead of the regular values, "Arthur" or "Barbara". This
205  
-     * behavior is trigerred by the nil value of self.formatArguments.
206  
-     */
207  
-    
208  
-    self.formatArguments = nil;
209  
-    NSString *localizableFormat = [tag renderContentWithContext:context HTMLSafe:HTMLSafe error:error];
210  
-    
211  
-    
212  
-    /**
213  
-     * Perform a second rendering that will fill our formatArguments array with
214  
-     * HTML-escaped tag renderings.
215  
-     *
216  
-     * Our mustacheTag:willRenderObject: implementation will now let the regular
217  
-     * values through ("Arthur" or "Barbara"), so that our
218  
-     * mustacheTag:didRenderObject:as: method can fill self.formatArguments.
219  
-     * This behavior is not the same as the previous one, and is trigerred by
220  
-     * the non-nil value of self.formatArguments.
221  
-     */
222  
-    
223  
-    self.formatArguments = [NSMutableArray array];
224  
-    [tag renderContentWithContext:context HTMLSafe:HTMLSafe error:error];
225  
-    
226  
-    
227  
-    /**
228  
-     * Localize the format, and render.
229  
-     *
230  
-     * Unfortunately, [NSString stringWithFormat:] does not accept an array of
231  
-     * formatArguments to fill the format. Let's support up to 3 arguments:
232  
-     */
233  
-    
234  
-    NSString *localizedFormat = NSLocalizedString(localizableFormat, nil);
235  
-    NSString *rendering = nil;
236  
-    switch (self.formatArguments.count) {
237  
-        case 0:
238  
-            rendering = localizedFormat;
239  
-            break;
240  
-            
241  
-        case 1:
242  
-            rendering = [NSString stringWithFormat:
243  
-                         localizedFormat,
244  
-                         [self.formatArguments objectAtIndex:0]];
245  
-            break;
246  
-            
247  
-        case 2:
248  
-            rendering = [NSString stringWithFormat:
249  
-                         localizedFormat,
250  
-                         [self.formatArguments objectAtIndex:0],
251  
-                         [self.formatArguments objectAtIndex:1]];
252  
-            break;
253  
-            
254  
-        case 3:
255  
-            rendering = [NSString stringWithFormat:
256  
-                         localizedFormat,
257  
-                         [self.formatArguments objectAtIndex:0],
258  
-                         [self.formatArguments objectAtIndex:1],
259  
-                         [self.formatArguments objectAtIndex:2]];
260  
-            break;
261  
-            
262  
-        default:
263  
-            NSAssert(NO, @"Not implemented");
264  
-            break;
265  
-    }
266  
-    
267  
-    
268  
-    /**
269  
-     * Cleanup and return
270  
-     */
271  
-    
272  
-    self.formatArguments = nil;
273  
-    return rendering;
274  
-}
275  
-
276  
-- (id)mustacheTag:(GRMustacheTag *)tag willRenderObject:(id)object
277  
-{
278  
-    /**
279  
-     * We behave as stated in renderForMustacheTag:context:HTMLSafe:error:
280  
-     */
281  
-    
282  
-    if (self.formatArguments) {
283  
-        return object;
284  
-    }
285  
-
286  
-    return @"%@";
287  
-}
288  
-
289  
-- (void)mustacheTag:(GRMustacheTag *)tag didRenderObject:(id)object as:(NSString *)rendering
290  
-{
291  
-    /**
292  
-     * We behave as stated in renderForMustacheTag:context:HTMLSafe:error:
293  
-     */
294  
-    
295  
-    [self.formatArguments addObject:rendering];
296  
-}
297  
-
298  
-@end
299  
-```
300  
-
301  
-**[Download the code](../../../../tree/master/Guides/sample_code/localization)**
302  
-
303  
-
304  
-Localizing a template section with arguments and conditions
305  
------------------------------------------------------------
306  
-
307  
-Download the [GRMustacheLocalization Xcode project](../../../../tree/master/Guides/sample_code/localization): it provides tiny modifications to the `LocalizingHelper` class, in order to deal with Mustache boolean sections, and have the following code work:
308  
-
309  
-```objc
310  
-id localizingHelper = [LocalizingHelper new];
311  
-id isPluralFilter = [GRMustacheFilter filterWithBlock:^id(NSNumber *count) {
312  
-    if ([count intValue] > 1) {
313  
-        return @YES;
314  
-    }
315  
-    return @NO;
316  
-}];
317  
-
318  
-NSString *templateString = @"{{#localize}}{{name1}} and {{name2}} {{#count}}have {{#isPlural(count)}}{{count}} mutual friends{{/}}{{^isPlural(count)}}one mutual friend{{/}}{{/count}}{{^count}}have no mutual friend{{/count}}.{{/localize}}";
319  
-GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL];
320  
-
321  
-{
322  
-    id data = @{
323  
-        @"name1": @"Arthur",
324  
-        @"name2": @"Barbara",
325  
-        @"count": @(0),
326  
-        @"localize": localizingHelper,
327  
-        @"isPlural": isPluralFilter,
328  
-    };
329  
-    
330  
-    // Arthur and Barbara have no mutual friend.
331  
-    // Arthur et Barbara n’ont pas d’ami commun.
332  
-    // Arthur y Barbara no tienen ningún amigo en común.
333  
-    
334  
-    NSString *rendering = [template renderObject:data withFilters:filters];
335  
-}
336  
-
337  
-{
338  
-    id data = @{
339  
-        @"name1": @"Craig",
340  
-        @"name2": @"Dennis",
341  
-        @"count": @(1),
342  
-        @"localize": localizingHelper,
343  
-        @"isPlural": isPluralFilter,
344  
-    };
345  
-    
346  
-    // Craig and Dennis have one mutual friend.
347  
-    // Craig et Dennis ont un ami commun.
348  
-    // Craig y Dennis tiene un amigo en común.
349  
-    
350  
-    NSString *rendering = [template renderObject:data withFilters:filters];
351  
-}
352  
-
353  
-{
354  
-    id data = @{
355  
-        @"name1": @"Eugene",
356  
-        @"name2": @"Fiona",
357  
-        @"count": @(5),
358  
-        @"localize": localizingHelper,
359  
-        @"isPlural": isPluralFilter,
360  
-    };
361  
-    
362  
-    // Eugene and Fiona have 5 mutual friends.
363  
-    // Eugene et Fiona ont 5 amis communs.
364  
-    // Eugene y Fiona tiene 5 amigos en común.
365  
-    
366  
-    NSString *rendering = [template renderObject:data withFilters:filters];
367  
-}
368  
-```
369  
-
370  
-**[Download the code](../../../../tree/master/Guides/sample_code/localization)**
371  
-
372  
-[up](../../../../tree/master/Guides/sample_code), [next](../forking.md)
  1
+This document has been [superseded](../standard_library.md).
319  Guides/sample_code/localization/GRMustacheLocalization.xcodeproj/project.pbxproj
... ...
@@ -1,319 +0,0 @@
1  
-// !$*UTF8*$!
2  
-{
3  
-	archiveVersion = 1;
4  
-	classes = {
5  
-	};
6  
-	objectVersion = 46;
7  
-	objects = {
8  
-
9  
-/* Begin PBXBuildFile section */
10  
-		5632EF1315E0D55D009EA316 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5632EF1215E0D55D009EA316 /* Cocoa.framework */; };
11  
-		5632EF1F15E0D55D009EA316 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5632EF1E15E0D55D009EA316 /* main.m */; };
12  
-		5632EF2615E0D55D009EA316 /* GRAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5632EF2515E0D55D009EA316 /* GRAppDelegate.m */; };
13  
-		5632EF2915E0D55D009EA316 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5632EF2715E0D55D009EA316 /* MainMenu.xib */; };
14  
-		5632EF3615E0D5BF009EA316 /* libGRMustache6-MacOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5632EF3515E0D5BF009EA316 /* libGRMustache6-MacOS.a */; };
15  
-		56BF7C5615E0E08F0067308D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 56BF7C5415E0E08F0067308D /* Localizable.strings */; };
16  
-		56F1AB551635CD5500CC68EE /* LocalizingHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 56F1AB541635CD5500CC68EE /* LocalizingHelper.m */; };
17  
-/* End PBXBuildFile section */
18  
-
19  
-/* Begin PBXFileReference section */
20  
-		5632EF0E15E0D55D009EA316 /* GRMustacheLocalization.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GRMustacheLocalization.app; sourceTree = BUILT_PRODUCTS_DIR; };
21  
-		5632EF1215E0D55D009EA316 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
22  
-		5632EF1515E0D55D009EA316 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
23  
-		5632EF1615E0D55D009EA316 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
24  
-		5632EF1715E0D55D009EA316 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
25  
-		5632EF1A15E0D55D009EA316 /* GRMustacheLocalization-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GRMustacheLocalization-Info.plist"; sourceTree = "<group>"; };
26  
-		5632EF1E15E0D55D009EA316 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
27  
-		5632EF2015E0D55D009EA316 /* GRMustacheLocalization-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GRMustacheLocalization-Prefix.pch"; sourceTree = "<group>"; };
28  
-		5632EF2415E0D55D009EA316 /* GRAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GRAppDelegate.h; sourceTree = "<group>"; };
29  
-		5632EF2515E0D55D009EA316 /* GRAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GRAppDelegate.m; sourceTree = "<group>"; };
30  
-		5632EF2815E0D55D009EA316 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
31  
-		5632EF3415E0D5BF009EA316 /* GRMustache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GRMustache.h; path = include/GRMustache.h; sourceTree = "<group>"; };
32  
-		5632EF3515E0D5BF009EA316 /* libGRMustache6-MacOS.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libGRMustache6-MacOS.a"; path = "lib/libGRMustache6-MacOS.a"; sourceTree = "<group>"; };
33  
-		56BF7C5515E0E08F0067308D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
34  
-		56F1AB531635CD5500CC68EE /* LocalizingHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizingHelper.h; sourceTree = "<group>"; };
35  
-		56F1AB541635CD5500CC68EE /* LocalizingHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalizingHelper.m; sourceTree = "<group>"; };
36  
-/* End PBXFileReference section */
37  
-
38  
-/* Begin PBXFrameworksBuildPhase section */
39  
-		5632EF0B15E0D55D009EA316 /* Frameworks */ = {
40  
-			isa = PBXFrameworksBuildPhase;
41  
-			buildActionMask = 2147483647;
42  
-			files = (
43  
-				5632EF1315E0D55D009EA316 /* Cocoa.framework in Frameworks */,
44  
-				5632EF3615E0D5BF009EA316 /* libGRMustache6-MacOS.a in Frameworks */,
45  
-			);
46  
-			runOnlyForDeploymentPostprocessing = 0;
47  
-		};
48  
-/* End PBXFrameworksBuildPhase section */
49  
-
50  
-/* Begin PBXGroup section */
51  
-		5632EF0315E0D55C009EA316 = {
52  
-			isa = PBXGroup;
53  
-			children = (
54  
-				5632EF1815E0D55D009EA316 /* GRMustacheLocalization */,
55  
-				5632EF1115E0D55D009EA316 /* Frameworks */,
56  
-				5632EF0F15E0D55D009EA316 /* Products */,
57  
-			);
58  
-			sourceTree = "<group>";
59  
-		};
60  
-		5632EF0F15E0D55D009EA316 /* Products */ = {
61  
-			isa = PBXGroup;
62  
-			children = (
63  
-				5632EF0E15E0D55D009EA316 /* GRMustacheLocalization.app */,
64  
-			);
65  
-			name = Products;
66  
-			sourceTree = "<group>";
67  
-		};
68  
-		5632EF1115E0D55D009EA316 /* Frameworks */ = {
69  
-			isa = PBXGroup;
70  
-			children = (
71  
-				5632EF1215E0D55D009EA316 /* Cocoa.framework */,
72  
-				5632EF1415E0D55D009EA316 /* Other Frameworks */,
73  
-			);
74  
-			name = Frameworks;
75  
-			sourceTree = "<group>";
76  
-		};
77  
-		5632EF1415E0D55D009EA316 /* Other Frameworks */ = {
78  
-			isa = PBXGroup;
79  
-			children = (
80  
-				5632EF1515E0D55D009EA316 /* AppKit.framework */,
81  
-				5632EF1615E0D55D009EA316 /* CoreData.framework */,
82  
-				5632EF1715E0D55D009EA316 /* Foundation.framework */,
83  
-			);
84  
-			name = "Other Frameworks";
85  
-			sourceTree = "<group>";
86  
-		};
87  
-		5632EF1815E0D55D009EA316 /* GRMustacheLocalization */ = {
88  
-			isa = PBXGroup;
89  
-			children = (
90  
-				5632EF2415E0D55D009EA316 /* GRAppDelegate.h */,
91  
-				5632EF2515E0D55D009EA316 /* GRAppDelegate.m */,
92  
-				56F1AB531635CD5500CC68EE /* LocalizingHelper.h */,
93  
-				56F1AB541635CD5500CC68EE /* LocalizingHelper.m */,
94  
-				56BF7C5415E0E08F0067308D /* Localizable.strings */,
95  
-				5632EF3315E0D594009EA316 /* GRMustache */,
96  
-				5632EF1915E0D55D009EA316 /* Supporting Files */,
97  
-			);
98  
-			path = GRMustacheLocalization;
99  
-			sourceTree = "<group>";
100  
-		};
101  
-		5632EF1915E0D55D009EA316 /* Supporting Files */ = {
102  
-			isa = PBXGroup;
103  
-			children = (
104  
-				5632EF2715E0D55D009EA316 /* MainMenu.xib */,
105  
-				5632EF1A15E0D55D009EA316 /* GRMustacheLocalization-Info.plist */,
106  
-				5632EF1E15E0D55D009EA316 /* main.m */,
107  
-				5632EF2015E0D55D009EA316 /* GRMustacheLocalization-Prefix.pch */,
108  
-			);
109  
-			name = "Supporting Files";
110  
-			sourceTree = "<group>";
111  
-		};
112  
-		5632EF3315E0D594009EA316 /* GRMustache */ = {
113  
-			isa = PBXGroup;
114  
-			children = (
115  
-				5632EF3415E0D5BF009EA316 /* GRMustache.h */,
116  
-				5632EF3515E0D5BF009EA316 /* libGRMustache6-MacOS.a */,
117  
-			);
118  
-			name = GRMustache;
119  
-			path = ../../../..;
120  
-			sourceTree = "<group>";
121  
-		};
122  
-/* End PBXGroup section */
123  
-
124  
-/* Begin PBXNativeTarget section */
125  
-		5632EF0D15E0D55D009EA316 /* GRMustacheLocalization */ = {
126  
-			isa = PBXNativeTarget;
127  
-			buildConfigurationList = 5632EF2C15E0D55D009EA316 /* Build configuration list for PBXNativeTarget "GRMustacheLocalization" */;
128  
-			buildPhases = (
129  
-				5632EF0A15E0D55D009EA316 /* Sources */,
130  
-				5632EF0B15E0D55D009EA316 /* Frameworks */,
131  
-				5632EF0C15E0D55D009EA316 /* Resources */,
132  
-			);
133  
-			buildRules = (
134  
-			);
135  
-			dependencies = (
136  
-			);
137  
-			name = GRMustacheLocalization;
138  
-			productName = GRMustacheLocalization;
139  
-			productReference = 5632EF0E15E0D55D009EA316 /* GRMustacheLocalization.app */;
140  
-			productType = "com.apple.product-type.application";
141  
-		};
142  
-/* End PBXNativeTarget section */
143  
-
144  
-/* Begin PBXProject section */
145  
-		5632EF0515E0D55D009EA316 /* Project object */ = {
146  
-			isa = PBXProject;
147  
-			attributes = {
148  
-				CLASSPREFIX = GR;
149  
-				LastUpgradeCheck = 0440;
150  
-				ORGANIZATIONNAME = "Gwendal Roué";
151  
-			};
152  
-			buildConfigurationList = 5632EF0815E0D55D009EA316 /* Build configuration list for PBXProject "GRMustacheLocalization" */;
153  
-			compatibilityVersion = "Xcode 3.2";
154  
-			developmentRegion = English;
155  
-			hasScannedForEncodings = 0;
156  
-			knownRegions = (
157  
-				en,
158  
-			);
159  
-			mainGroup = 5632EF0315E0D55C009EA316;
160  
-			productRefGroup = 5632EF0F15E0D55D009EA316 /* Products */;
161  
-			projectDirPath = "";
162  
-			projectRoot = "";
163  
-			targets = (
164  
-				5632EF0D15E0D55D009EA316 /* GRMustacheLocalization */,
165  
-			);
166  
-		};
167  
-/* End PBXProject section */
168  
-
169  
-/* Begin PBXResourcesBuildPhase section */
170  
-		5632EF0C15E0D55D009EA316 /* Resources */ = {
171  
-			isa = PBXResourcesBuildPhase;
172  
-			buildActionMask = 2147483647;
173  
-			files = (
174  
-				5632EF2915E0D55D009EA316 /* MainMenu.xib in Resources */,
175  
-				56BF7C5615E0E08F0067308D /* Localizable.strings in Resources */,
176  
-			);
177  
-			runOnlyForDeploymentPostprocessing = 0;
178  
-		};
179  
-/* End PBXResourcesBuildPhase section */
180  
-
181  
-/* Begin PBXSourcesBuildPhase section */
182  
-		5632EF0A15E0D55D009EA316 /* Sources */ = {
183  
-			isa = PBXSourcesBuildPhase;
184  
-			buildActionMask = 2147483647;
185  
-			files = (
186  
-				5632EF1F15E0D55D009EA316 /* main.m in Sources */,
187  
-				5632EF2615E0D55D009EA316 /* GRAppDelegate.m in Sources */,
188  
-				56F1AB551635CD5500CC68EE /* LocalizingHelper.m in Sources */,
189  
-			);
190  
-			runOnlyForDeploymentPostprocessing = 0;
191  
-		};
192  
-/* End PBXSourcesBuildPhase section */
193  
-
194  
-/* Begin PBXVariantGroup section */
195  
-		5632EF2715E0D55D009EA316 /* MainMenu.xib */ = {
196  
-			isa = PBXVariantGroup;
197  
-			children = (
198  
-				5632EF2815E0D55D009EA316 /* en */,
199  
-			);
200  
-			name = MainMenu.xib;
201  
-			sourceTree = "<group>";
202  
-		};
203  
-		56BF7C5415E0E08F0067308D /* Localizable.strings */ = {
204  
-			isa = PBXVariantGroup;
205  
-			children = (
206  
-				56BF7C5515E0E08F0067308D /* en */,
207  
-			);
208  
-			name = Localizable.strings;
209  
-			sourceTree = "<group>";
210  
-		};
211  
-/* End PBXVariantGroup section */
212  
-
213  
-/* Begin XCBuildConfiguration section */
214  
-		5632EF2A15E0D55D009EA316 /* Debug */ = {
215  
-			isa = XCBuildConfiguration;
216  
-			buildSettings = {
217  
-				ALWAYS_SEARCH_USER_PATHS = NO;
218  
-				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
219  
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
220  
-				CLANG_ENABLE_OBJC_ARC = YES;
221  
-				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
222  
-				COPY_PHASE_STRIP = NO;
223  
-				GCC_C_LANGUAGE_STANDARD = gnu99;
224  
-				GCC_DYNAMIC_NO_PIC = NO;
225  
-				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
226  
-				GCC_OPTIMIZATION_LEVEL = 0;
227  
-				GCC_PREPROCESSOR_DEFINITIONS = (
228  
-					"DEBUG=1",
229  
-					"$(inherited)",
230  
-				);
231  
-				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
232  
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
233  
-				GCC_WARN_ABOUT_RETURN_TYPE = YES;
234  
-				GCC_WARN_UNINITIALIZED_AUTOS = YES;
235  
-				GCC_WARN_UNUSED_VARIABLE = YES;
236  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
237  
-				ONLY_ACTIVE_ARCH = YES;
238  
-				SDKROOT = macosx;
239  
-			};
240  
-			name = Debug;
241  
-		};
242  
-		5632EF2B15E0D55D009EA316 /* Release */ = {
243  
-			isa = XCBuildConfiguration;
244  
-			buildSettings = {
245  
-				ALWAYS_SEARCH_USER_PATHS = NO;
246  
-				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
247  
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
248  
-				CLANG_ENABLE_OBJC_ARC = YES;
249  
-				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
250  
-				COPY_PHASE_STRIP = YES;
251  
-				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
252  
-				GCC_C_LANGUAGE_STANDARD = gnu99;
253  
-				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
254  
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
255  
-				GCC_WARN_ABOUT_RETURN_TYPE = YES;
256  
-				GCC_WARN_UNINITIALIZED_AUTOS = YES;
257  
-				GCC_WARN_UNUSED_VARIABLE = YES;
258  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
259  
-				SDKROOT = macosx;
260  
-			};
261  
-			name = Release;
262  
-		};
263  
-		5632EF2D15E0D55D009EA316 /* Debug */ = {
264  
-			isa = XCBuildConfiguration;
265  
-			buildSettings = {
266  
-				COMBINE_HIDPI_IMAGES = YES;
267  
-				GCC_PRECOMPILE_PREFIX_HEADER = YES;
268  
-				GCC_PREFIX_HEADER = "GRMustacheLocalization/GRMustacheLocalization-Prefix.pch";
269  
-				INFOPLIST_FILE = "GRMustacheLocalization/GRMustacheLocalization-Info.plist";
270  
-				LIBRARY_SEARCH_PATHS = (
271  
-					"$(inherited)",
272  
-					"\"$(SRCROOT)/../../../lib\"",
273  
-				);
274  
-				PRODUCT_NAME = "$(TARGET_NAME)";
275  
-				WRAPPER_EXTENSION = app;
276  
-			};
277  
-			name = Debug;
278  
-		};
279  
-		5632EF2E15E0D55D009EA316 /* Release */ = {
280  
-			isa = XCBuildConfiguration;
281  
-			buildSettings = {
282  
-				COMBINE_HIDPI_IMAGES = YES;
283  
-				GCC_PRECOMPILE_PREFIX_HEADER = YES;
284  
-				GCC_PREFIX_HEADER = "GRMustacheLocalization/GRMustacheLocalization-Prefix.pch";
285  
-				INFOPLIST_FILE = "GRMustacheLocalization/GRMustacheLocalization-Info.plist";
286  
-				LIBRARY_SEARCH_PATHS = (
287  
-					"$(inherited)",
288  
-					"\"$(SRCROOT)/../../../lib\"",
289  
-				);
290  
-				PRODUCT_NAME = "$(TARGET_NAME)";
291  
-				WRAPPER_EXTENSION = app;
292  
-			};
293  
-			name = Release;
294  
-		};
295  
-/* End XCBuildConfiguration section */
296  
-
297  
-/* Begin XCConfigurationList section */
298  
-		5632EF0815E0D55D009EA316 /* Build configuration list for PBXProject "GRMustacheLocalization" */ = {
299  
-			isa = XCConfigurationList;
300  
-			buildConfigurations = (
301  
-				5632EF2A15E0D55D009EA316 /* Debug */,
302  
-				5632EF2B15E0D55D009EA316 /* Release */,
303  
-			);
304  
-			defaultConfigurationIsVisible = 0;
305  
-			defaultConfigurationName = Release;
306  
-		};
307  
-		5632EF2C15E0D55D009EA316 /* Build configuration list for PBXNativeTarget "GRMustacheLocalization" */ = {
308  
-			isa = XCConfigurationList;
309  
-			buildConfigurations = (
310  
-				5632EF2D15E0D55D009EA316 /* Debug */,
311  
-				5632EF2E15E0D55D009EA316 /* Release */,
312  
-			);
313  
-			defaultConfigurationIsVisible = 0;
314  
-			defaultConfigurationName = Release;
315  
-		};
316  
-/* End XCConfigurationList section */
317  
-	};
318  
-	rootObject = 5632EF0515E0D55D009EA316 /* Project object */;
319  
-}
29  Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.h
... ...
@@ -1,29 +0,0 @@
1  
-// The MIT License
2  
-//
3  
-// Copyright (c) 2013 Gwendal Roué
4  
-//
5  
-// Permission is hereby granted, free of charge, to any person obtaining a copy
6  
-// of this software and associated documentation files (the "Software"), to deal
7  
-// in the Software without restriction, including without limitation the rights
8  
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  
-// copies of the Software, and to permit persons to whom the Software is
10  
-// furnished to do so, subject to the following conditions:
11  
-//
12  
-// The above copyright notice and this permission notice shall be included in
13  
-// all copies or substantial portions of the Software.
14  
-//
15  
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  
-// THE SOFTWARE.
22  
-
23  
-#import <Cocoa/Cocoa.h>
24  
-
25  
-@interface GRAppDelegate : NSObject <NSApplicationDelegate>
26  
-
27  
-@property (assign) IBOutlet NSWindow *window;
28  
-
29  
-@end
173  Guides/sample_code/localization/GRMustacheLocalization/GRAppDelegate.m
... ...
@@ -1,173 +0,0 @@
1  
-// The MIT License
2  
-//
3  
-// Copyright (c) 2013 Gwendal Roué
4  
-//
5  
-// Permission is hereby granted, free of charge, to any person obtaining a copy
6  
-// of this software and associated documentation files (the "Software"), to deal
7  
-// in the Software without restriction, including without limitation the rights
8  
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  
-// copies of the Software, and to permit persons to whom the Software is
10  
-// furnished to do so, subject to the following conditions:
11  
-//
12  
-// The above copyright notice and this permission notice shall be included in
13  
-// all copies or substantial portions of the Software.
14  
-//
15  
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  
-// THE SOFTWARE.
22  
-
23  
-#import "GRAppDelegate.h"
24  
-#import "GRMustache.h"
25  
-#import "LocalizingHelper.h"
26  
-
27  
-@implementation GRAppDelegate
28  
-
29  
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
30  
-{
31  
-    {
32  
-        /**
33  
-         * Localizing a template section
34  
-         */
35  
-        
36  
-        NSLog(@"-----------------------------");
37  
-        NSLog(@"Localizing a template section");
38  
-        
39  
-        id data = @{
40  
-            @"localize": [GRMustache renderingObjectWithBlock:^NSString *(GRMustacheTag *tag, GRMustacheContext *context, BOOL *HTMLSafe, NSError *__autoreleasing *error) {
41  
-                return NSLocalizedString(tag.innerTemplateString, nil);
42  
-            }]
43  
-        };
44  
-        
45  
-        NSString *templateString = @"{{#localize}}Hello{{/localize}}";
46  
-        NSString *rendering = [GRMustacheTemplate renderObject:data fromString:templateString error:NULL];
47  
-        
48  
-        NSLog(@"%@", rendering);
49  
-        
50  
-        // With LocalizingHelper class
51  
-        
52  
-        data = @{
53  
-            @"localize": [[LocalizingHelper alloc] init]
54  
-        };
55  
-        rendering = [GRMustacheTemplate renderObject:data fromString:templateString error:NULL];
56  
-        NSLog(@"With LocalizingHelper: %@", rendering);
57  
-    }
58  
-    
59  
-    {
60  
-        /**
61  
-         * Localizing a value
62  
-         */
63  
-        
64  
-        NSLog(@"------------------");
65  
-        NSLog(@"Localizing a value");
66  
-        
67  
-        id data = @{
68  
-            @"greeting": @"Hello",
69  
-            @"localize": [GRMustacheFilter filterWithBlock:^id(id value) {
70  
-                return NSLocalizedString([value description], nil);
71  
-            }]
72  
-        };
73  
-        
74  
-        NSString *templateString = @"{{ localize(greeting) }}";
75  
-        NSString *rendering = [GRMustacheTemplate renderObject:data fromString:templateString error:NULL];
76  
-        
77  
-        NSLog(@"%@", rendering);
78  
-        
79  
-        // With LocalizingHelper class
80  
-        
81  
-        data = @{
82  
-            @"greeting": @"Hello",
83  
-            @"localize": [[LocalizingHelper alloc] init]
84  
-        };
85  
-        rendering = [GRMustacheTemplate renderObject:data fromString:templateString error:NULL];
86  
-        NSLog(@"With LocalizingHelper: %@", rendering);
87  
-    }
88  
-    
89  
-    {
90  
-        /**
91  
-         * Localizing a template section with arguments
92  
-         */
93  
-        
94  
-        NSLog(@"--------------------------------------------");
95  
-        NSLog(@"Localizing a template section with arguments");
96  
-        
97  
-        id data = @{
98  
-        @"name1": @"Arthur",
99  
-        @"name2": @"Barbara",
100  
-        @"localize": [[LocalizingHelper alloc] init]
101  
-        };
102  
-        
103  
-        NSString *templateString = @"{{#localize}}Hello {{name1}}! Do you know {{name2}}?{{/localize}}";
104  
-        NSString *rendering = [GRMustacheTemplate renderObject:data fromString:templateString error:NULL];
105  
-        
106  
-        NSLog(@"With LocalizingHelper: %@", rendering);
107  
-    }
108  
-    
109  
-    {
110  
-        /**
111  
-         * Localizing a template section with arguments and conditions
112  
-         */
113  
-        
114  
-        NSLog(@"-----------------------------------------------------------");
115  
-        NSLog(@"Localizing a template section with arguments and conditions");
116  
-        
117  
-        id localizingHelper = [[LocalizingHelper alloc] init];
118  
-        id isPluralFilter = [GRMustacheFilter filterWithBlock:^id(NSNumber *count) {
119  
-            if ([count intValue] > 1) {
120  
-                return @YES;
121  
-            }
122  
-            return @NO;
123  
-        }];
124  
-